vc_will_do has asked for the wisdom of the Perl Monks concerning the following question:

I am new to mod_perl. From "practical_modperl", I have learned that we can hook handlers on different phases of a request namely

PerlPostReadRequestHandler PerlTransHandler PerlInitHandler PerlHeaderParserHandler PerlAuthenHandler PerlAuthzHandler PerlAccessHandler PerlTypeHandler PerlFixupHandler PerlHandler PerlLogHandler PerlCleanupHandler PerlChildInitHandler PerlChildExitHandler PerlDispatchHandler
it explains  PerlHandler or PerlResponseHandler ( mod_perl2 ) very well. I am much interested in other handlers like PerlAuthenHandler, PerlAuthzHandler etc... Can anybody get me some document/tutorial with some simple basic examples of these?

Thanks for all your help.

Replies are listed 'Best First'.
Re: mod_perl2 hooks
by atemon (Chaplain) on Aug 31, 2007 at 04:38 UTC

    Hi,

    To get example for all handlers, have a look at mod_perl2 HTTP Handlers.

    This is a code thats there in "practical mod_perl" itself, which explains few most useful handlers. (works with mod_perl 1.x or with Apache2::compat ).

    Apache conf (httpd.conf)

    PerlModule Book::StartupLog PerlOpenLogsHandler Book::StartupLog::open_logs PerlPostConfigHandler Book::StartupLog::post_config PerlChildInitHandler Book::StartupLog::child_init PerlChildExitHandler Book::StartupLog::child_exit

    The Perl code

    package Book::StartupLog; use strict; use warnings; use Apache::Log ( ); use Apache::ServerUtil ( ); use File::Spec::Functions; use Apache::Const -compile => 'OK'; my $log_file = catfile "logs", "startup_log"; my $log_fh; sub open_logs { my($conf_pool, $log_pool, $temp_pool, $s) = @_; my $log_path = Apache::server_root_relative($conf_pool, $log_file) +; $s->warn("opening the log file: $log_path"); open $log_fh, ">>$log_path" or die "can't open $log_path: $!"; my $oldfh = select($log_fh); $| = 1; select($oldfh); say("process $$ is born to reproduce"); return Apache::OK; } sub post_config { my($conf_pool, $log_pool, $temp_pool, $s) = @_; say("configuration is completed"); return Apache::OK; } sub child_exit { my($child_pool, $s) = @_; say("process $$ now exits"); return Apache::OK; } sub child_init { my($child_pool, $s) = @_; say("process $$ is born to serve"); return Apache::OK; } sub say { my($caller) = (caller(1))[3] =~ /([^:]+)$/; if (defined $log_fh) { printf $log_fh "[%s] - %-11s: %s\n", scalar(localtime), $caller, $_[0]; } else { # when the log file is not open warn __PACKAGE__ . " says: $_[0]\n"; } } END { say("process $$ is shutdown\n"); } 1;
    Hope this helps.

    Cheers !

    --VC



    There are three sides to any argument.....
    your side, my side and the right side.

Re: mod_perl2 hooks
by perrin (Chancellor) on Aug 31, 2007 at 04:44 UTC