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

List:       apache-modperl
Subject:    Re: [MP2] Problem when defining new directives in a container
From:       "titetluc titetluc" <titetluc () gmail ! com>
Date:       2008-10-14 14:52:57
Message-ID: 9b0e769d0810140752l3e4d78cew89386d0e8d7670e9 () mail ! gmail ! com
[Download RAW message or body]

Any ideas ?

Gaetan

2008/10/7 titetluc titetluc <titetluc@gmail.com>

> Hello all,
>
> I am developing a new module which defines 2 new directives (TestDirective1
> and TestDirective2). These directives are usable in a container (Location,
> Directory, ...).
> The following code defines the directives :
>
> =====BEGIN CODE=====================================
> package TestDirective;
> use warnings;
> use strict;
> use Carp;
>
> use Apache2::Const -compile => qw(RAW_ARGS);
> use Apache2::CmdParms ();
> use Apache2::Module ();
> use Apache2::Directive ();
> use Apache2::Const qw(:common);
>
> my @directives = (
>           {
>               name         => 'TestDirective1',
>               func         => __PACKAGE__ . '::TestDirective1',
>               args_how     => Apache2::Const::RAW_ARGS,
>           },
>           {
>               name         => 'TestDirective2',
>               func         => __PACKAGE__ . '::TestDirective2',
>               args_how     => Apache2::Const::RAW_ARGS,
>           },
>           );
>
> Apache2::Module::add(__PACKAGE__, \@directives);
>
> sub TestDirective1 {
>     my ($self, $parms, $arg) = @_;
>     print STDERR "hello\n";
>     $self->{TestDirective1} = 'hello';
>     return;
> }
>
> sub TestDirective2 {
>     my ($self, $parms, $arg) = @_;
>     my $td1 = Apache2::Module::get_config(__PACKAGE__, $parms->server);
>
>     if (defined $td1){
>         print STDERR "world\n";
>     }
>     $self->{TestDirective2} = 'world';
>     return;
> }
>
>
> sub response {
>     my ($self,$r) = @_;
>     print 'hello world';
>     return OK;
> }
>
> 1;
>
> =====END CODE======================================
>
>
> When using the new directives with the following configuration file
>
> =====BEGIN CONFIG======================================
> PerlLoadModule TestDirective;
>
> <Location /test>
>     SetHandler perl-script
>     TestDirective1
>     TestDirective2
>
>     PerlResponseHandler TestDirectives->response
> </Location>
> =====END CONFIG======================================
>
>  STDERR output, when starting Apache, is
> "hello
> world"
> =>  correct
>
>
> But when using the new directives with the following configuration file
>
> =====BEGIN CONFIG======================================
> PerlLoadModule TestDirective;
>
> <Location /test>
>     SetHandler perl-script
>     TestDirective2
>
>     PerlResponseHandler TestDirectives->response
> </Location>
> =====END CONFIG======================================
>
> STDERR output, when starting Apache, is
> "world"
> =>  incorrect
>
> STDERR is not empty (it should)
> What is wrong in the TestDirective::TestDirective2 function ?
> Which test do I have to apply ('defined $td1' is not the correct test !!!)
> ?
>
> Thanks
>
> Gaetan
>
>

