You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Matthew <ma...@matthewboehm.com> on 2006/05/03 00:43:13 UTC

the dreaded 'subroutine redefined'

Hey gang,
  When I actually execute the code in web browser 
(http://www.mydomain.com/test/tester), I get this in my apache error_log:

[Tue May  2 23:33:57 2006] v2.pm: Subroutine handler redefined at 
/home/me/public_html/confer//mypackage/tester.pm line 10.
<..repeats for each subroutine in the file..>

My httpd.conf section relating to mod_perl is thus:

PerlModule      Apache2::Reload
PerlInitHandler Apache2::Reload
PerlSetVar      ReloadAll Off
PerlRequire     /home/me/public_html/confer/startup.pl
<Location /confer/tester>
         SetHandler              perl-script
         PerlResponseHandler     mypackage::tester
</Location>

Should I be doing "PerlModule mypackage::tester" above the <Location> 
section? Or doing "use mypackage::tester" inside startup.pl?

I read something on google that says I should be using Apache::Symbol 
but I didn't see a mod_perl2 version of that.

Thanks in advance,
Matthew

Re: the dreaded 'subroutine redefined'

Posted by Jonathan Vanasco <jo...@2xlp.com>.
On May 3, 2006, at 4:59 PM, Matthew wrote:

> I had a feeling it was Apache::Reload. In the future, we shouldn't  
> need this module as we won't be making daily changes to the code.
>
> Thanks a million.
> -Matthew

Apache::Reload is simply amazing for development machines (to the  
point that I can't imagine ever turning it off on one ), but you  
really shouldn't run it on your production machines.

There are a few operational caveats, and its a big performance hit.

If  you're getting this on a production box, you should consider  
stripping it out now and just doing a graceful restart when changes  
are made.

Re: the dreaded 'subroutine redefined'

Posted by Matthew <ma...@matthewboehm.com>.
I had a feeling it was Apache::Reload. In the future, we shouldn't need 
this module as we won't be making daily changes to the code.

Thanks a million.
-Matthew

Perrin Harkins wrote:
> On Wed, 2006-05-03 at 16:48 -0400, Perrin Harkins wrote:
> 
>>On Tue, 2006-05-02 at 17:43 -0500, Matthew wrote:
>>
>>>Hey gang,
>>>  When I actually execute the code in web browser 
>>>(http://www.mydomain.com/test/tester), I get this in my apache error_log:
>>>
>>>[Tue May  2 23:33:57 2006] v2.pm: Subroutine handler redefined at 
>>>/home/me/public_html/confer//mypackage/tester.pm line 10.
>>><..repeats for each subroutine in the file..>
>>
>>That's not a problem.  This is just a warning telling you that
>>Apache::Reload has reloaded your module and the sub was redefined.  If
>>it really bothers you, you can add a "no warnings (redefine)" to your
>>version of Apache::Reload.
> 
> 
> Correction:
> Add "no warnings qw(redefine);" to your module.  You shouldn't need to
> modify Apache::Reload.
> 
> - Perrin
> 

Re: the dreaded 'subroutine redefined'

Posted by Perrin Harkins <pe...@elem.com>.
On Wed, 2006-05-03 at 16:48 -0400, Perrin Harkins wrote:
> On Tue, 2006-05-02 at 17:43 -0500, Matthew wrote:
> > Hey gang,
> >   When I actually execute the code in web browser 
> > (http://www.mydomain.com/test/tester), I get this in my apache error_log:
> > 
> > [Tue May  2 23:33:57 2006] v2.pm: Subroutine handler redefined at 
> > /home/me/public_html/confer//mypackage/tester.pm line 10.
> > <..repeats for each subroutine in the file..>
> 
> That's not a problem.  This is just a warning telling you that
> Apache::Reload has reloaded your module and the sub was redefined.  If
> it really bothers you, you can add a "no warnings (redefine)" to your
> version of Apache::Reload.

Correction:
Add "no warnings qw(redefine);" to your module.  You shouldn't need to
modify Apache::Reload.

- Perrin


Re: the dreaded 'subroutine redefined'

Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2006-05-02 at 17:43 -0500, Matthew wrote:
> Hey gang,
>   When I actually execute the code in web browser 
> (http://www.mydomain.com/test/tester), I get this in my apache error_log:
> 
> [Tue May  2 23:33:57 2006] v2.pm: Subroutine handler redefined at 
> /home/me/public_html/confer//mypackage/tester.pm line 10.
> <..repeats for each subroutine in the file..>

That's not a problem.  This is just a warning telling you that
Apache::Reload has reloaded your module and the sub was redefined.  If
it really bothers you, you can add a "no warnings (redefine)" to your
version of Apache::Reload.

- Perrin


Re: the dreaded 'subroutine redefined'

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
Matthew wrote:
> None of my subroutines are prototyped. They all follow the format:
> 
>    sub <name>() {
>      <code>
>    }
As Perrin/Randal said, thats a prototype of no arguments
While I'm on it
&foo
is different from
&foo()

The first gets access to the global @_ (aka whatever function foo was called 
from, its @_ is handed to foo), the latter does not.

Finally, as long as your sub foo {} comes before the call to it (i.e scripts),
you generally don't write the sigil & -- i.e.
&foo(), but merely foo()


> use Apache2::Reload;
You should generally move this to your httpd.conf file and configure it
PerlModule Apache2::Reload
PerlInitHandler Apache2::Reload
PerlSetVar ReloadAll Off
PerlSetVar ReloadModules "confer::tester FOO::*"

You can use
PerlSetVar ReloadDebug On
to get a list in error_log of what files Apache2:Reload is stating to see if 
they need to be reload.  If you only care about one file, you should make this 
list be 1 file via the ReloadModules directive.  This will lessen the 
performance impact as Johnathan pointed out.

> use vars qw($q $r $dbh $template $sql);
just fyi, it takes more memory (bytes) to do this instead of our do to symbol 
table mumbo jumbo.

Finally *sometimes* mod_perl doesn't like it when a function gets 'redefined'
Though I agree with
no warnings qw(redefine);

If you're developing actively, you might notice some strangeness especially if 
you cause a syntax error and hope Apache2::Reload will reload correctly.  Notice 
above, I said SOMETIMES.

HTH

------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F  6A47 D55A 7172 A799 97F

"It takes a minute to have a crush on someone, an hour to like someone,
and a day to love someone, but it takes a lifetime to forget someone..."

Re: the dreaded 'subroutine redefined'

Posted by Matthew <ma...@matthewboehm.com>.
Nope. Didn't realize that () was prototyped.  I should note that I pass 
variables to the functions like so:

if($cmd eq "login") {
   &doLogin($q->param("username"), $q->param("password"));
}

sub doLogin() {
   my ($username, $password) = @_;
   if($username eq "you" && $password eq "me") {
     print "Success";
   } else {
     print "Denied";
   }
}

-Matthew

Randal L. Schwartz wrote:
>>>>>>"Matthew" == Matthew  <ma...@matthewboehm.com> writes:
> 
> 
> Matthew> None of my subroutines are prototyped. They all follow the format:
> Matthew>     sub <name>() {
> Matthew>       <code>
> Matthew>     }
> 
> You realize that's a prototype? :)
> 

Re: the dreaded 'subroutine redefined'

Posted by "Randal L. Schwartz" <me...@stonehenge.com>.
>>>>> "Matthew" == Matthew  <ma...@matthewboehm.com> writes:

Matthew> None of my subroutines are prototyped. They all follow the format:
Matthew>     sub <name>() {
Matthew>       <code>
Matthew>     }

You realize that's a prototype? :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<me...@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

Re: the dreaded 'subroutine redefined'

Posted by Matthew <ma...@matthewboehm.com>.
None of my subroutines are prototyped. They all follow the format:

    sub <name>() {
      <code>
    }

Here are the first few lines of tester.pm and the code for the handler() 
function.
----------------------------------------------------------------------
package confer::tester;

use strict;
use warnings;

use Apache2::Reload;

use vars qw($q $r $dbh $template $sql);

sub handler {
         $r = shift;
         $q = CGI->new();

         # Instance the database connection and wrapper
	# messageDie as the fuction if something fails
         $dbh =
          DBI->connect("DBI:mysql:database=conf;host=:/tmp/mysql.sock;",
                 "tester",
                 "testerpass",
                 {'RaiseError' => 1});

         $dbh->{HandleError} = sub { &messageDie(
		"A database error has occured.", shift, shift) };

         # We will always print out HTML
         $r->content_type("text/html");

         # Instance the template object
         $template = new HTML::Template(filename => 'background.tpl',
                         path => [ '/home/me/public_html/confer/' ],
                         die_on_bad_params => 0,
                         stack_debug => 0,
                         debug => 0);

	# What are we going to do?
         my $cmd = (defined($q->param("_cmd")) ?
		$q->param("_cmd") :
		"logintype");

	if($cmd eq "logintype") {
		&printLogin();
	elsif($cmd eq "stats") {
		&printStats();
	} else {
		&messageDie("How the frack did you get here?");
	}

	return Apache2::Const::OK;
}

Thanks,
Matthew

Philip M. Gollucci wrote:
>> PerlModule      Apache2::Reload
>> PerlInitHandler Apache2::Reload
>> PerlSetVar      ReloadAll Off
>> PerlRequire     /home/me/public_html/confer/startup.pl
>> <Location /confer/tester>
>>         SetHandler              perl-script
>>         PerlResponseHandler     mypackage::tester
>> </Location>
> 
> Can you show some of the file's   sub foo { lines ?
> I've noticed Exporter doesn't always play nice if you protoype your 
> functions
> sub foo ($@;\%) {
> 
> Also, whether or not your preload your module in startup.pl or 
> httpd.conf is merely a choice.
> 
> You can tweak a couple things about the way PerlModule works via 
> PerlOptions
> http://perl.apache.org/docs/2.0/user/config/config.html#C_AutoLoad_
> 
> HTH
> 
> 
> 

Re: the dreaded 'subroutine redefined'

Posted by "Philip M. Gollucci" <pg...@p6m7g8.com>.
> PerlModule      Apache2::Reload
> PerlInitHandler Apache2::Reload
> PerlSetVar      ReloadAll Off
> PerlRequire     /home/me/public_html/confer/startup.pl
> <Location /confer/tester>
>         SetHandler              perl-script
>         PerlResponseHandler     mypackage::tester
> </Location>
Can you show some of the file's   sub foo { lines ?
I've noticed Exporter doesn't always play nice if you protoype your functions
sub foo ($@;\%) {

Also, whether or not your preload your module in startup.pl or httpd.conf is 
merely a choice.

You can tweak a couple things about the way PerlModule works via PerlOptions
http://perl.apache.org/docs/2.0/user/config/config.html#C_AutoLoad_

HTH



-- 
------------------------------------------------------------------------
Philip M. Gollucci (pgollucci@p6m7g8.com) 323.219.4708
Consultant / http://p6m7g8.net/Resume/resume.shtml
Senior Software Engineer - TicketMaster - http://ticketmaster.com
1024D/A79997FA F357 0FDD 2301 6296 690F  6A47 D55A 7172 A799 97F

"It takes a minute to have a crush on someone, an hour to like someone,
and a day to love someone, but it takes a lifetime to forget someone..."