You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Jim Schueler <js...@tqis.com> on 2002/07/11 22:46:17 UTC

END subroutine in Apache::Registry

I just read the fine print: Apache::Registry runs BEGIN subroutines just 
once per child process, but END routines run every time a script is run.  
The implication is that an otherwise robust module may behave unexpectedly 
when it's imported by an Apache::Registry script.  Doesn't this cause 
problems for mod_perl users?  There is no mention of this issue in either 
mod_perl_to_cgi or mod_perl_traps.

Admittedly, most of the code in my END subroutines should probably be 
refactored into OO DESTROY subroutines anyways.  But if not burned, I've
been significantly scalded by this belated realization.

I don't see anything on CPAN that can be easily applied to all of the
modules that written.  I'll happily fill that void, but I must be
overlooking the obvious solution.  Can anyone provide any insights?

Jim Schueler
Motor City Interactive

Re: END subroutine in Apache::Registry

Posted by Stas Bekman <st...@stason.org>.
Hi Jim,

> The documentation is neither unclear nor confusing.  However, the
> implication was not obvious (well... not obvious enough) when I first read
> this section three years ago.  If you're sincere about wanting
> suggestions, here's mine:

of course :)

> In addition to understanding the behavior of END blocks in
> Apache::Registry scripts, a script writer must realize that any module
> invoked via "use" or "include" may work differently than its designer
> intended, if that module contains END blocks.

great, will add that. Though I've noticed that it works this way only if 
you 'use'. if you 'require' it's being ignored completely (not even run 
on the shutdown), is it just me or do you see the same? seems like a bug 
to me, unless I'm missing something.

Thanks Jim!

>  -Jim
> 
> 
> On Fri, 12 Jul 2002, Stas Bekman wrote:
> 
> 
>>Jim Schueler wrote:
>>
>>>I just read the fine print: Apache::Registry runs BEGIN subroutines just 
>>>once per child process, but END routines run every time a script is run.  
>>>The implication is that an otherwise robust module may behave unexpectedly 
>>>when it's imported by an Apache::Registry script.  Doesn't this cause 
>>>problems for mod_perl users?  There is no mention of this issue in either 
>>>mod_perl_to_cgi or mod_perl_traps.
>>>
>>>Admittedly, most of the code in my END subroutines should probably be 
>>>refactored into OO DESTROY subroutines anyways.  But if not burned, I've
>>>been significantly scalded by this belated realization.
>>>
>>>I don't see anything on CPAN that can be easily applied to all of the
>>>modules that written.  I'll happily fill that void, but I must be
>>>overlooking the obvious solution.  Can anyone provide any insights?
>>
>>Please read:
>>http://perl.apache.org/release/docs/1.0/guide/porting.html#END_blocks
>>
>>The special case is for registry scripts that include END blocks. If the 
>>the explanation at the above URL is unclear/confusing, please suggest 
>>how to improve it.
>>
>>__________________________________________________________________
>>Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
>>http://stason.org/     mod_perl Guide ---> http://perl.apache.org
>>mailto:stas@stason.org http://use.perl.org http://apacheweek.com
>>http://modperlbook.org http://apache.org   http://ticketmaster.com
>>
> 



-- 


__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: END subroutine in Apache::Registry

Posted by Jim Schueler <js...@tqis.com>.
Hi Stas.

The documentation is neither unclear nor confusing.  However, the
implication was not obvious (well... not obvious enough) when I first read
this section three years ago.  If you're sincere about wanting
suggestions, here's mine:

In addition to understanding the behavior of END blocks in
Apache::Registry scripts, a script writer must realize that any module
invoked via "use" or "include" may work differently than its designer
intended, if that module contains END blocks.

 -Jim


On Fri, 12 Jul 2002, Stas Bekman wrote:

