monarch has asked for the wisdom of the Perl Monks concerning the following question:

I'm using mod_perl 2 and HTML::Mason. This isn't necessarily a Mason question, though, as the problem could be solved through either Mason or Apache2::Request.

I want to be able to pass a variable from my httpd.conf into the called mod_perl pages. e.g. set a variable called "sitename" that I can access by calling something like $r->{sitename} or $r->param("sitename").

It is important that the variable is associated with the handler because I am using many virtual web sites (each with their own handler) with Apache on Linux.

Here is the configuration I am presently using for my handler..

<Perl> { package MyMasonHandler_mywebsite; use vars qw(@ISA); push( @ISA, 'HTML::Mason::ApacheHandler' ); my $ah = HTML::Mason::ApacheHandler->new( comp_root => "/home/mywebsite/html", data_dir => "/var/cache/mason/mywebsite", args_method => 'mod_perl', ); sub handler { my ( $r ) = @_; # maybe set something here? # e.g. $r->param("sitename") = "mywebsite"; $ah->handle_request( $r ); } } </Perl> <VirtualHost *:80> ServerName mywebsite DocumentRoot /home/mywebsite/html <Files *.mhtml> SetHandler perl-script PerlHandler MyMasonHandler_mywebsite </Files> </VirtualHost>

Replies are listed 'Best First'.
Re: Passing variable from httpd.conf via Apache2::Request or Mason
by perrin (Chancellor) on Apr 26, 2006 at 03:55 UTC
      Thankyou for this; on closer inspection I can see that PerlSetVar can be used locally to a <Directory>, <Files>, or even a <VirtualHost> directive. Perfect, it gives me the localisation I need! I can retrieve the value using $r->dir_config('somekey').