perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Angus Lees <...@inodes.org>
Subject Re: Modules not functioning correctly
Date Mon, 28 Jul 2003 17:47:30 GMT
At Sat, 26 Jul 2003 22:08:50 -0400, Justin Harrison wrote:
> All the files are uniquely titled. i.e, there is only one code.pm, one
> rules.pm, etc. Many other embperl pages "use" rules.pm, but they are all the
> same files.

When you do "use rules;" the first time, perl finds the right rules.pm
file and compiles it.  It then remembers that it has done so (in %INC)
and later "use rules;" invocations do nothing.  This means that every
page after the first (for each apache child process), encounters an
undefined &codeform.


So you have several solutions:

1.  ensure rules.pm gets reloaded every time.

Try replacing "use rules;" with "do $path_to_rules_pm;".  This will
force perl to recompile rules.pm every time.  Fairly nasty since it
ends up duplicating the function for each caller, each time its run.


2.  compile it once and put &codeform somewhere you can find it.

Add "package rules;" to the top of rules.pm.

Everywhere you use "&codeform", replace it with "&rules::codeform".

This is the most efficient solution, since the first bit of code to
"use rules" actually loads and compiles rules.pm and then everyone
just refers to the same function.


3.  compile it once and import an alias for &codeform into each
    caller.

Add this to the top of rules.pm:

 package rules;

 use base qw(Exporter);
 our @EXPORT = qw(&codeform);

The other thing that "use" does is invoke "import PackageName".  In
addition to method (2), the above code inherits a suitable import()
function from Exporter.  This import function will make an alias for
&rules::codeform in all packages that do "use rules".

This is the easiest solution, since you shouldn't have to actually
modify any code beyond those simple changes to rules.pm.



For more information, see "perldoc -f package", "perldoc -f use" and
"perldoc Exporter" (probably in that order).

-- 
 - Gus

---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Mime
View raw message