You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by "Roberto C. Sánchez" <ro...@connexer.com> on 2009/04/14 02:21:45 UTC

Undefined subroutine error

So,

I've been dealing with trying to figure out an "Undefined subroutine"
error on one of my sites.  At first I thought it was something to do
with Apache::ASP, so I sent a message requesting help to that list:
http://mail-archives.apache.org/mod_mbox/perl-asp/200811.mbox/thread

However, even after upgrading the server from Debian Etch to Lenny and
migrating the site from Apache::ASP to HTML::Mason, I still get the
exact same "Undefined subroutine" error.  That makes me think that this
something at a lower level.

If anyone could possibly help or provide any insight, I would really
appreciate it.  This has really been causing me to wrack my brain since
it only occurs on the production server and not on the development
server (both are identically configured).

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by Perrin Harkins <ph...@gmail.com>.
On Mon, Apr 13, 2009 at 10:54 PM, Roberto C. Sánchez
<ro...@connexer.com> wrote:
> The entire Example/Image.pm:

I don't see you exporting get_image_data.  Do you call it with a
fully-qualified name then?  e.g. Example::Image::get_image_data().

- Perrin

Re: Undefined subroutine error

Posted by "Roberto C. Sánchez" <ro...@connexer.com>.
On Mon, Apr 13, 2009 at 10:12:27PM -0400, Perrin Harkins wrote:
> 
> In your Image.pm module, do you declare a package name?  Do you export
> get_image_name()?  How do you load this module in your new Mason
> setup?
> 
The entire Example/Image.pm:

----------8<---------->8----------

package Example::Image;

use Image::ExifTool;
use vars qw( %dirs %urls );

sub get_image_data ($;$$) {
  my $image_name = $_[0];
  my $image_src = $_[1] ? $_[1] : $urls{'img'};
  my $image_dir = $_[2] ? $_[2] : $dirs{'img'};
  my %image_data;
  $image_data{'src'} = $image_src . $image_name;
  my $info = Image::ExifTool::ImageInfo($image_dir . $image_name);
  $image_data{'comment'} = $$info{'Comment'};
  $image_data{'width'} = $$info{'ImageWidth'};
  $image_data{'height'} = $$info{'ImageHeight'};
  return %image_data;
}

1;

----------8<---------->8----------

The module is loaded with a 'PerlModule Example::Image' directive.  I
have also tried without the PerlModule directive and with 'use' in the
global.asa (for Apache::ASP) and the main component (for HTML::Mason).

> > This has really been causing me to wrack my brain since
> > it only occurs on the production server and not on the development
> > server (both are identically configured).
> 
> Are they really identically configured?  Are you sure there isn't a
> difference in startup.pl or in MaxRequestsPerChild or something like
> that?
> 
I have no startup.pl and the MaxRequestsPerChild setting is identical
for both servers.

The only differences that I found were mod_include and mod_disk_cache
were enabled on the development server, but not on the production
server.  I have enabled them in production to see if that makes a
difference.  For the moment, the 500 errors have seemingly disappeared.
However, they have on occasion disappeared only to return after a day or
so.

But for now it appears to be OK for a few tens of thousands of requests.

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by "Roberto C. Sánchez" <ro...@connexer.com>.
On Wed, Apr 15, 2009 at 10:29:20AM +0200, Torsten Foertsch wrote:
> 
> Ok, then how about checking if your module is really loaded. 
> Apache2::Status provides that or you could probably use this 
> PerlResponseHandler (untested):
> 
> <Location /DUMPMODULES>
>   SetHandler modperl
>   PerlResponseHandler "sub {              \
>     use Data::Dumper;                     \
>     use Apache2::RequestRec();            \
>     use Apache2::RequestIO();             \
>     $_[0]->content_type(q{text/plain});   \
>     $_[0]->print(Dumper(\%INC));          \
>     return 0;                             \
>   }"
> </Location>
> 
> It prints %INC to the browser. So you can check if your module is loaded 
> from the correct path.
> 
This is in the output:

'Example/Image.pm' => '/etc/perl/Example/Image.pm'

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by Torsten Foertsch <to...@gmx.net>.
On Wed 15 Apr 2009, Roberto C. Sánchez wrote:
> > Would it be possible to post your module? Perhaps you forgot
> > the "package" declaration?
>
> ----------8<---------->8----------
>
> package Example::Image;

