Plack-Middleware-Session

 view release on metacpan or  search on metacpan

lib/Plack/Session/Store.pm  view on Meta::CPAN

package Plack::Session::Store;
use strict;
use warnings;

our $VERSION   = '0.36';
our $AUTHORITY = 'cpan:STEVAN';

use Plack::Util::Accessor qw[ _stash ];

sub new {
    my ($class, %params) = @_;
    $params{'_stash'} ||= +{};
    bless { %params } => $class;
}

sub fetch {
    my ($self, $session_id) = @_;
    $self->_stash->{ $session_id };
}

sub store {
    my ($self, $session_id, $session) = @_;
    $self->_stash->{ $session_id } = $session;
}

sub remove {
    my ($self, $session_id) = @_;
    delete $self->_stash->{ $session_id }
}

1;

__END__

=pod

=head1 NAME

Plack::Session::Store - Basic in-memory session store

=head1 SYNOPSIS

  use Plack::Builder;
  use Plack::Middleware::Session;
  use Plack::Session::Store;

  my $app = sub {
      return [ 200, [ 'Content-Type' => 'text/plain' ], [ 'Hello Foo' ] ];
  };

  builder {
      enable 'Session'; # this is the default store
      $app;
  };

=head1 DESCRIPTION

This is a very basic in-memory session data store. It is volatile
storage and not recommended for multiprocessing environments. However
it is very useful for development and testing.

This should be considered the store "base" class (although
subclassing is not a requirement) and defines the spec for
all B<Plack::Session::Store::*> modules. You will only
need to override a couple methods if you do subclass. See
the other B<Plack::Session::Store::*> for examples of this.

=head1 METHODS

=over 4

=item B<new ( %params )>



( run in 0.949 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )