monks,

for 10 years Ive been able to find any answer I ave needed here, or on Stack Overflow. Today, neither have helped, much.

My need is to Manhandle Apache::Session::* Similar to the way MasonX::Request::WithApacheSession used to. However Im using Apache2, mod_perl2 and well, MasonX is pretty broken there. I'm still using HTML::Mason, but with my owe Session Handler. This gives me the flexability to switch Data Sources from say Postgres to MySQL (Not that I would, but you never know). Also, If I can get this code functioning well enough, I'd happily submit it to CPAN to have a working workaround for MasonX breakage. (MasonX::Request::WithApache2Session and MasonX::Request::WithApacheSession2 do not work at all). The code follows.

M42C::Web
package M42C::Web; use 5.008009; use strict; use warnings; use M42C::Web::Session; our @EXPORT = qw(); our $VERSION = '2.0.01'; sub new { my $this = shift; my $class = ref $this || $this; my $self = {}; my $r = shift; bless($self, $class); $self->{_r} = $r; return $self; }; sub session { my $self = shift; return M42C::Web::Session->new( ${$self->{_r}} )->session(); }; 1; __END__
M42C::Web::Session.pm
package M42C::Web::Session; use strict; use warnings; use CGI::Cookie; use Carp; use DBI; sub new { my $this = shift; my $class = ref $this || $this; my $self = {}; my $r = shift; bless($self, $class); my %params = @_; $self->{_r} = $r; $self->{_commit} = $params{AutoCommit}; $self->getConnection(); if($self->getCookie) { $class->getSession(); } else { $class->createSession(); }; return $class; } sub getConnection { my $self = shift; return if( $self->{_dbi} ); my $sessionClass = $self->{_r}->dir_config->get("M42CSessionCl +ass"); eval { require $sessionClass; $sessionClass->import(); 1; } or do { my $err = $@; die($err); }; my $dbh = DBI->connect( $self->{_r}->dir_config->get("M42CSessionDataSource"), $self->{_r}->dir_config->get("M42CSessionDataUsername" +), $self->{_r}->dir_config->get("M42CSessionDataPassword" +)); $self->{_dbh} = $dbh; } sub session { my $self = shift; my %cookies = CGI::Cookie->fetch(); if($cookies{'sessionid'}) { $self->{_session} = $self->getSession( $cookies{'sessi +onid'}->value() ); } else { $self->{_session} = $self->createSession(); }; return $self->{_session}; }; sub getCookie { my $self = shift; my %cookies = CGI::Cookie->fetch(); if($cookies{"sessionid"}) { return $cookies{"sessionid"}; }; return undef; } sub setCookie { my $self = shift; my $sid = shift; my $cookie = CGI::Cookie->new( '-value' => $sid, '-name' => $self->{_r}->dir_config->get("M42CCookieNam +e") || 'sessionid', '-expires' => $self->{_r}->dir_config->get("M42CCookie +Expires") || 0, '-domain' => $self->{_r}->dir_config->get("M42CCookieD +omain"), '-path' => $self->{_r}->dir_config->get("M42CCookiePat +h") || '/', '-secure' => $self->{_r}->dir_config->get("M42CCookieS +ecure") || undef, '-httponly' => $self->{_r}->dir_config->get("M42CCooki +eHttp") || undef ); $self->{_r}->headers_out->add("Set-Cookie", $cookie); } sub getSession { my $self = shift; my $cookie = $self->getCookie(); return $self->createSession() if (! $cookie); my %session; tie(%session, $self->{_r}->dir_config->get("M42CSessionClass") +, $cookie->value(), { Handle=>$self->{_dbh}, Commit=>$self->{_r}->dir_config->get("M42CSessionAutoC +ommit") }); return \%session; }; sub createSession { my $self = shift; my %session; tie(%session, $self->{_r}->dir_config->get("M42CSessionClass") +, undef, { Handle=>$self->{_dbh}, Commit=>$self->{_r}->dir_config->get("M42CSessionAutoC +ommit") }); if($self->{_r}->dir_config->get("M42CSessionUseCookie")) { $self->setCookie(\%session); }; return \%session; }; 1; __END__
And Finally the autohandler
<%init> # $m->comp('/comps/session.comp'); use Data::Dumper; use M42C::Web::Session; my $eng = M42C::Web->new(\$r); </%init> <pre> <% Dumper($eng->session) %> </pre>
The Error I receive is:
Can't locate Apache::Session::Postgres in @INC (@INC contains: /opt/m4 +2c/managed/opt/perl/5.8.9/lib/5.8.9/x86_64-linux /opt/m42c/managed/op +t/perl/5.8.9/lib/5.8.9 /opt/m42c/managed/opt/perl/5.8.9/lib/site_perl +/5.8.9/x86_64-linux /opt/m42c/managed/opt/perl/5.8.9/lib/site_perl/5. +8.9 . /opt/m42c/managed/opt/httpd) at /opt/m42c/managed/opt/perl/5.8. +9/lib/site_perl/5.8.9/M42C/Web/Session.pm line 39. ... 35: return if( $self->{_dbi} ); 36: 37: my $sessionClass = $self->{_r}->dir_config->get("M42CSessionCl +ass"); 38: eval { 39: require $sessionClass; <-- Offending line 40: $sessionClass->import(); 41: 1; 42: } or do { 43: my $err = $@;

Obviously my perl istallation is frameworked, and I have confirmed that Apache::Session::Postgres is in fact installed with

perl -MApache::Session::Postgres. Just for kicks I have tried "using" +the module as well to no effect. As well, if the require line is fail +ing, WHY is blowing through the eval. Should it not be blowing at the + die line below it? <code> [shell]$ locate Postgres.pm |grep "Apache/Session" /opt/m42c/managed/opt/perl/5.8.9/lib/site_perl/5.8.9/Apache/Session/Po +stgres.pm /opt/m42c/managed/opt/perl/5.8.9/lib/site_perl/5.8.9/Apache/Session/St +ore/Postgres.pm
Any and all guidance is much appreciated.

In reply to failure to require an installed module + eval fails to trap? by Keep

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.