Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Is CGI::Session compatible with CGI::Lite::Request ?

by afoken (Chancellor)
on Apr 26, 2015 at 19:24 UTC ( [id://1124779]=note: print w/replies, xml ) Need Help??


in reply to Is CGI::Session compatible with CGI::Lite::Request ?

didn't work

Details? The relevant part of your code, messages found in the error log?

Documentation of CGI::Session says it is compatible with any CGI.pm like modules which have param() method. But CGI::Lite::Request do have param() method.

Did you notice that load() in CGI::Session calls the cookie() method of $request (called $query in the CGI::Session source)? According to the documentation, cookie('somename') in CGI returns the cookie value (a string, a hash, or an array), but cookie('somename') in CGI::Lite::Request returns an instance of CGI::Lite::Cookie (an object).

The current version of CGI::Session on CPAN also documents that the cookie() method is called, but it does not document what it is expected to return. The code seems to expect it to behave like CGI's cookie() method, i.e. return the value of the cookie, not a cookie object.

Your options:

  • Extract the session ID from $request in your code, then pass the session ID, not $request, as second parameter to load().
  • Patch CGI::Session to call the value() method on the return value of cookie()
  • Create a helper object that implements param() and cookie() as expected by CGI::Session based on data from $request. Pass that object instead of $request to load(). (See below)

The helper class, quick and dirty and not tested:

sub new { my ($class,$lite_request)=@_; return bless [ $lite_request ],$class; } sub param { my ($self,$name)=@_; return $self->[0]->param($name); } sub cookie { my ($self,$name)=@_; return $self->[0]->cookie($name)->value(); }

Alexander

--
Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)

Replies are listed 'Best First'.
Re^2: Is CGI::Session compatible with CGI::Lite::Request ?
by Anonymous Monk on Apr 27, 2015 at 02:17 UTC

    Thanks a lot for the detailed reply
    I simply changed the parameters as you said and worked fine

    $session = CGI::Session->load(undef, $q->cookie('sid')->value(), {Dire +ctory => "$LOCAL_PATH/admin/session"});

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1124779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-04-25 07:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found