I see space for a plugin here. Unless I'm overlooking something, you need a way to temporarily set a configuration option and have it removed at the end of the request:
# ... in your code
volatile session_expires => '...'; # whatever the business logic dictates
# ... in the plugin, proof of concept
my %original_for;
register volatile => sub {
my ($name, $value) = @_;
my $config = config();
if (! exists $original_for{$name}) {
$original_for{$name} = exists($config->{$name}) ? [ $config->{$name} ] : undef;
}
set $name, $value;
};
after sub { # restore original values
my $config = config();
while (my ($name, $value) = each %original_for) {
delete $config->{$name};
$config->{$name} = $value->[0] if ref $value;
}
%original_for = ();
};
Of course the restoration mechanism above somewhat breaks encapsulation for config/set/setting. Could we possibly use only Dancer::Config::setting? The tricky part is handling the "no previous value for this configuration" case.
And of course this does not play well with threads (but I wonder if Dancer plays nice with them at all).
Cheers,
Flavio.
Hmm, I dug into the actual code and found this in Dancer::Session::Abstract:
if (my $expires = setting('session_expires')) {
$cookie{expires} =
Dancer::Cookie::_epoch_to_gmtstring(time + $expires);
}
It appears I can have a global timeout option in the settings. This
is useful although I think I need something a bit more flexible. I
need to be able to choose a session time out based on user input. For
example, if they check "remember me" I want the session to expire in 2
weeks, otherwise just use a session cookie.
The write_session_id method is specifically mentioned as something I
should not attempt to overload. Does anyone have any ideas about how
I can have a dynamic session timeout?
Thanks again,
Brian
On Mon, Mar 14, 2011 at 4:27 PM, Brian E. Lozier <brian@massassi.com> wrote:
> When I use Dancer::Session::YAML to create a session, the session
> cookie is set to expire when the browser closes. Is there a way for
> me to set an expire time for the session cookie? I looked in
> Dancer::Session, Dancer::Session::YAML, Dancer::Cookbook, and
> Dancer::Session::Abstract but didn't see anything (maybe I missed it).
>
> Thanks,
> Brian
>
_______________________________________________
Dancer-users mailing list
Dancer-users@perldancer.org
http://www.backup-manager.org/cgi-bin/listinfo/dancer-users