perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Angus Lees <>
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, one
>, etc. Many other embperl pages "use", but they are all the
> same files.

When you do "use rules;" the first time, perl finds the right
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 gets reloaded every time.

Try replacing "use rules;" with "do $path_to_rules_pm;".  This will
force perl to recompile 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

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 and then everyone
just refers to the same function.

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

Add this to the top of

 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

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

 - Gus

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message