package HTML::Mason; use HTML::Mason; # brings in subpackages: Parser, Interp, etc. use strict; $Apache::Session::DBIStore::DataSource = 'dbi:Pg:dbname=DATABASE'; $Apache::Session::DBIStore::UserName = 'USER'; $Apache::Session::SysVSemaphoreLocker::nsems = 16; use HTML::Mason::Commands; # brings in subpackages: Parser, Interp, etc. use Apache::Cookie; use Apache::Session::DBI; my $parser = new HTML::Mason::Parser; my $interp = new HTML::Mason::Interp (parser=>$parser, comp_root=>'/home', out_mode=>'stream', data_dir=>'/var/mason/data'); my $ah = new HTML::Mason::ApacheHandler (interp=>$interp); chown ( [getpwnam('nobody')]->[2], [getgrnam('nobody')]->[2], $interp->files_written ); # chown nobody sub handler { my ($r) = @_; # don't serve up non-text files. return -1 if $r->content_type && substr(lc $r->content_type, 0, 5) ne "text/"; my %cookie = Apache::Cookie->fetch; eval { tie %session, 'Apache::Session::DBI', (defined $cookie{SID} ? $cookie{SID}->value : undef); if(not defined $cookie{SID}) { $cookie{SID} = Apache::Cookie->new($r, -name => "SID", -value => $session{_session_id}, -path => "/"); $cookie{SID}->bake; } }; if(not defined $session{_session_id} || $@) { warn $@; tie %session, 'Apache::Session::DBI', undef; $cookie{SID}->value($session{_session_id}); $cookie{SID}->bake; } $session{lastaccess} = time; my $status = $ah->handle_request($r); untie %session; return $status; } 1;