Ok, then how about checking if your module is really loaded. 
Apache2::Status provides that or you could probably use this 
PerlResponseHandler (untested):

<Location /DUMPMODULES>
  SetHandler modperl
  PerlResponseHandler "sub {              \
    use Data::Dumper;                     \
    use Apache2::RequestRec();            \
    use Apache2::RequestIO();             \
    $_[0]->content_type(q{text/plain});   \
    $_[0]->print(Dumper(\%INC));          \
    return 0;                             \
  }"
</Location>

It prints %INC to the browser. So you can check if your module is loaded 
from the correct path.

Torsten

-- 
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net

Re: Undefined subroutine error

Posted by "Roberto C. Sánchez" <ro...@connexer.com>.
On Tue, Apr 14, 2009 at 07:48:49PM +0200, Torsten Foertsch wrote:
> On Tue 14 Apr 2009, Roberto C. Sánchez wrote:
> > I am currently using the latter call everywhere and it is still
> > generating the "Undefined subroutine" error.
> 
> Would it be possible to post your module? Perhaps you forgot 
> the "package" declaration?
> 

----------8<---------->8----------

package Example::Image;

use Image::ExifTool;
use vars qw( %dirs %urls );

sub get_image_data ($;$$) {
  my $image_name = $_[0];
  my $image_src = $_[1] ? $_[1] : $urls{'img'};
  my $image_dir = $_[2] ? $_[2] : $dirs{'img'};
  my %image_data;
  $image_data{'src'} = $image_src . $image_name;
  my $info = Image::ExifTool::ImageInfo($image_dir . $image_name);
  $image_data{'comment'} = $$info{'Comment'};
  $image_data{'width'} = $$info{'ImageWidth'};
  $image_data{'height'} = $$info{'ImageHeight'};
  return %image_data;
}

1;

----------8<---------->8----------

Also, let me ephasize that I have three sites using this exact same
module in the same exact manner as the problem site, yet without any
sort of problem.

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by Torsten Foertsch <to...@gmx.net>.
On Tue 14 Apr 2009, Roberto C. Sánchez wrote:
> I am currently using the latter call everywhere and it is still
> generating the "Undefined subroutine" error.

Would it be possible to post your module? Perhaps you forgot 
the "package" declaration?

Torsten

-- 
Need professional mod_perl support?
Just hire me: torsten.foertsch@gmx.net

Re: Undefined subroutine error

Posted by "Roberto C. Sánchez" <ro...@connexer.com>.
On Tue, Apr 21, 2009 at 01:30:58PM -0400, Perrin Harkins wrote:
> On Tue, Apr 21, 2009 at 12:22 PM, Roberto C. Sánchez
> <ro...@connexer.com> wrote:
> > So, on a lark I tried moving the "PerlModule Example::Image" from the
> > .htacess file to the virtual host configuration.  I then restarted
> > apache.  So far, it seems to have been working for several days.  In the
> > past, the problem would usually manifest itself within 8 hours or so of
> > an apache restart.
> 
> Why were you putting it in a .htaccess file?  Were you trying to avoid
> loading it until people access a certain directory?
> 
I have the .htaccess in subversion, but not the virtual host config.

> > Could this have something to do with threading?
> 
> Are you using a threaded MPM?  That's not recommended unless you're on
> Windows because of memory consumption.  I haven't heard any bug
> reports about this kind of behavior on threads though.
> 
I'm actually using apache2-mpm-prefork.

Regards,

-Roberto
-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by Perrin Harkins <ph...@gmail.com>.
On Tue, Apr 21, 2009 at 12:22 PM, Roberto C. Sánchez
<ro...@connexer.com> wrote:
> So, on a lark I tried moving the "PerlModule Example::Image" from the
> .htacess file to the virtual host configuration.  I then restarted
> apache.  So far, it seems to have been working for several days.  In the
> past, the problem would usually manifest itself within 8 hours or so of
> an apache restart.

Why were you putting it in a .htaccess file?  Were you trying to avoid
loading it until people access a certain directory?

> Could this have something to do with threading?

Are you using a threaded MPM?  That's not recommended unless you're on
Windows because of memory consumption.  I haven't heard any bug
reports about this kind of behavior on threads though.

- Perrin

