[cgiapp] Session name, CGI::Session and CAP::Session
Todd Wade
trwww at sbcglobal.net
Fri Feb 15 16:56:06 EST 2008
Hi Lee,
Unless I'm misunderstanding I would dispense with CAP::Session and store different CGI::Session instances in CAP::Stash:
http://search.cpan.org/~kazeburo/CGI-Application-Plugin-Stash/lib/CGI/Application/Plugin/Stash.pm
use CGI::Application::Plugin::Stash;
...
$self->stash->{sessions}{'My::Subclass1'} = CGI::Session->new(...);
$self->stash->{sessions}{'My::Subclass2'} = CGI::Session->new(...);
Then maybe make my own ->session method that finds the correct session for the subclass:
sub session {
my $self = shift;
return $self->stash->{sessions}{ ref $self };
}
?
Todd W.
----- Original Message ----
From: Lee Carmichael <lecar_red at yahoo.com>
To: cgiapp at lists.openlib.org
Sent: Friday, February 15, 2008 3:00:46 PM
Subject: [cgiapp] Session name, CGI::Session and CAP::Session
Hello Everyone,
I am having a bit of an issue with how the 'name' attribute is being set on CGI::Session (CGI::Session->name). It is necessary to set the class value for 'name' before creating a session after which it is possible and useful to set it on the instance.
I have a base class that I use for multiple CGI::App sub classes, this setups the main support for CAP::Session. Since we have lots of different cgi based apps that do very different things and that shouldn't really share session data, I need a way to alter this name. The main problem is that some of these apps are mod-perl based, which is where the class value causes issues ( or has the potential for issues). I know that I could use the 'path' value but there are cases where two subclasses could use the same session but be at different paths... ( I know, I'm being a pain in the butt :)
I have found a solution but I'm not sure its the best one. In the base class, I allow each class to set the name differently for each app as a parameter. The main problem I run into is to prevent issues with it storing that for all other sub classes, I need to do something like:
... in some code that is called as a init callback....
## fetch current global name
my $old = CGI::Session->name;
## change it temporarily until new session has been created
CGI::Session->name( $self->session_name );
$self->session->name( $self->session_name );
## restore global one
CGI::Session->name( $old);
This is pretty ugly but I couldn't figure out a way around it. This give me a brief amount of time where the package value is set and I hope that it doesn't get used (or reset) by another app. Most of the apps are used by just a few (or single) users so this isn't a huge problem. But it just doesn't feel right.
>From looking at the CGI::Session code, I don't there is another way to do this. Any ideas?
One solution that I had was a new hash ref of parameters could be passed to 'new' and 'load' (of CGI::Session). Something like:
CGI::Session->new( 'driver:File', $self->query, { Directory => File::Spec->tmpdir}, { name => 'SpecialName', update_atime => 1, .... } );
I am very willing to create a patch and tests for this new constructor option, if it makes sense to everyone.
Also, I have noticed that CAP::Session uses CGI::Session->name is a few places where the instance may have changed the parameter and will require a patch to fix these issues. I am willing to produce a patch and test for these issues as well.
Thanks,
Lee
##### CGI::Application community mailing list ################
## ##
## To unsubscribe, or change your message delivery options, ##
## visit: http://lists.openlib.org/mailman/listinfo/cgiapp ##
## ##
## Web archive: http://lists.openlib.org/pipermail/cgiapp/ ##
## Wiki: http://cgiapp.erlbaum.net/ ##
## ##
################################################################
More information about the cgiapp
mailing list