perl-asp mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tim Pushor" <t...@crossthread.com>
Subject Re: use script variables in cleanup code?
Date Mon, 11 Feb 2002 21:09:09 GMT
Joshua,

Thanks again for your help. I'm not much of a perl programmer, and it didn't
occur to me that passing the ref in the anonymous sub would be enough to
keep it in scope.

So does the cleanup handler run regardless of whether the script is aborted
or not? Is there any (built in) way of determining if the script went to
completion?

Thanks!
Tim

----- Original Message -----
From: "Joshua Chamas" <joshua@chamas.com>
To: "Tim Pushor" <timp@crossthread.com>
Cc: <asp@perl.apache.org>
Sent: Sunday, February 10, 2002 3:29 PM
Subject: Re: use script variables in cleanup code?


> > Tim Pushor wrote:
> >
> > Is there a way to use local script variables in your cleanup code?
Whatabout variables/functions declared in global.ini?
> >
> > I would think you could use your session or application object if you
can, but I don't have any need for either in this app.
> >
> > I specifically need to be able to call a function declared in
global.ini, and would like to somehow be able to operate on objects defined
in the asp
> > page before it goes out of scope - i.e.
> >
> > <%
> >      sub handler {
> >         my $n=some_magic;
> >         $n->unlock
> >         log failure;
> >     }
> >
> >     $n=new object;
> >     $Server->RegisterCleanup (&handler);
> >     $n->lock;
> >     .. do stuff ..
> >     $n->unlock;
> >     log success;
> >
>
> I believe you are on the right track, how about:
>
> # in script
> <%
>   my $n = new object;
>   $Server->RegisterCleanup(sub { &handler($n) });
> %>
>
> # in global.asa
> sub handler {
>   my $n = shift || die("need \$n to handle");
>   ...
> }
>
> Even if originally declared with my($n), the $n should stay in
> scope until after the script ends because it was being used
> in the runtime sub {} that was installed for RegisterCleanup
>
> Also, make sure to turn on PerlSetVar UseStrict if you have
> not done so already, as this will save you many headaches
> down the road.
>
> -- Josh
> _________________________________________________________________
> Joshua Chamas                           Chamas Enterprises Inc.
> NodeWorks Founder                       Huntington Beach, CA  USA
> http://www.nodeworks.com                1-714-625-4051
>


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


Mime
View raw message