Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

[MP2] Problem when defining new directives in a container

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


titetluc at gmail

Oct 7, 2008, 1:49 AM

Post #1 of 2 (384 views)
Permalink
[MP2] Problem when defining new directives in a container

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


titetluc at gmail

Oct 14, 2008, 7:52 AM

Post #2 of 2 (321 views)
Permalink
Re: [MP2] Problem when defining new directives in a container [In reply to]

Any ideas ?

Gaetan

2008/10/7 titetluc titetluc <titetluc[at]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
>
>

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact lists@gossamer-threads.com
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.