This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
--------------enigB5654438FF3F1D05AFCA0BD8
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: quoted-printable

titetluc titetluc wrote:
> Hello,
>=20
> I am writing a new mod_perl Apache (mod_perl2) to manage session=20
> tracking and SSO
> This module defines a new Apache directive (MyNewDirective), which is=20
> usable in a , block.
>=20
> For example
>
> Set-Handler perl-script
> MyNewDirective a_test arg1 arg2
> PerlResponseHandler ResponseHandlerToTestTheNewDirective
>

>
> Set-Handler perl-script
> PerlResponseHandler ResponseHandlerToTestTheNewDirective
>

>=20
>=20
> When this directive is used, my module should a PerlLogHandler=20
> automatically to obtain the following configuration
>
> Set-Handler perl-script
> MyNewDirective a_test arg1 arg2
> PerlResponseHandler ResponseHandlerToTestTheNewDirective
> PerlLogHandler TestPerlLogHandler
>

>
> Set-Handler perl-script
> PerlResponseHandler ResponseHandlerToTestTheNewDirective
>

>=20
> I tried to use the push_handler method when the 'MyNewDirective' is def=

ined.
>=20
> my @directives =3D ({name =3D> 'MyNewDirective ', func =3D>=20
> __PACKAGE__.'::MyNewDirective'});
>=20
> Apache2::Module::add(__PACKAGE__, \@directives);
>=20
> sub MyNewDirective {
> my ($self, $parms, $arg) =3D @_;
>=20
> # blablabla
>=20
> $parms->server->push_handlers(PerlLogHandler =3D> sub {my ($r) _ @_=

;=20
> $r->server->error_log('hello world'); return Apache2::Const::OK;});



Right here, you are adding your handler to the current *server* configura=
tion
object, effectively enabling this handler for eery requests to that serve=
r/vhost

> # blablabla
> return;
> }
>=20
> This code works ... but for any blocks.
> For example, if I access the URI '/a_test', the PerlLogHandler will be =


> called BUT if I access the URI '/another_test', the PerlLogHandler will=

=20
> also be called.


See above.

> Do I use the mod_perl API correctly ?


Correctly, yes. Unfortunately, it's not what you are trying to do.

> What is wrong in my code ?


If you want to push your loghandler only for requests for your configured=

module, I would just delay the loghandler registration until runtime and
do it in your content handler with

$r->push_handlerrs(...)

Or you can do it in your command handler, but like so

sub MyLogHandler {
[...]
}

sub MyNewDirective {
my ($self, $param, $arg) =3D @_;

$parms->add_config(["PerlLogHandler MyLogHandler"]);
[...]

--=20
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/


--------------enigB5654438FF3F1D05AFCA0BD8
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFIFuMYyzKhB4jDpaURAoWUAKCkOo6tllhzc4FsUqAcfI v/iyYD6ACfdhQf
iGzq4SiPsixGhzHWKJpDuvg=
=KckB
-----END PGP SIGNATURE-----

--------------enigB5654438FF3F1D05AFCA0BD8--