perl-embperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bengt Rasmusson" <>
Subject RE: Modules not functioning correctly
Date Wed, 26 Nov 2003 12:00:36 GMT
When encountering the problem mentioned in this thread I have successfully
used Angus solutions - I usually use solution 2. But today I experienced
something curious (I am using b08).

In my previous .epl pages I successfully used "use conn;" which referred to
a file named which at the top included the line "package conn;". In I have a sub called "connection" and in the .epl pages I refer to it
as "conn::connection()".

Today I created a new .epl file as a copy of one of the working .epl pages
and named it test.epl. I also created new .pm file called In
test.epl I have the line "use conn_pages;" and in I have the
line "package conn_pages;".  In I have a sub called
"connection" and in the .epl page I refer to it as
"conn_pages::connection()". But this don't work - now and then I receive the
familiar error message about undefined function.

I then made an exakt copy of test.epl and of, and named them
test2.epl and In test2.epl I have the line "use pagesconn;"
and in the line "package pagesconn;". And as suspected: In I have a sub called "connection" and in the .epl page I refer
to it as "pagesconn::connection()". This works fine!

So in summary:
"use conn;", "conn::connection()",, and "package conn;" works!
"use conn_pages;", "conn_pages::connection()",, and "package
conn_pages;" does *not* work!
"use pagesconn;", "pagesconn::connection()",, and "package
pagesconn;" works!

Can anyone explane this behavior? Isn't underscore an allowed character in a
package name? Or in library file names? Or?


-----Ursprungligt meddelande-----
Fran: Angus Lees []
Skickat: den 28 juli 2003 19:48
Till: Justin Harrison
Amne: Re: Modules not functioning correctly

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
> 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:

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

View raw message