You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Jaak <va...@hot.ee> on 2001/08/13 18:44:32 UTC
embper && modules from different files
Hi,
Thanks for Apache::Reload. Sorry for dumb question again.
as I wrote:
I made a module testModule.pm
sub test {
print OUT "just testing..."; }
and test.html
[+ &test; +]
I use file main.epl where:
[- use testModule ; -]
[- Execute ('*') -]
Now when I call test.html. Program cannot find testModule.pm
(when I use testModule on the same page it's OK).
How can I define testModule.pm for site wide use?
Thanks.
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: embper && modules from different files
Posted by Gerald Richter <ri...@ecos.de>.
>
> Now when I call test.html. Program cannot find testModule.pm
> (when I use testModule on the same page it's OK).
> How can I define testModule.pm for site wide use?
>
Since every file runs in it's own Perl namespace, you cannot import your
test function in all files at once. So you either have to write the
use testModule ;
in every file where you want to have the functions imported or call the test
function via full name
testModule::test
The third possibilitie is to let all files run in the same namespace, which
is decribed here http://perl.apache.org/embperl/TipsAndTricks.pod.cont.html
, but depending on how you use it, this may increase memory usage.
Gerald
-------------------------------------------------------------
Gerald Richter ecos electronic communication services gmbh
Internetconnect * Webserver/-design/-datenbanken * Consulting
Post: Tulpenstrasse 5 D-55276 Dienheim b. Mainz
E-Mail: richter@ecos.de Voice: +49 6133 925131
WWW: http://www.ecos.de Fax: +49 6133 925152
-------------------------------------------------------------
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org
Re: embper && modules from different files
Posted by "Luiz Fernando B. Ribeiro" <li...@athome.pro.br>.
Hi Jaak,
I think I can help you:
J> as I wrote:
J> I made a module testModule.pm
J> sub test {
J> print OUT "just testing..."; }
J> and test.html
J> [+ &test; +]
You could try to use a Object Oriented approach sin you are usin
EmbperlObject, like this:
in Module.pm:
package MyModule;
new {
my $class = shift;
return bless {}, $class;
}
test {
my $self = shift;
return 'String returned';
}
other functions...
In the html files you can use the [++] to print values:
[- use MyModule;
$obj = new MyModule;
-]
<html>
...
<p>[+ $obj->test +]</p>
...
</html>
J> I use file main.epl where:
J> [- use testModule ; -]
J> [- Execute ('*') -]
J> Now when I call test.html. Program cannot find testModule.pm
J> (when I use testModule on the same page it's OK).
J> How can I define testModule.pm for site wide use?
To solve this put the object in the $req variable returned as the
first argument in @_ to every page you load, this way they become
"Globals":
in main.epl:
[- use MyModule; # Or if you use mod_perl you should use [!!]
# instead
$req = shift;
$obj = new MyModule;
$req->{obj} = $obj; # This way you can retrieve the object in any
# file you Execute
-]
...
[- Execute ('*') -]
...
In other files:
[-
$req = shift;
$obj = $req->{obj};
-]
[+ $obj->test +]
Good luck,
Luiz Fernando B. Ribeiro
----------------------------
At Home - Design e Internet
contato@athome.pro.br
athome@uol.com.br
---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org