[prev in list] [next in list] [prev in thread] [next in thread] 

List:       apache-modperl
Subject:    Re: [MP2][QUESTION]Adding handlers when defining a new directive
From:       "titetluc titetluc" <titetluc () gmail ! com>
Date:       2008-04-29 11:25:52
Message-ID: 9b0e769d0804290425r56467f36r60bdd0d5683cd4fc () mail ! gmail ! com
[Download RAW message or body]

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 <gozer@ectoplasm.org>:
>
> 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
> http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/
>
>
>

[Attachment #3 (text/html)]

It works !<br>Thanks a lot.<br><br>One additionnal question: does the hook ordering \
work (according to the mod_perl documentation, it does not !) \
?<br><br>Gaetan<br><br><div><span class="gmail_quote">2008/4/29, Philippe M. Chiasson \
&lt;<a href="mailto:gozer@ectoplasm.org">gozer@ectoplasm.org</a>&gt;:</span><blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt \
0pt 0.8ex; padding-left: 1ex;"> <div><span class="e" \
id="q_11999680e4401efa_0">titetluc titetluc wrote:<br> <blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); padding-left: \
1ex;"> Hello,<br>
<br>
I am writing a new mod_perl Apache (mod_perl2) to manage session tracking and SSO<br>
This module defines a new Apache directive (MyNewDirective), which is usable in a \
&lt;location&gt;, &lt;files&gt;&lt;directory&gt; block.<br> <br>
For example<br>
&lt;Location /a_test&gt;<br>
 &nbsp; &nbsp;Set-Handler perl-script<br>
 &nbsp; &nbsp;MyNewDirective a_test arg1 arg2<br>
 &nbsp; &nbsp;PerlResponseHandler ResponseHandlerToTestTheNewDirective<br>
&lt;/Location&gt;<br>
&lt;Location /another_test&gt;<br>
 &nbsp; &nbsp;Set-Handler perl-script<br>
 &nbsp; &nbsp;PerlResponseHandler ResponseHandlerToTestTheNewDirective<br>
&lt;/Location&gt;<br>
<br>
<br>
When this directive is used, my module should a PerlLogHandler automatically to \
obtain the following configuration<br> &lt;Location /a_test&gt;<br>
 &nbsp; &nbsp;Set-Handler perl-script<br>
 &nbsp; &nbsp;MyNewDirective a_test arg1 arg2<br>
 &nbsp; &nbsp;PerlResponseHandler ResponseHandlerToTestTheNewDirective<br>
 &nbsp; &nbsp;PerlLogHandler TestPerlLogHandler<br>
&lt;/Location&gt;<br>
&lt;Location /another_test&gt;<br>
 &nbsp; &nbsp;Set-Handler perl-script<br>
 &nbsp; &nbsp;PerlResponseHandler ResponseHandlerToTestTheNewDirective<br>
&lt;/Location&gt;<br>
<br>
I tried to use the push_handler method when the &#39;MyNewDirective&#39; is \
defined.<br> <br>
my @directives = ({name =&gt; &#39;MyNewDirective &#39;, func =&gt; \
__PACKAGE__.&#39;::MyNewDirective&#39;});<br> <br>
Apache2::Module::add(__PACKAGE__, \@directives);<br>
<br>
sub MyNewDirective {<br>
 &nbsp; &nbsp;my ($self, $parms, $arg) = @_;<br>
<br>
 &nbsp; &nbsp;# blablabla<br>
<br>
 &nbsp; &nbsp;$parms-&gt;server-&gt;push_handlers(PerlLogHandler =&gt; sub {my ($r) _ \
@_; $r-&gt;server-&gt;error_log(&#39;hello world&#39;); return \
Apache2::Const::OK;});<br> </blockquote>
<br>
<br></span></div>
Right here, you are adding your handler to the current *server* configuration<br>
object, effectively enabling this handler for eery requests to that server/vhost<span \
class="q"><br> <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
padding-left: 1ex;">  &nbsp; &nbsp;# blablabla<br>
 &nbsp; &nbsp;return;<br>
}<br>
<br>
This code works ... but for any blocks.<br>
For example, if I access the URI &#39;/a_test&#39;, the PerlLogHandler will be called \
BUT if I access the URI &#39;/another_test&#39;, the PerlLogHandler will also be \
called.<br> </blockquote>
<br></span>
See above.<span class="q"><br>
<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
padding-left: 1ex;"> Do I use the mod_perl API correctly ?<br>
</blockquote>
<br></span>
Correctly, yes. Unfortunately, it&#39;s not what you are trying to do.<span \
class="q"><br> <br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); \
padding-left: 1ex;"> What is wrong in my code ?<br>
</blockquote>
<br></span>
If you want to push your loghandler only for requests for your configured<br>
module, I would just delay the loghandler registration until runtime and<br>
do it in your content handler with<br>
<br>
$r-&gt;push_handlerrs(...)<br>
<br>
Or you can do it in your command handler, but like so<br>
<br>
sub MyLogHandler {<br>
[...]<br>
}<br>
<br>
sub MyNewDirective {<br>
 &nbsp;my ($self, $param, $arg) = @_;<br>
<br>
 &nbsp;$parms-&gt;add_config([&quot;PerlLogHandler MyLogHandler&quot;]);<br>
 &nbsp;[...]<br><span class="sg">
<br>
-- <br>
Philippe M. Chiasson &nbsp; &nbsp; GPG: F9BFE0C2480E7680 1AE53631CB32A107 \
88C3A5A5<br> <a href="http://gozer.ectoplasm.org/" target="_blank" onclick="return \
top.js.OpenExtLink(window,event,this)">http://gozer.ectoplasm.org/</a> &nbsp; &nbsp; \
&nbsp; m/gozer\@(apache|cpan|ectoplasm)\.org/<br> <br>
</span><br clear="all"></blockquote></div><br>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic