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>

In reply to Passing variable from httpd.conf via Apache2::Request or Mason by monarch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.