Can anyone help with this problem? I read about Apache::Session in this months Linux journal and I'd like to use it to keep state in my HTML::Mason app. The trouble is I can't get it to work! (I'm, using 1.51) This is my Apache (1.3.9 with modperl 1.21 on Debian GNU/Linux) configuration
<Directory /www/htdocs/myapp> Options Indexes FollowSymLinks AllowOverride None PerlRequire "/www/HTML-Mason/myapp.pl" SetHandler perl-script PerlHandler HTML::Mason </Directory>
This is myapp.pl:
package HTML::Mason; use HTML::Mason; use strict; use Apache::DBI; my $dbsource = "dbi:mysql:myapp"; my $dbuser = 'myapp'; my $dbpass = 'mypass'; # Import some modules for use in components { package HTML::Mason::Commands; use vars qw(%session); use CGI::Cookie; use CGI::Carp; use Apache::DBI; use Apache::Session::MySQL; use Mail::Sendmail; } # Create a new Mason parser my $parser = new HTML::Mason::Parser; # Create a new Mason interpreter my $interp = new HTML::Mason::Interp (parser => $parser, comp_root => '/www/htdocs/carboncontacts/ +', data_dir => '/www/HTML-Mason/'); # Create a new Mason ApacheHandler my $ah = new HTML::Mason::ApacheHandler (interp => $interp); # Make sure that things are done as nobody, and not root! chown ( [getpwnam('www')]->[2], [getgrnam('www')]->[2], $interp->files_written ); # ----------------------------------------------------------- # Create our content handler. sub handler { # Get the Apache request object my $r = shift; # Only handle text return -1 if defined($r->content_type) && $r->content_type !~ m|^text/|io; # Get the incoming cookies my %cookies = parse CGI::Cookie($r->header_in('Cookie')); # Try to re-establish an existing session eval { tie %HTML::Mason::Commands::session, 'Apache::Session::MySQL', ($cookies{'AF_SID'} ? $cookies{'AF_SID'}->value() : undef), { DataSource => $dbsource, UserName => $dbuser, Password => $dbpass }; }; # If we could not re-establish an existing # session, create a new session. if ( $@ ) { if ( $@ =~ m#^Object does not exist in the data store# ) { tie %HTML::Mason::Commands::session, 'Apache::Session::MyS +QL', undef, { DataSource => $dbsource, UserName => $dbuser, Password => $dbpass }; undef $cookies{'AF_SID'}; } } if ( !$cookies{'AF_SID'} ) { my $cookie = new CGI::Cookie(-name => 'AF_SID', -value => $HTML::Mason::Commands::session{_session_i +d}, -path => '/myapp/'); $r->header_out('Set-Cookie', => $cookie); } my $status = $ah->handle_request($r); untie %HTML::Mason::Commands::session; return $status; } 1;
In my database (MySQL 3.22.32) I have a table defined like this:
CREATE TABLE sessions ( id CHAR(32) NOT NULL PRIMARY KEY, a_session TEXT );
Now according to what I have read, this should be enough to give me a hash called %session to which I can read and write which would translate into setting and reading cookies. But like I said it doesn't work :(

Other perl modules in use:

DBI 1.13
DBD::MySQL 1.2202
Apache::DBI 0.86
Mail::Sendmail 0.77

Any responses gratefully accepted

-- Jaldhar


In reply to How to use Apache::Session? by jaldhar

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.