[MP2] Problem when defining new directives in a container - modperl

This is a discussion on [MP2] Problem when defining new directives in a container - modperl ; 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 ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: [MP2] Problem when defining new directives in a container

  1. [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:irective ();
    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;


    SetHandler perl-script
    TestDirective1
    TestDirective2

    PerlResponseHandler TestDirectives->response

    =====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;


    SetHandler perl-script
    TestDirective2

    PerlResponseHandler TestDirectives->response

    =====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


  2. Re: [MP2] Problem when defining new directives in a container

    Any ideas ?

    Gaetan

    2008/10/7 titetluc titetluc

    > 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:irective ();
    > 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;
    >
    >
    > SetHandler perl-script
    > TestDirective1
    > TestDirective2
    >
    > PerlResponseHandler TestDirectives->response
    >

    > =====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;
    >
    >
    > SetHandler perl-script
    > TestDirective2
    >
    > PerlResponseHandler TestDirectives->response
    >

    > =====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
    >
    >



+ Reply to Thread