> Jim Schueler wrote:
> > I just read the fine print: Apache::Registry runs BEGIN subroutines just 
> > once per child process, but END routines run every time a script is run.  
> > The implication is that an otherwise robust module may behave unexpectedly 
> > when it's imported by an Apache::Registry script.  Doesn't this cause 
> > problems for mod_perl users?  There is no mention of this issue in either 
> > mod_perl_to_cgi or mod_perl_traps.
> > 
> > Admittedly, most of the code in my END subroutines should probably be 
> > refactored into OO DESTROY subroutines anyways.  But if not burned, I've
> > been significantly scalded by this belated realization.
> > 
> > I don't see anything on CPAN that can be easily applied to all of the
> > modules that written.  I'll happily fill that void, but I must be
> > overlooking the obvious solution.  Can anyone provide any insights?
> 
> Please read:
> http://perl.apache.org/release/docs/1.0/guide/porting.html#END_blocks
> 
> The special case is for registry scripts that include END blocks. If the 
> the explanation at the above URL is unclear/confusing, please suggest 
> how to improve it.
> 
> __________________________________________________________________
> Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
> http://stason.org/     mod_perl Guide ---> http://perl.apache.org
> mailto:stas@stason.org http://use.perl.org http://apacheweek.com
> http://modperlbook.org http://apache.org   http://ticketmaster.com
> 


Re: END subroutine in Apache::Registry

Posted by Stas Bekman <st...@stason.org>.
>>Please read:
>>http://perl.apache.org/release/docs/1.0/guide/porting.html#END_blocks
>>
>>The special case is for registry scripts that include END blocks. If the 
>>the explanation at the above URL is unclear/confusing, please suggest 
>>how to improve it.
> 
> 
> It's pretty clear, and the bit about BEGIN blocks is right next to it,
> but it might be worth adding a note about the imbalance between BEGIN
> blocks and END blocks under Apache::Registry to cover this issue.

I don't think there is really a need, but if we do so, the "imbalance" 
is between END and all *other* special blocks, like INIT, CHECK, BEGIN 
etc. So I believe that what is says now is just fine. The registry END 
block is the black sheep...

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


Re: END subroutine in Apache::Registry

Posted by Ged Haywood <ge...@www2.jubileegroup.co.uk>.
Hi Jim, Stas,

On Fri, 12 Jul 2002, Stas Bekman wrote:

> Jim Schueler wrote:
> > I just read the fine print:

:)  Good man.

> > Apache::Registry runs BEGIN subroutines just once per child
> > process, but END routines run every time a script is run.  The
> > implication is that an otherwise robust module may behave
> > unexpectedly when it's imported by an Apache::Registry script.

Yup.

> >  Doesn't this cause problems for mod_perl users?

Only at first. :)

> > There is no mention of this issue in either mod_perl_to_cgi or
> > mod_perl_traps.

The Apache::Registry documentation is probably the more appropriate
place for this, since Apache::Registry is an acknowledged hack anyway
and you should really be aiming to use handlers...

> Please read:
> http://perl.apache.org/release/docs/1.0/guide/porting.html#END_blocks
> 
> The special case is for registry scripts that include END blocks. If the 
> the explanation at the above URL is unclear/confusing, please suggest 
> how to improve it.

It's pretty clear, and the bit about BEGIN blocks is right next to it,
but it might be worth adding a note about the imbalance between BEGIN
blocks and END blocks under Apache::Registry to cover this issue.

73,
Ged.


Re: END subroutine in Apache::Registry

Posted by Stas Bekman <st...@stason.org>.
Jim Schueler wrote:
> I just read the fine print: Apache::Registry runs BEGIN subroutines just 
> once per child process, but END routines run every time a script is run.  
> The implication is that an otherwise robust module may behave unexpectedly 
> when it's imported by an Apache::Registry script.  Doesn't this cause 
> problems for mod_perl users?  There is no mention of this issue in either 
> mod_perl_to_cgi or mod_perl_traps.
> 
> Admittedly, most of the code in my END subroutines should probably be 
> refactored into OO DESTROY subroutines anyways.  But if not burned, I've
> been significantly scalded by this belated realization.
> 
> I don't see anything on CPAN that can be easily applied to all of the
> modules that written.  I'll happily fill that void, but I must be
> overlooking the obvious solution.  Can anyone provide any insights?

Please read:
http://perl.apache.org/release/docs/1.0/guide/porting.html#END_blocks

The special case is for registry scripts that include END blocks. If the 
the explanation at the above URL is unclear/confusing, please suggest 
how to improve it.

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com