in reply to Learning mod_perl

what was the thing that bite's me most... is that every your page/script runs inside a sub() i.e.
#mod_perl_handler sub handler { sub your_sub() {}.. ...your script.... }
this means your subs runs as closures (this is very well explained into modperl docs)
One disadventage of running this way is that u should use
our $myvar;
instead of :
my $myvar;
so that vars behave correctly inside your_sub() i.e. they become globals which is good for memory-conserving tehnique, but can be nasty if reused for other purposes by accident. In one email in the past I proposed to Stas Beckman, to use "goto"-variant instead of encompasing mod_perl_sub() so that this become non-issue.
Pseudo code (by memory), havent used mod_perl long time:
#mod_perl-handler package Blah; sub handler { ....house keeping code... goto MYCODE } sub your_sub { .... } MYCODE: ...your code here....

Replies are listed 'Best First'.
Re^2: Learning mod_perl
by adrianh (Chancellor) on Jul 11, 2003 at 23:09 UTC
    what was the thing that bite's me most... is that every your page/script runs inside a sub()

    This is only true if you're using the mod_perl Apache::PerlRun or Apache::Registry handlers - which are mainly used for the conversion of existing CGI based scripts to run under mod_perl.The CGI to mod_perl Porting of the mod_perl guide covers this.

    Once you start writing "native" mod_perl code the problem goes away.

      yep that is true, but most of time ppl write scripts directly using some framework like Apache::ASP, Apache::Registry, Apache::Perlrun etc.. instead of writing mod_perl handlers directly...:")
      Even if mod_perl stays the same, just with one simple options it can be done so that ppl may choose between these 2 variants... it is just a matter of string concatenation...
        yep that is true, but most of time ppl write scripts directly using some framework like Apache::ASP, Apache::Registry, Apache::Perlrun etc.. instead of writing mod_perl handlers directly...:")

        I wasn't trying to say that the other frameworks were bad, just that the "wrapped in sub" thing is not always true. It only applies to certain ways of implementing handlers.

        (I'm also not sure that "most" people use these method. You can't really leverage all of the power of mod_perl until you get beyond Apache::Registry and friends. I rarely use them myself.)

        Even if mod_perl stays the same, just with one simple options it can be done so that ppl may choose between these 2 variants... it is just a matter of string concatenation...

        Sorry. No idea what you mean here.