HTTP::Session::Store::OnMemory - store session data on memory


HTTP-Session documentation Contained in the HTTP-Session distribution.

Index


Code Index:

NAME

Top

HTTP::Session::Store::OnMemory - store session data on memory

SYNOPSIS

Top

    HTTP::Session->new(
        store => HTTP::Session::Store::OnMemory->new(
            data => {
                foo => 'bar',
            }
        ),
        state => ...,
        request => ...,
    );

DESCRIPTION

Top

store session data on memory for testing

CONFIGURATION

Top

data

session data.

METHODS

Top

select
update
delete
insert

for internal use only

SEE ALSO

Top

HTTP::Session


HTTP-Session documentation Contained in the HTTP-Session distribution.

package HTTP::Session::Store::OnMemory;
use strict;
use warnings;
use base qw/Class::Accessor::Fast/;

__PACKAGE__->mk_ro_accessors(qw/data/);

sub new {
    my $class = shift;
    my %args = ref($_[0]) ? %{$_[0]} : @_;
    # set default values
    $args{data} ||= {};
    bless {%args}, $class;
}

sub select {
    my ( $self, $session_id ) = @_;
    Carp::croak "missing session_id" unless $session_id;
    $self->data->{$session_id};
}

sub insert {
    my ($self, $session_id, $data) = @_;
    Carp::croak "missing session_id" unless $session_id;
    $self->data->{$session_id} = $data;
}

sub update {
    my ($self, $session_id, $data) = @_;
    Carp::croak "missing session_id" unless $session_id;
    $self->data->{$session_id} = $data;
}

sub delete {
    my ($self, $session_id) = @_;
    Carp::croak "missing session_id" unless $session_id;
    delete $self->data->{$session_id};
}

sub cleanup { Carp::croak "This storage doesn't support cleanup" }

1;
__END__