[Attachment #3 (text/html)]

<div dir="ltr">Any ideas ?<br><br>Gaetan<br><br><div class="gmail_quote">2008/10/7 \
titetluc titetluc <span dir="ltr">&lt;<a \
href="mailto:titetluc@gmail.com">titetluc@gmail.com</a>&gt;</span><br><blockquote \
class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt \
0pt 0.8ex; padding-left: 1ex;"> <div dir="ltr">Hello all,<br><br>I am developing a \
new module which defines 2 new directives (TestDirective1 and TestDirective2). These \
directives are usable in a container (Location, Directory, ...).<br>The following \
code defines the directives :<br>

<br>=====BEGIN CODE=====================================<br>package \
TestDirective;<br>use warnings;<br>use strict;<br>use Carp;<br><br>use Apache2::Const \
-compile =&gt; qw(RAW_ARGS);<br>use Apache2::CmdParms ();<br>use Apache2::Module \
();<br>

use Apache2::Directive ();<br>use Apache2::Const qw(:common);<br><br>my @directives = \
(<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; \
&#39;TestDirective1&#39;,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; func&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
=&gt; __PACKAGE__ . &#39;::TestDirective1&#39;,<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
args_how&nbsp;&nbsp;&nbsp;&nbsp; =&gt; \
Apache2::Const::RAW_ARGS,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; \
},<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; {<br>&nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
name&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =&gt; \
&#39;TestDirective2&#39;,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; func&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
=&gt; __PACKAGE__ . &#39;::TestDirective2&#39;,<br>

&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
args_how&nbsp;&nbsp;&nbsp;&nbsp; =&gt; \
Apache2::Const::RAW_ARGS,<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; \
},<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; \
);<br><br>Apache2::Module::add(__PACKAGE__, \@directives);<br><br>sub TestDirective1 \
{<br>&nbsp;&nbsp;&nbsp; my ($self, $parms, $arg) = @_;<br>&nbsp;&nbsp;&nbsp; print \
STDERR &quot;hello\n&quot;;<br>

&nbsp;&nbsp;&nbsp; $self-&gt;{TestDirective1} = \
&#39;hello&#39;;<br>&nbsp;&nbsp;&nbsp; return;<br>}<br><br>sub TestDirective2 \
{<br>&nbsp;&nbsp;&nbsp; my ($self, $parms, $arg) = @_;<br>&nbsp;&nbsp;&nbsp; my $td1 \
= Apache2::Module::get_config(__PACKAGE__, $parms-&gt;server);<br><br>

&nbsp;&nbsp;&nbsp; if (defined $td1){<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; \
print STDERR &quot;world\n&quot;;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; \
$self-&gt;{TestDirective2} = &#39;world&#39;;<br>&nbsp;&nbsp;&nbsp; \
return;<br>}<br><br><br>sub response {<br>&nbsp;&nbsp;&nbsp; my ($self,$r) = \
@_;<br>&nbsp;&nbsp;&nbsp; print &#39;hello world&#39;;<br>

&nbsp;&nbsp;&nbsp; return OK;<br>}<br><br>1;<br><br>=====END \
CODE======================================<br> <br><br>When using the new directives \
with the following configuration file<br><br>=====BEGIN \
CONFIG======================================<br>

PerlLoadModule TestDirective;<br><br>&lt;Location /test&gt;<br>&nbsp;&nbsp;&nbsp; \
SetHandler perl-script<br>&nbsp;&nbsp;&nbsp; TestDirective1<br>&nbsp;&nbsp;&nbsp; \
TestDirective2<br><br>&nbsp;&nbsp;&nbsp; PerlResponseHandler \
TestDirectives-&gt;response<br>&lt;/Location&gt;<br>=====END \
CONFIG======================================<br>



<br>&nbsp;STDERR output, when starting Apache, is \
<br>&quot;hello<br>world&quot;<br>=&gt;&nbsp; correct<br><br><br>But when using the \
new directives with the following configuration file<br> <br>
=====BEGIN CONFIG======================================<br>


PerlLoadModule TestDirective;<br>
<br>
&lt;Location /test&gt;<br>
&nbsp;&nbsp;&nbsp; SetHandler perl-script<br>
&nbsp;&nbsp;&nbsp; TestDirective2<br>
<br>
&nbsp;&nbsp;&nbsp; PerlResponseHandler TestDirectives-&gt;response<br>
&lt;/Location&gt;<br>
=====END CONFIG======================================<br>


<br>
STDERR output, when starting Apache, is <br>
&quot;world&quot;<br>
=&gt;&nbsp; incorrect<br><br>STDERR is not empty (it should)<br>What is wrong in the \
TestDirective::TestDirective2 function ?<br>Which test do I have to apply \
(&#39;defined $td1&#39; is not the correct test !!!) ?<br><br>Thanks<br>

<br>Gaetan<br><br></div>
</blockquote></div><br></div>



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

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