Dancer::Session::Simple - in-memory session backend for Dancer


Dancer documentation Contained in the Dancer distribution.

Index


Code Index:

NAME

Top

Dancer::Session::Simple - in-memory session backend for Dancer

DESCRIPTION

Top

This module implements a very simple session backend, holding all session data in memory. This means that sessions are volatile, and no longer exist when the process exits. This module is likely to be most useful for testing purposes.

CONFIGURATION

Top

The setting session should be set to Simple in order to use this session engine in a Dancer application.

AUTHOR

Top

This module has been written by David Precious, see the AUTHORS file for details.

SEE ALSO

Top

See Dancer::Session for details about session usage in route handlers.

COPYRIGHT

Top

LICENSE

Top

This module is free software and is released under the same terms as Perl itself.


Dancer documentation Contained in the Dancer distribution.

package Dancer::Session::Simple;

use strict;
use warnings;
use base 'Dancer::Session::Abstract';

use Dancer::ModuleLoader;
use Dancer::Config 'setting';
use Dancer::FileUtils 'path';


my %sessions;

# create a new session and return the newborn object
# representing that session
sub create {
    my ($class) = @_;

    my $self = Dancer::Session::Simple->new;
    $self->flush;
    return $self;
}

# Return the session object corresponding to the given id
sub retrieve {
    my ($class, $id) = @_;

    return $sessions{$id};
}


sub destroy {
    my ($self) = @_;
    undef $sessions{$self->id};
}

sub flush {
    my $self = shift;
    $sessions{$self->id} = $self;
    return $self;
}

1;
__END__