ASP4
view release on metacpan or search on metacpan
lib/ASP4/SessionStateManager.pm view on Meta::CPAN
my $conn = context()->config->data_connections->session;
local $^W = 0;
$class->set_db('Session',
$conn->dsn,
$conn->username,
$conn->password
);
my $id = $s->parse_session_id();
unless( $id && $s->verify_session_id( $id, $conn->session_timeout ) )
{
$s->{SessionID} = $s->new_session_id();
$s->write_session_cookie($r);
return $s->create( $s->{SessionID} );
}# end unless()
return $s->retrieve( $id );
}# end new()
sub context { ASP4::HTTPContext->current }
lib/ASP4/SessionStateManager.pm view on Meta::CPAN
my $name = $config->cookie_name;
my @cookie = (
'Set-Cookie' => "$name=$s->{SessionID}; path=/; $domain"
);
context()->headers_out->push_header( @cookie );
@cookie;
}# end write_session_cookie()
sub verify_session_id
{
my ($s, $id, $timeout ) = @_;
my $is_active;
if( $timeout eq '*' )
{
local $s->db_Session->{AutoCommit} = 1;
my $sth = $s->db_Session->prepare(<<"");
SELECT count(*)
FROM asp_sessions
lib/ASP4/SessionStateManager.pm view on Meta::CPAN
FROM asp_sessions
WHERE session_id = ?
AND modified_on - created_on < ?
$sth->execute( $id, $timeout );
($is_active) = $sth->fetchrow();
$sth->finish();
}# end if()
return $is_active;
}# end verify_session_id()
sub create
{
my ($s, $id) = @_;
local $s->db_Session->{AutoCommit} = 1;
my $sth = $s->db_Session->prepare_cached(<<"");
delete from asp_sessions
where session_id = ?
lib/ASP4/SessionStateManager/InMemory.pm view on Meta::CPAN
my $cache = {};
sub new
{
my ($class, $r) = @_;
my $id = $class->parse_session_id();
my $s = bless {SessionID => $id}, $class;
my $conn = ASP4::ConfigLoader->load->data_connections->session;
unless( $id && $s->verify_session_id( $id, $conn->session_timeout ) )
{
$s->{SessionID} = $s->new_session_id();
$s->write_session_cookie($r);
return $s->create( $s->{SessionID} );
}# end unless()
return $s->retrieve( $id );
}# end new()
sub now { time() }
sub verify_session_id
{
my ($s, $id, $ttl) = @_;
exists $cache->{$id};
}# end verify_session_id()
sub retrieve
{
my ($s, $id) = @_;
return $cache->{$id}
if exists $cache->{$id};
}# end retrieve()
lib/ASP4/SessionStateManager/Memcached.pm view on Meta::CPAN
sub new
{
my ($class, $r) = @_;
my $s = bless { }, $class;
my $conn = ASP4::ConfigLoader->load->data_connections->session;
$memd = Cache::Memcached->new({
servers => [ $conn->dsn ]
});
my $id = $s->parse_session_id();
unless( $id && $s->verify_session_id( $id, $conn->session_timeout ) )
{
$s->{__ttl} = $conn->session_timeout;
$s->{SessionID} = $s->new_session_id();
$s->write_session_cookie($r);
return $s->create( $s->{SessionID} );
}# end unless()
return $s->retrieve( $id );
}# end new()
sub verify_session_id
{
my ($s, $id) = @_;
my $ref = $memd->get( $id )
or return;
$s = bless decode_json($ref), ref($s) ? ref($s) : $s;
}# end verify_session_id()
*retrieve = \&verify_session_id;
sub create
{
my ($s, $id) = @_;
$s->save();
return $s;
}# end create()
( run in 0.435 second using v1.01-cache-2.11-cpan-5467b0d2c73 )