Re: Undefined subroutine error

Posted by "Roberto C. Sánchez" <ro...@connexer.com>.
On Tue, Apr 14, 2009 at 01:56:57PM -0400, Perrin Harkins wrote:
> On Tue, Apr 14, 2009 at 1:34 PM, Roberto C. Sánchez
> <ro...@connexer.com> wrote:
> > On Tue, Apr 14, 2009 at 01:21:09PM -0400, Perrin Harkins wrote:
> >> On Tue, Apr 14, 2009 at 12:48 PM, Roberto C. Sánchez
> >> <ro...@connexer.com> wrote:
> >> > As far as loading the module, I have tried:
> >> >
> >> >  - "PerlModule Example::Image" in .htaccess
> >> >  - "use Example::Image;" in the main HTML::Mason component
> >>
> >> Either of those should be ok.  If you decide to export the sub later,
> >> you'd need to call it from Mason.
> >>
> > I'm not sure what you mean by this.
> 
> Well, read up about exporting and then it should make more sense.
> Perl has namespaces, and when you export a sub you need to export it
> to the namespace where you want to call it, which is Mason in this
> case.
> 

So, on a lark I tried moving the "PerlModule Example::Image" from the
.htacess file to the virtual host configuration.  I then restarted
apache.  So far, it seems to have been working for several days.  In the
past, the problem would usually manifest itself within 8 hours or so of
an apache restart.

Could this have something to do with threading?

Regards,

-Roberto
-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by Perrin Harkins <ph...@gmail.com>.
On Tue, Apr 14, 2009 at 1:34 PM, Roberto C. Sánchez
<ro...@connexer.com> wrote:
> On Tue, Apr 14, 2009 at 01:21:09PM -0400, Perrin Harkins wrote:
>> On Tue, Apr 14, 2009 at 12:48 PM, Roberto C. Sánchez
>> <ro...@connexer.com> wrote:
>> > As far as loading the module, I have tried:
>> >
>> >  - "PerlModule Example::Image" in .htaccess
>> >  - "use Example::Image;" in the main HTML::Mason component
>>
>> Either of those should be ok.  If you decide to export the sub later,
>> you'd need to call it from Mason.
>>
> I'm not sure what you mean by this.

Well, read up about exporting and then it should make more sense.
Perl has namespaces, and when you export a sub you need to export it
to the namespace where you want to call it, which is Mason in this
case.

> I am currently using the latter call everywhere and it is still
> generating the "Undefined subroutine" error.

Then you must not be getting same error message that you posted to the
Apache::ASP list.  That was:
&Apache::ASP::Compiles::__ASP__srv_http_www_e_ample_com__x::get_image_data

This error message is what you get when you haven't defined that sub
in the current namespace and are calling it as get_image_data().  You
wouldn't get this message from calling
Example::Image::get_image_data().

- Perrin

Re: Undefined subroutine error

Posted by "Roberto C. Sánchez" <ro...@connexer.com>.
On Tue, Apr 14, 2009 at 01:21:09PM -0400, Perrin Harkins wrote:
> On Tue, Apr 14, 2009 at 12:48 PM, Roberto C. Sánchez
> <ro...@connexer.com> wrote:
> > As far as loading the module, I have tried:
> >
> >  - "PerlModule Example::Image" in .htaccess
> >  - "use Example::Image;" in the main HTML::Mason component
> 
> Either of those should be ok.  If you decide to export the sub later,
> you'd need to call it from Mason.
> 
I'm not sure what you mean by this.

> > As far as calling the function:
> >
> >  - get_image_data('masthead.png', $urls{'img'}, $dirs{'img'});
> >  - Example::Image::get_image_data('masthead.png', $urls{'img'}, $dirs{'img'});
> 
> Ok, I don't see how the first one could work with the code you've
> shown.  You're defining the sub in a package, so you either have to
> export it or call it with the fully-qualified path, like you do in the
> second case.
> 
I have used the first syntax and have not noticed a different in the
prevalence of the "Undefined subroutine" error between the two.

> If you're not familiar with this stuff, read up on exporting in the
> perlmod man page or your favorite Perl book.
> 
> If you use the second syntax everywhere, I think this problem will go
> away.  The issue is with the sub being available in your current
> namespace, not with loading the module.
> 
I am currently using the latter call everywhere and it is still
generating the "Undefined subroutine" error.

