Loading ...
Sorry, an error occurred while loading the content.

[mp2] custom configuration not initialised via SERVER_CREATE

Expand Messages
  • Richard Leopold
    MOIn ! The documentation explains how to do Apache Server Configuration Customization in Perl and the SERVER_CREATE/DIR_CREATE mechanism to set defaults. But
    Message 1 of 1 , Aug 1, 2005
    • 0 Attachment
      MOIn !

      The documentation explains how to do "Apache Server Configuration
      Customization in Perl" and the SERVER_CREATE/DIR_CREATE mechanism
      to set defaults.

      But it only does work, if a customised directive would be be found
      in the configuration. Just calling

      Apache2::Module::add(__PACKAGE__, \@directives);

      is not enough to create a initial configuration via the given
      *_CREATE -method of __PACKAGE__

      below I'll give you an example test.

      Any suggestions or hints to get an initial configuration while
      loading the __PACKAGE__ ? - or is it a bug ?

      Regards - Richard


      ## my http.conf has the lines

      PerlLoadModule kit::BaseConfig_XX

      # remark/unremark the following line to show the effect ...
      MOI_TestDefaultXX x

      # lynx this location
      <Location "/kit/XX">
      SetHandler modperl
      PerlResponseHandler kit::BaseConfig_XX
      </Location>


      ## Here comes the test-module

      package kit::BaseConfig_XX;

      use 5.008;
      use strict;
      use warnings FATAL => 'all';

      use Apache2::Module ();
      use Apache2::CmdParms ();
      use Apache2::ServerUtil ();

      use Apache2::RequestRec ();
      use Apache2::RequestIO ();
      use Apache2::RequestUtil ();

      use Apache2::Const -compile => qw(
      OK
      );

      # ================================================
      our $SRV_CFG = { Test_default => '_XX Hello server' };
      our $DIR_CFG = { Test_default => '_XX Hello directory' };

      my @directives = (
      {
      name => 'MOI_TestDefaultXX',
      },
      );


      sub MOI_TestDefaultXX {
      my($self, $parms, $arg) = @_;
      my $key = 'TestDefaultXX';

      $self->{_config}->{$key} = $arg;
      unless ($parms->path) {
      my $srv_cfg = Apache2::Module::get_config($self, $parms->server);
      $srv_cfg->{_config}->{$key} = $arg;
      }

      return $self;
      }

      Apache2::Module::add(__PACKAGE__, \@directives);
      # ================================================

      sub SERVER_CREATE {
      my($class, $parms) = @_;

      my $default = eval '$' . $class . '::SRV_CFG' || {};

      my $self = {
      name => $class,
      _config => $default,
      };

      return bless $self, $class;
      }

      sub DIR_CREATE {
      my($class, $parms) = @_;

      my $default = eval '$' . $class . '::DIR_CFG' || {};

      my $self = {
      name => $class,
      _config => $default,
      };

      return bless $self, $class;
      }


      use Data::Dumper;

      sub handler ($) {
      my $r = shift;

      my $srv_cfg = Apache2::Module::get_config(__PACKAGE__, $r->server());
      my $dir_cfg = Apache2::Module::get_config(__PACKAGE__, $r->server(), $r->per_dir_config());

      $r->content_type('text/plain');
      $r->print( Dumper( $srv_cfg, $dir_cfg) );

      return Apache2::Const::OK;
      }

      1;
    Your message has been successfully submitted and would be delivered to recipients shortly.