intermittent "Undefined subroutine" with mod_perl

Discussion in 'Perl Misc' started by Moulin Kluge, Jan 27, 2004.

  1. Moulin Kluge

    Moulin Kluge Guest

    Hello,

    I'm running a mod_perl application that works ok for a couple of
    hours, but after a while I start getting an intermittent error:

    Software error:

    Undefined subroutine
    &ModPerl::ROOT::ModPerl::Registry::var_www_cgi_2dbin_request_requestlist_2epl::printHeaders
    called at /var/www/cgi-bin/request/requestlist.pl line 30.

    It appears to only happen on a single thread, and when I hit this
    thread, then I get the error. I'm running Redhat 9, completely
    updated with Apache 2.0.40, mod_perl 1.99, and the latest update from
    CPAN of CGI.pm.

    I have multiple projects that use customized version of the same
    private module, which doesn't really work with the latest mod_perl and
    apache, because mod_perl scripts no longer have the current directory
    set to the same as the script location, so I added the following to
    the top of the scripts so that I can use my private modules:

    BEGIN {
    if( $ENV{"SCRIPT_FILENAME"} && $ENV{"SCRIPT_FILENAME"} =~
    /^(.+)\/[^\/]+$/ )
    {
    chdir $1;
    }
    # Set library paths in @INC, at compile time
    unshift @INC, '.';
    }

    The PrintHeaders function that is declared as "Undefined" above is in
    the module. Is there possibly something weird going on here where one
    of the threads perhaps ignoring this code? I know that this is not
    the best way to handle modules (as opposed to putting them in the @INC
    dirs), but it is really useful in a development environment.

    Any help is appreciated. Thank you.

    Eli
    Moulin Kluge, Jan 27, 2004
    #1
    1. Advertising

  2. (Moulin Kluge) writes:

    > I'm running a mod_perl application that works ok for a couple of
    > hours, but after a while I start getting an intermittent error:
    >
    > Software error:
    >
    > Undefined subroutine
    > &ModPerl::ROOT::ModPerl::Registry::var_www_cgi_2dbin_request_requestlist_2epl::printHeaders
    > called at /var/www/cgi-bin/request/requestlist.pl line 30.


    This is usually an effect of using Perl4-style libraries within
    mod_perl. Don't do that. If you have a legacy library you have to
    use then wrap it in a Perl5-style library (i.e. and module that uses
    exporter).

    > I have multiple projects that use customized version of the same
    > private module, which doesn't really work with the latest mod_perl and
    > apache, because mod_perl scripts no longer have the current directory
    > set to the same as the script location,


    I think you'll find it never really worked - perhaps you were
    (unknowingly) already using kludge mentioned below.

    > so I added the following to
    > the top of the scripts so that I can use my private modules:
    >
    > BEGIN {
    > if( $ENV{"SCRIPT_FILENAME"} && $ENV{"SCRIPT_FILENAME"} =~
    > /^(.+)\/[^\/]+$/ )
    > {
    > chdir $1;
    > }
    > # Set library paths in @INC, at compile time
    > unshift @INC, '.';
    > }


    Oh, so that would be your problem. Don't do that (muck about with
    @INC) either.

    The major point of mod_perl Registry is to only have to load each
    module once rather than once per script. Once a module called Foo is
    loaded no other module called Foo will be loaded by the same
    interpreter thread.

    > The PrintHeaders function that is declared as "Undefined" above is in
    > the module. Is there possibly something weird going on here where one
    > of the threads perhaps ignoring this code? I know that this is not
    > the best way to handle modules (as opposed to putting them in the @INC
    > dirs), but it is really useful in a development environment.


    There are features mod_perl that allow different areas of the server
    to effectively have different @INC (Apache::perlVINC). It works by
    reloading modules. This is intended as a development environment tool
    - it's not something you'd want in a production environment. Be aware
    that not all modules can be reloaded with impunity. Some will leak
    memory. Some will do worse things.

    In the case of a production environment ISTR that you can (in mod_perl2)
    have multiple Perl interpreter pools and use different pools for
    different areas of your website. (But then again do you really want
    mod_perl2 in a production environment yet?).

    --
    \\ ( )
    . _\\__[oo
    .__/ \\ /\@
    . l___\\
    # ll l\\
    ###LL LL\\
    Brian McCauley, Jan 27, 2004
    #2
    1. Advertising

  3. Moulin Kluge

    pkent Guest

    In article <>,
    (Moulin Kluge) wrote:

    > BEGIN {
    > if( $ENV{"SCRIPT_FILENAME"} && $ENV{"SCRIPT_FILENAME"} =~
    > /^(.+)\/[^\/]+$/ )
    > {
    > chdir $1;
    > }


    BEGIN blocks are executed at compile time. As you know, compilation
    happens once under mod_perl.

    Also the environment and cwd is reset on each request.

    You don't paste any code but I suspect that this is related to the
    problem - if you show us the relevant bit it might shed light on a
    different place though. Personally though I think the chdir is not how
    I'd do it, I'd do:

    #### begin program.pl
    use strict;
    use lib '/home/moulin/lib';
    use PrivateModule;

    # some code

    PrivateModule::thingy( $foo );
    ####################

    or some variant with importing, or OO or whatever appropriate to the
    task in hand.

    P

    --
    pkent 77 at yahoo dot, er... what's the last bit, oh yes, com
    Remove the tea to reply
    pkent, Jan 27, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    0
    Views:
    483
  2. Replies:
    4
    Views:
    176
    Bob Walton
    Aug 12, 2003
  3. Torsten Mangner

    testing for 'undefined subroutine'

    Torsten Mangner, Nov 4, 2003, in forum: Perl Misc
    Replies:
    3
    Views:
    138
    Bob Walton
    Nov 5, 2003
  4. it_says_BALLS_on_your forehead
    Replies:
    0
    Views:
    345
    it_says_BALLS_on_your forehead
    Jan 24, 2006
  5. Replies:
    2
    Views:
    438
    Big and Blue
    Jan 25, 2006
Loading...

Share This Page