How about:

package ModPerlPackage;

use vars qw( $is_init );
$is_init = 0;

sub handler($) {
        ...
        $is_init = initialize($r) unless $is_init;
        ...
}

Just making initialize return a true value on success.

There's undoubtedly a much more subtle solution...

HTH

Jim



Rafael Kitover wrote:
> 
> We obviously do not have access to a request object during a BEGIN {}
> block, but if I have a bunch of PerlSetVar things that I don't want to
> re-initialize every time handler() is called for speed reasons, what is
> the most elegant way to have an initialization sub that needs access to
> things set in PerlSetVar? Just something like:
> 
> my $is_initialized = 0;
> 
> sub handler($) {
>         ...
>         unless ($is_initialized) {
>                 initialize($r);
>                 $is_initialized = 1;
>         }
>         ...
> }
> 
> sub initialize($) {
>         ...
>         do stuff with $r->dir_info("thingie")
>         ...
> }
> 
> The problem with this is that initialize would be called for every
> child, though this is better than initializing stuff at every request.
> 
> TIA
> 
> --
> Do what thou wilt shall be the whole of the Law.
> Love is the law, love under will.
> 
>   ------------------------------------------------------------------------
>    Part 1.2Type: application/pgp-signature

Reply via email to