Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: mod_perl and modules (Or "how do I import subs into my PerlHandler module)

by Sihal (Pilgrim)
on Nov 22, 2002 at 11:34 UTC ( [id://215065]=note: print w/replies, xml ) Need Help??


in reply to mod_perl and modules (Or "how do I import subs into my PerlHandler module)

Here are some snippets: my PerlHandler module does something like that:
use QMM::photo::qmm_photo qw(get_usr_params);
and in package qmm_photo;
package QMM::photo::qmm_photo ; #use strict; use Exporter; use DBI; use lib "/home/loic/server" ; our @ISA = ('Exporter'); our @EXPORT = qw( get_usr_params );
Without the explicit use QMM::photo::qmm_photo qw(...) ; my main module wouldn't load the funcs properly.

Replies are listed 'Best First'.
Re: Re: mod_perl and modules (Or "how do I import subs into my PerlHandler module)
by UnderMine (Friar) on Nov 22, 2002 at 12:14 UTC
    Try removing the our as @ISA and @EXPORT are special variables and are not related to the package scope..
    package QMM::photo::qmm_photo ; use strict; use Exporter; use DBI; use lib "/home/loic/server" ; @ISA = ('Exporter'); @EXPORT = qw( get_usr_params );
    Hope it Helps
    UnderMine
Re: Re: mod_perl and modules (Or "how do I import subs into my PerlHandler module)
by perrin (Chancellor) on Nov 22, 2002 at 14:28 UTC
    If you want to refer to subs defined in another package you do have to use the package prefix or import them. That's the perl5 way. There are people who make perl4-style library files with no package declaration that just add their subs to the current package when you use them, but this is a bad practice and should be avoided.

    The only mod_perl-specific issue is that if you run your script under Apache::Registry and use the same perl4-style library file in two scripts, the second one to run will not find the subs (because it's in a different package).

      Hum.
      Well usually everything in @EXPORT is exported by default when under normal use, and only stuff in EXPORT_OOK has to be exported explicitely.
      Apparently (from my experience, but I might do something wrong) under mod_perl, you'd better import everything explicitely else it won't work.
        mod_perl should not affect the behavior of the exporter. I think there must be something else going on.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://215065]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2025-03-27 16:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    When you first encountered Perl, which feature amazed you the most?










    Results (70 votes). Check out past polls.

    Notices?
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.