nodebunny has asked for the wisdom of the Perl Monks concerning the following question:
package My::Role::PersistsData; use Moose::Role; use namespace::autoclean; has '_cgi' => ( is => 'rw', isa => 'Maybe[CGI]', builder => '_build_cgi' ); has '_sss' => ( is => 'rw', isa => 'Maybe[CGI::Session]', builder => '_build_sss' );
package My::Session; use Moose; use namespace::autoclean; with 'My::Role::PersistsData'; use CGI; use CGI::Session ('-ip_match'); use CGI::Carp qw/fatalsToBrowser warningsToBrowser/; sub start{ my($self) = @_; my $cgi = $self->cgi(); $self->log("Session Started!"); } sub cgi{ my($self) = @_; $self->_cgi = $self->_build_cgi() unless $self->_cgi; return ($self->_cgi); } sub _build_cgi{ my($self) = @_; my $cgi = CGI->new(); if(!$cgi){ #print "mising cgi"; } return ( $cgi ); } sub _build_sss{ my($self) = @_; my $cgi = $self->cgi(); my $sid = $cgi->cookie("CGISESSID") || $cgi->param('CGIS +ESSID') || undef; $self->log("Session ID Initial is: ".($sid?$sid:"undef") +); my $sss = CGI::Session->new(undef, $cgi, {Directory=>'t +mp'}) or die CGI::Session->errstr; my $cookie = $cgi->cookie(CGISESSID => $sss->id() ); $self->log("Resulting Session ID is: ".$sid." cookie is: + ".$cookie); print $cgi->header( -cookie=>$cookie ); return ( $sss ); }
use Data::Dumper; $Data::Dumper::Sortkeys = 1; use CGI; use CGI::Carp qw(fatalsToBrowser); use My::Session; $| = 1; $, = " "; $\ = "\n <br />"; my $sss = My::Session->new(); $sss->start(); print "<title>Test Sessions</title>"; print "TEST"; print "<pre>",Dumper($sss),"</pre>";
$sss = new CGI::Session("driver:File", $sid, {Directory=>'/tmp'})
new(): failed: load(): couldn't thaw() data using CGI::Session::Se +rialize::default:thaw(): couldn't thaw. syntax error at (eval 253) li +ne 2, near "/>"
Low and behold removing Data::Dumper and all my html output fixed this -- I think -- but that doesnt necessarily solve my problem or help me understand why this is breaking.... $self->{_DATA} = $self->{_OBJECTS}->{serializer}->thaw($raw_da +ta); unless ( defined $self->{_DATA} ) { #die $raw_data . "\n"; return $self->set_error( "load(): couldn't thaw() data usi +ng $self->{_OBJECTS}->{serializer} :" . $self->{_OBJECTS}->{serializer}->e +rrstr ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CGI::Sessions fails when I use Data::Dumper
by moritz (Cardinal) on Sep 20, 2011 at 14:36 UTC | |
by nodebunny (Novice) on Sep 20, 2011 at 15:32 UTC | |
|
Re: CGI::Sessions fails when I use Data::Dumper
by Anonymous Monk on Sep 20, 2011 at 14:38 UTC | |
by nodebunny (Novice) on Sep 20, 2011 at 15:31 UTC | |
by Anonymous Monk on Sep 20, 2011 at 16:01 UTC |