OVH Cloud OVH Cloud

PushHandler avec ModuleConfig

1 réponse
Avatar
Xavier
Bonjour,

pour fignoler un module Apache/modperl, je voudrais remplacer :
PerlInitHandler Mon::Module
par
MonModule On

J'ai préparé le Makefile et tout ce qui est prévu au chapitre 8 de
"Writing Apache modules with Perl and C", mais je ne voie pas comment
mettre en place le Handler dans la procédure MonModule. Y-a-t'il une
entrée particulière dans l'objet $cnf pour ça ?

sub MonModule {
my($cnf,$parms,$arg)=@_;
$cnf{__le_handler?__} = \&myhandler if($arg);
}

Dans la littérature, j'ai vu $cnf{handler}, mais ça semblait appeler un
handler traditionnel et pas Perl. En revanche, je ne trouve aucune doc
sur la classe de l'objet "per-directory/server" $cnf.

Merci.
Xavier

1 réponse

Avatar
Xavier
Bonjour,

pour fignoler un module Apache/modperl, je voudrais remplacer :
PerlInitHandler Mon::Module
par
MonModule On

Ci-dessous la réponse reçue sur la mailing-list modperl :


these are not the same thing, so they will not have the same effect.

both are parsed and executed only once - when you start the server. well,
ok, twice, but who's counting :) they will also be executed each time you
restart the server.

however, the PerlInitHandler directive tells mod_perl to run My::Module for
each request during the post-read phase. a custom directive will not be
able to do that for you.


I've done the XS file using Apache::ExtUtils, but I don't know how to
write the "MyModule" sub. Is there any entry in the $cfg object to do it?

sub MyModule {
my($cfg,$parms,$arg)=@_;
$cfg->{__WHAT__} = &myhandler if($arg);
}

With Google, I've found scripts using "$cfg->{handler}", but they're
calling a standard handler, not a Perl one; I've neither found any doc
about the "per-directory/server" $cfg class.


perl directive handlers are _only_ an access to the httpd.conf parsing
process - they do not register your module nor tell it when to run.
therefore you will always need two directives if you want some request-time
action. at least not with mod_perl 1.0 - in mp2 you should be able to use
Apache::Module::add_config to push the PerlInitHandler into the config
for you.

see recipes 7.8, 7.10, and 7.11 for a few more examples of using directive
handlers:

http://www.modperlcookbook.org/chapters/ch07.pdf

the code for each of these is also available

http://www.modperlcookbook.org/code/ch07/

HTH

--Geoff

--
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html