> - Perrin

Regards,

-Roberto
-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by Perrin Harkins <ph...@gmail.com>.
On Tue, Apr 14, 2009 at 12:48 PM, Roberto C. Sánchez
<ro...@connexer.com> wrote:
> As far as loading the module, I have tried:
>
>  - "PerlModule Example::Image" in .htaccess
>  - "use Example::Image;" in the main HTML::Mason component

Either of those should be ok.  If you decide to export the sub later,
you'd need to call it from Mason.

> As far as calling the function:
>
>  - get_image_data('masthead.png', $urls{'img'}, $dirs{'img'});
>  - Example::Image::get_image_data('masthead.png', $urls{'img'}, $dirs{'img'});

Ok, I don't see how the first one could work with the code you've
shown.  You're defining the sub in a package, so you either have to
export it or call it with the fully-qualified path, like you do in the
second case.

If you're not familiar with this stuff, read up on exporting in the
perlmod man page or your favorite Perl book.

If you use the second syntax everywhere, I think this problem will go
away.  The issue is with the sub being available in your current
namespace, not with loading the module.

- Perrin

Re: Undefined subroutine error

Posted by "Roberto C. Sánchez" <ro...@connexer.com>.
On Tue, Apr 14, 2009 at 12:36:25PM -0400, Perrin Harkins wrote:
> On Tue, Apr 14, 2009 at 8:38 AM, Roberto C. Sánchez
> <ro...@connexer.com> wrote:
> > OK, so the changes to include the mod_include and mod_disk_cache on the
> > production server did not do the trick.  The problem persists.
> 
> I think it's all about the way you export your function, but you
> haven't answered my question about how you call it.
> 
Sorry, I thought that you were asking how I loaded the module.  It
appears that you want to know how I call the specific function.

As far as loading the module, I have tried:

 - "PerlModule Example::Image" in .htaccess
 - "use Example::Image;" in the main HTML::Mason component

As far as calling the function:

 - get_image_data('masthead.png', $urls{'img'}, $dirs{'img'});
 - Example::Image::get_image_data('masthead.png', $urls{'img'}, $dirs{'img'});

As far as "exporting", I'm not sure to what you are referring.

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by Perrin Harkins <ph...@gmail.com>.
On Tue, Apr 14, 2009 at 8:38 AM, Roberto C. Sánchez
<ro...@connexer.com> wrote:
> OK, so the changes to include the mod_include and mod_disk_cache on the
> production server did not do the trick.  The problem persists.

I think it's all about the way you export your function, but you
haven't answered my question about how you call it.

- Perrin

Re: Undefined subroutine error

Posted by "Roberto C. Sánchez" <ro...@connexer.com>.
On Mon, Apr 13, 2009 at 10:12:27PM -0400, Perrin Harkins wrote:
> 
> Are they really identically configured?  Are you sure there isn't a
> difference in startup.pl or in MaxRequestsPerChild or something like
> that?
> 
OK, so the changes to include the mod_include and mod_disk_cache on the
production server did not do the trick.  The problem persists.

Regards,

-Roberto

-- 
Roberto C. Sánchez
http://people.connexer.com/~roberto
http://www.connexer.com

Re: Undefined subroutine error

Posted by Perrin Harkins <pe...@elem.com>.
On Mon, Apr 13, 2009 at 8:21 PM, Roberto C. Sánchez
<ro...@connexer.com> wrote:
> I've been dealing with trying to figure out an "Undefined subroutine"
> error on one of my sites.  At first I thought it was something to do
> with Apache::ASP, so I sent a message requesting help to that list:
> http://mail-archives.apache.org/mod_mbox/perl-asp/200811.mbox/thread
>
> However, even after upgrading the server from Debian Etch to Lenny and
> migrating the site from Apache::ASP to HTML::Mason, I still get the
> exact same "Undefined subroutine" error.  That makes me think that this
> something at a lower level.

In your Image.pm module, do you declare a package name?  Do you export
get_image_name()?  How do you load this module in your new Mason
setup?

> This has really been causing me to wrack my brain since
> it only occurs on the production server and not on the development
> server (both are identically configured).

Are they really identically configured?  Are you sure there isn't a
difference in startup.pl or in MaxRequestsPerChild or something like
that?

- Perrin