[cgiapp] encoding pragma and CGI::Session

Todd Ross tar.lists at yahoo.com
Fri Sep 3 12:08:32 EDT 2010


Hello,

While trying to add CGI::Application::Plugin::Session to an existing 
application, I came across a potential conflict between the encoding pragma and 
CGI::Session that I'm looking for feedback on.

This isn't a CGI::Application issue but I figured since there are plugins to 
incorporate CGI::Session with CGI::Application that it would be okay to post 
this here.  That, and Mark maintains both modules.  :)

I've tried to distill this to the barest elements (CGI::Application and 
CAP::Session aren't involved):

[me at unixbox1:~]> cat testutf8.pl
#!/usr/bin/perl

use strict;
use warnings;

# http://perldoc.perl.org/5.8.8/encoding.html
#use encoding 'utf8';

use CGI;
use CGI::Session;

my $query = new CGI();

my $session = new CGI::Session(undef, $query, undef);
if (!$session) {
        die "Error instantiating CGI::Session: $@\n";
}

my $session_id = $session->id();
print "session id: $session_id\n";

if (!$ENV{HTTP_COOKIE}) {
        # new session
        print "adding { name => 'value' } to session\n";

        $session->param(
                name => 'value'
        );
} else {
        # existing session
        print 'retrieving name from session: ' . $session->param('name') . "\n";
}

[me at unixbox1:~]> ./testutf8.pl
session id: 5db231f9102f9067bdb384df7227c096
adding { name => 'value' } to session

[me at unixbox1:~]> cat /tmp/cgisess_5db231f9102f9067bdb384df7227c096
$D = {'_SESSION_ID' => '5db231f9102f9067bdb384df7227c096','_SESSION_ATIME' => 
1283525840,'name' => 'value','_SESSION_REMOTE_ADDR' => '','_SESSION_CTIME' => 
1283525840};;$D

[me at unixbox1:~]> env HTTP_COOKIE="CGISESSID=5db231f9102f9067bdb384df7227c096" 
./testutf8.pl
session id: 5db231f9102f9067bdb384df7227c096
retrieving name from session: value

... works fine.  When I uncomment the "use encoding 'utf8';" statement, things 
go awry:

[me at unixbox1:~]> ./testutf8.pl
session id: dc43ad7276188fb45b386135a4b3d5e1
adding { name => 'value' } to session

[me at unixbox1:~]> cat /tmp/cgisess_dc43ad7276188fb45b386135a4b3d5e1
$D = {'_SESSION_ID' => 'dc43ad7276188fb45b386135a4b3d5e1','_SESSION_ATIME' => 
1283529349,'name' => 'value','_SESSION_REMOTE_ADDR' => '','_SESSION_CTIME' => 
1283529349};;$D

[me at unixbox1:~]> env HTTP_COOKIE="CGISESSID=dc43ad7276188fb45b386135a4b3d5e1" 
./testutf8
Error instantiating CGI::Session:       (in cleanup) Can't locate object method 
"renewed" via package "Encode::utf8" (perhaps you forgot to load 
"Encode::utf8"?) at (eval 11) line 1.

...  Is this a bug in CGI::Session?

[me at unixbox1:~]> perl -MCGI -MCGI::Session -e 'print "CGI: 
$CGI::VERSION\nCGI::Session: $CGI::Session::VERSION\n"' 

CGI: 3.15
CGI::Session: 4.20

[me at unixbox1:~]> perl -v | head -2 | tail -1
This is perl, v5.8.8 built for sun4-solaris

Todd


      


More information about the cgiapp mailing list