Skip to content

Commit

Permalink
move session key prefix setting to Store from Core
Browse files Browse the repository at this point in the history
  • Loading branch information
typester committed Sep 3, 2009
1 parent fe28a98 commit e429795
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/Ark/Plugin/Session/Backend.pm
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ has session_data => (
builder => sub {
my $self = shift;
return unless $self->session_id;
$self->get_session_data( 'session:' . $self->session_id );
$self->get_session_data( $self->session_id );
},
);

Expand Down Expand Up @@ -85,7 +85,7 @@ sub initialize_session_data {
$self->session_data({});
}

# Store
# State
sub get_session_id { }

sub set_session_id {
Expand All @@ -106,7 +106,7 @@ sub finalize_session {
my ($self, $res) = @_;

if ($self->session_updated and my $sid = $self->session_id) {
$self->set_session_data( "session:${sid}", $self->session_data );
$self->set_session_data( $sid, $self->session_data );
}
}

Expand Down
17 changes: 13 additions & 4 deletions lib/Ark/Plugin/Session/Store/Model.pm
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package Ark::Plugin::Session::Store::Model;
use Ark::Plugin 'Session';

has model => (
has store_model => (
is => 'rw',
isa => 'Object',
lazy => 1,
Expand All @@ -11,11 +11,18 @@ has model => (
},
);

has store_model_key_prefix => (
is => 'rw',
isa => 'Str',
default => 'session:',
);

around 'get_session_data' => sub {
my $next = shift;
my ($self, $key) = @_;
$key = $self->store_model_key_prefix . $key;

if (my $session = $self->model->get($key)) {
if (my $session = $self->store_model->get($key)) {
return $session;
}

Expand All @@ -25,17 +32,19 @@ around 'get_session_data' => sub {
around 'set_session_data' => sub {
my $next = shift;
my ($self, $key, $value) = @_;
$key = $self->store_model_key_prefix . $key;

$self->model->set( $key, $value );
$self->store_model->set( $key, $value );

$next->(@_);
};

around 'remove_session_data' => sub {
my $next = shift;
my ($self, $key) = @_;
$key = $self->store_model_key_prefix . $key;

$self->model->remove( $key );
$self->store_model->remove( $key );

$next->(@_);
};
Expand Down

0 comments on commit e429795

Please sign in to comment.