You are viewing a plain text version of this content. The canonical link for it is here.
Posted to asp@perl.apache.org by Arnon Weinberg <ar...@ca.mci.com> on 2004/08/24 00:28:09 UTC

Can't undef active subroutine

I'm getting the following in my error_log:
[asp] [12696] [error] Can't undef active subroutine at 
/usr/lib/perl5/site_perl/5.8.0/Apache/ASP.pm line 1320. <--> , 
/usr/lib/perl5/site_perl/5.8.0/Apache/ASP.pm line 1518

The following code is sufficient to replicate the problem.  Basically, a 
recursive script that declares a subroutine.  I saw in the style guide that 
in-script subroutine declaration is bad because of closures, but I'm 
getting a run-time error here, and there are no variables being declared - 
in fact the subroutine is not even being called.

<%
   sub foo {}

   if ( ! $_[0] )
   {
     print "1st entry<br>\n";

     $Response->Include ( $ENV{SCRIPT_FILENAME}, 1 );
   }
   else
   {
     print "Re-entry<br>\n";
   }
%>

This error happens with Apache::ASP version 2.57-8, but not with 2.35-1 (I 
didn't try other versions) - ie, downgrading fixes the problem for 
me.  However, I would like to be able to upgrade at some point using this code.

Further details:
mod_perl-1.99_12-2
httpd-2.0.50-1.0

Any thoughts?


----------------------------------------------------------------------------
Arnon Weinberg <ar...@ca.mci.com>
Rapid Applications Development (RAD) Programmer
Systems group, MCI Canada
416-216-5311     pager: 416-791-7594     vnet: 842-5311


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Can't undef active subroutine

Posted by Warren Young <wa...@etr-usa.com>.
Arnon Weinberg wrote:

>  is to add a config option
> to control the script caching behavior so that people aware of the 
> closure issues can use embedded subs more freely; 

I'd rather that Apache::ASP refused to run on an ASP page with 
subroutines defined by default, and let you flip a config switch to 
force it to accept it.  That way, people wouldn't make Apache::ASP's 
life hard without being aware that they're doing it.

More likely, the error they get without the config flag set would 
encourage them to move the subroutines to someplace that doesn't cause 
problems.

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Can't undef active subroutine

Posted by Arnon Weinberg <ar...@ca.mci.com>.
In the end, this is just a style issue, as surely subroutines can be 
declared elsewhere.  I would prefer to have my subroutines in the script in 
this particular instance because ... well, that's where they belong.  This 
script is the only one using them, and the subroutines reference global 
variables declared and used in this script.  No big deal, but I thought I'd 
give it a shot.

I'd come up with the code ref solution as well, but again, I'm trying to 
solve a style issue, and that's kinda ugly too.  Thanks for replying 
though, I now know my options, and have "closure" on the issue - pun intended.

One thing I might suggest, if it seems worthy, is to add a config option to 
control the script caching behavior so that people aware of the closure 
issues can use embedded subs more freely; but that's about all I can think of.


>This is interesting, but possibly unavoidable.  If there is a good reason to
>create a fix for this, perhaps we can find one.   Like the prior post 
>said, its
>bad form to have subs in the script, and causes no end of problems.
>
>To work around the closure issue that was catching a lot of people, recent
>releases of Apache::ASP do not cache a script compilation that has a 
>subroutine
>defined in it, so the script is recompiled each time.  Now it seems that 
>you are
>calling a routine, which calls itself and Apache::ASP tries to undefine the
>existing subroutine with another compilation, and of course this does not work
>since the subroutine is actively executing.  Perhaps this is a "feature"
>because having the subs in the script itself could result in a closure/sticky
>variable again when it tries to execute itself if it were still compiled 
>and we
>cached the compilation.
>
>My advice is if you really need to have subs in your script, then define 
>it as a
>code ref like so:
>
>my $foo = sub {};
>&$foo;
>
>this will not have closure problems since you are executing it per 
>request, and
>it will therefore do the right thing, as well as allow recursive calling 
>of the
>script.  Better yet if the subs can be moved to the global.asa or perl module.
>
>Regards,
>
>Josh
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
>For additional commands, e-mail: asp-help@perl.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Can't undef active subroutine

Posted by Joshua Chamas <jo...@chamas.com>.
Quoting Arnon Weinberg <ar...@ca.mci.com>:

>
> I'm getting the following in my error_log:
> [asp] [12696] [error] Can't undef active subroutine at
> /usr/lib/perl5/site_perl/5.8.0/Apache/ASP.pm line 1320. <--> ,
> /usr/lib/perl5/site_perl/5.8.0/Apache/ASP.pm line 1518
>
> The following code is sufficient to replicate the problem.  Basically, a
> recursive script that declares a subroutine.  I saw in the style guide that
> in-script subroutine declaration is bad because of closures, but I'm
> getting a run-time error here, and there are no variables being declared -
> in fact the subroutine is not even being called.
>
> <%
>    sub foo {}
>

This is interesting, but possibly unavoidable.  If there is a good reason to
create a fix for this, perhaps we can find one.   Like the prior post said, its
bad form to have subs in the script, and causes no end of problems.

To work around the closure issue that was catching a lot of people, recent
releases of Apache::ASP do not cache a script compilation that has a subroutine
defined in it, so the script is recompiled each time.  Now it seems that you are
calling a routine, which calls itself and Apache::ASP tries to undefine the
existing subroutine with another compilation, and of course this does not work
since the subroutine is actively executing.  Perhaps this is a "feature"
because having the subs in the script itself could result in a closure/sticky
variable again when it tries to execute itself if it were still compiled and we
cached the compilation.

My advice is if you really need to have subs in your script, then define it as a
code ref like so:

my $foo = sub {};
&$foo;

this will not have closure problems since you are executing it per request, and
it will therefore do the right thing, as well as allow recursive calling of the
script.  Better yet if the subs can be moved to the global.asa or perl module.

Regards,

Josh



---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org


Re: Can't undef active subroutine

Posted by Warren Young <wa...@etr-usa.com>.
Arnon Weinberg wrote:

> <%
>   sub foo {}

Don't do that!

Put subroutines in either global.asa, or in a separate Perl module.

If you search the Apache::ASP documentation, you will find where it 
specifically tells you not to define subroutines in your ASP files.  It 
has to do with the way the ASP files are processed.

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe@perl.apache.org
For additional commands, e-mail: asp-help@perl.apache.org