[MP2][QUESTION]Adding handlers when defining a new directive
am 29.04.2008 10:50:29 von titetluc
------=_Part_10554_26418713.1209459029230
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hello,
I am writing a new mod_perl Apache (mod_perl2) to manage session tracking
and SSO
This module defines a new Apache directive (MyNewDirective), which is usable
in a , block.
For example
Set-Handler perl-script
MyNewDirective a_test arg1 arg2
PerlResponseHandler ResponseHandlerToTestTheNewDirective
Set-Handler perl-script
PerlResponseHandler ResponseHandlerToTestTheNewDirective
When this directive is used, my module should a PerlLogHandler 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
I tried to use the push_handler method when the 'MyNewDirective' is defined.
my @directives = ({name => 'MyNewDirective ', func =>
__PACKAGE__.'::MyNewDirective'});
Apache2::Module::add(__PACKAGE__, \@directives);
sub MyNewDirective {
my ($self, $parms, $arg) = @_;
# blablabla
$parms->server->push_handlers(PerlLogHandler => sub {my ($r) _ @_;
$r->server->error_log('hello world'); return Apache2::Const::OK;});
# blablabla
return;
}
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 also
be called.
Do I use the mod_perl API correctly ?
What is wrong in my code ?
Thanks.
Gaetan
------=_Part_10554_26418713.1209459029230
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hello,
I am writing a new mod_perl Apache (mod_perl2) to manage session tracking and SSO
This module defines a new Apache directive (MyNewDirective), which is usable in a <location>, <files><directory> block.
For example
<Location /a_test>
Set-Handler perl-script
MyNewDirective a_test arg1 arg2
PerlResponseHandler ResponseHandlerToTestTheNewDirective
</Location>
<Location /another_test>
Set-Handler perl-script
PerlResponseHandler ResponseHandlerToTestTheNewDirective
</Location>
When this directive is used, my module should a PerlLogHandler automatically to obtain the following configuration
<Location /a_test>
Set-Handler perl-script
MyNewDirective a_test arg1 arg2
PerlResponseHandler ResponseHandlerToTestTheNewDirective
PerlLogHandler TestPerlLogHandler
</Location>
<Location /another_test>
Set-Handler perl-script
PerlResponseHandler ResponseHandlerToTestTheNewDirective
</Location>
I tried to use the push_handler method when the 'MyNewDirective' is defined.
my @directives = ({name => 'MyNewDirective ', func => __PACKAGE__.'::MyNewDirective'});
Apache2::Module::add(__PACKAGE__, \@directives);
sub MyNewDirective {
my ($self, $parms, $arg) = @_;
# blablabla
$parms->server->push_handlers(PerlLogHandler => sub {my ($r) _ @_; $r->server->error_log('hello world'); return Apache2::Const::OK;});
# blablabla
return;
}
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 also be called.
Do I use the mod_perl API correctly ?
What is wrong in my code ?
Thanks.
Gaetan
------=_Part_10554_26418713.1209459029230--
Re: [MP2][QUESTION]Adding handlers when defining a new directive
am 29.04.2008 10:58:00 von gozer
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
iD8DBQFIFuMYyzKhB4jDpaURAoWUAKCkOo6tllhzc4FsUqAcfIv/iyYD6ACf dhQf
iGzq4SiPsixGhzHWKJpDuvg=
=KckB
-----END PGP SIGNATURE-----
--------------enigB5654438FF3F1D05AFCA0BD8--
Re: [MP2][QUESTION]Adding handlers when defining a new directive
am 29.04.2008 13:25:52 von titetluc
------=_Part_11036_11123563.1209468352913
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
It works !
Thanks a lot.
One additionnal question: does the hook ordering work (according to the
mod_perl documentation, it does not !) ?
Gaetan
2008/4/29, Philippe M. Chiasson :
>
> titetluc titetluc wrote:
>
> > Hello,
> >
> > I am writing a new mod_perl Apache (mod_perl2) to manage session
> > tracking and SSO
> > This module defines a new Apache directive (MyNewDirective), which is
> > usable in a , block.
> >
> > For example
> >
> > Set-Handler perl-script
> > MyNewDirective a_test arg1 arg2
> > PerlResponseHandler ResponseHandlerToTestTheNewDirective
> >
> >
> > Set-Handler perl-script
> > PerlResponseHandler ResponseHandlerToTestTheNewDirective
> >
> >
> >
> > When this directive is used, my module should a PerlLogHandler
> > 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
> >
> >
> > I tried to use the push_handler method when the 'MyNewDirective' is
> > defined.
> >
> > my @directives = ({name => 'MyNewDirective ', func =>
> > __PACKAGE__.'::MyNewDirective'});
> >
> > Apache2::Module::add(__PACKAGE__, \@directives);
> >
> > sub MyNewDirective {
> > my ($self, $parms, $arg) = @_;
> >
> > # blablabla
> >
> > $parms->server->push_handlers(PerlLogHandler => sub {my ($r) _ @_;
> > $r->server->error_log('hello world'); return Apache2::Const::OK;});
> >
>
>
> Right here, you are adding your handler to the current *server*
> configuration
> object, effectively enabling this handler for eery requests to that
> server/vhost
>
> # blablabla
> > return;
> > }
> >
> > 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 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) = @_;
>
> $parms->add_config(["PerlLogHandler MyLogHandler"]);
> [...]
>
> --
> Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
> http://gozer.ectoplasm.org/ m/gozer\@(apache|cpan|ectoplasm)\.org/
>
>
>
------=_Part_11036_11123563.1209468352913
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
It works !
Thanks a lot.
One additionnal question: does the hook ordering work (according to the mod_perl documentation, it does not !) ?
Gaetan
2008/4/29, Philippe M. Chiasson <>:
titetluc titetluc wrote:
Hello,
I am writing a new mod_perl Apache (mod_perl2) to manage session tracking and SSO
This module defines a new Apache directive (MyNewDirective), which is usable in a <location>, <files><directory> block.
For example
<Location /a_test>
Set-Handler perl-script
MyNewDirective a_test arg1 arg2
PerlResponseHandler ResponseHandlerToTestTheNewDirective
</Location>
<Location /another_test>
Set-Handler perl-script
PerlResponseHandler ResponseHandlerToTestTheNewDirective
</Location>
When this directive is used, my module should a PerlLogHandler automatically to obtain the following configuration
<Location /a_test>
Set-Handler perl-script
MyNewDirective a_test arg1 arg2
PerlResponseHandler ResponseHandlerToTestTheNewDirective
PerlLogHandler TestPerlLogHandler
</Location>
<Location /another_test>
Set-Handler perl-script
PerlResponseHandler ResponseHandlerToTestTheNewDirective
</Location>
I tried to use the push_handler method when the 'MyNewDirective' is defined.
my @directives = ({name => 'MyNewDirective ', func => __PACKAGE__.'::MyNewDirective'});
Apache2::Module::add(__PACKAGE__, \@directives);
sub MyNewDirective {
my ($self, $parms, $arg) = @_;
# blablabla
$parms->server->push_handlers(PerlLogHandler => sub {my ($r) _ @_; $r->server->error_log('hello world'); return Apache2::Const::OK;});
Right here, you are adding your handler to the current *server* configuration
object, effectively enabling this handler for eery requests to that server/vhost
# blablabla
return;
}
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 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) = @_;
$parms->add_config(["PerlLogHandler MyLogHandler"]);
[...]
--
Philippe M. Chiasson GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
m/gozer\@(apache|cpan|ectoplasm)\.org/
------=_Part_11036_11123563.1209468352913--