theirpuppet has asked for the wisdom of the Perl Monks concerning the following question:

I've written my own library 'package', for a site i'm building. i bring it in with a 'use', and do libname::func_name() for the functions. i have no interest in doing OO with this. what i want, however, is to have the parent apache process load this package, offloading it from the children.

can i just do a require in /usr/include/apache/modules/perl/startup.perl ?? what about the fact that it's in the same dir as the scripts themselves, which currently allows me to do the 'use', and not in @INC? also, i plan on using Apache::Reload in the future, with the touch file mechanism. so i want to make sure that whatever changes i make now, will be good for Apache::Reload.

ps. i'm totally happy with the current 'use' and libname::func_name(), and have no interest in changing that.

Replies are listed 'Best First'.
Re: mod_perl and my own package
by BUU (Prior) on Oct 28, 2002 at 06:43 UTC
    According to what i know about mod_perl, what you want shouldn't matter. The first time yer script is hit, the script is compiled into byte code, including any modules associated with it. So there would be no need to have the module loaded by anything higher. Infact, that may be bad if you ran into issues with changing the library.

    Also note that if you aren't going to use Exporter, then you should "use" require to import your modules, as that explicitly shows that you aren't going to do any hanky panky with the namespaces.
      The advantage of loading it during startup is that the memory taken by that bytecode will be shared between processes.
      Also note that if you aren't going to use Exporter, then you should "use" require to import your modules, as that explicitly shows that you aren't going to do any hanky panky with the namespaces.

      What if you're using a module that exports nothing but runs class-specific initialization code in import()? Stick with the common idiom of importing an empty list of symbols.

      if you aren't going to use Exporter, then you should "use" require to import your modules, as that explicitly shows that you aren't going to do any hanky panky with the namespaces.
      No, that's what use Module (); is for.

      Makeshifts last the longest.

Re: mod_perl and my own package
by perrin (Chancellor) on Oct 28, 2002 at 16:34 UTC
    You can just do a use or require from startup.pl. You need to add the directory to @INC with a use lib statement, or else put it in <APACHE>/lib/perl/ which is automatically added to @INC under mod_perl.
      thanks perrin

      that's the answer i expected. glad to see i was right, and glad to have had your help (and everyone else's).

Re: mod_perl and my own package
by theirpuppet (Sexton) on Oct 28, 2002 at 21:40 UTC
    i did as perrin said, added it via 'use lib' and a 'use' statement in startup.perl. unfortunately all httpd processes grew significantly in size.
    'ps aux' from:
    10048 6640
    11840 6216
    11812 6192
    to:
    14104 10848
    15080 11940
    15120 11980

    doesn't seem like this should be the case. platform is suse linux 8.0

      Be careful how you interpret those numbers. Some of that memory is shared. It's all explained here.