Fix typos: s/CORE/CODE/, s/mdoule/module/
[catagits/Web-Session.git] / lib / Plack / Session / Store / File.pm
index 2c15ea1..95dcd41 100644 (file)
@@ -2,7 +2,7 @@ package Plack::Session::Store::File;
 use strict;
 use warnings;
 
-our $VERSION   = '0.03';
+our $VERSION   = '0.11';
 our $AUTHORITY = 'cpan:STEVAN';
 
 use Storable ();
@@ -30,28 +30,21 @@ sub new {
 }
 
 sub fetch {
-    my ($self, $session_id, $key) = @_;
-    my $store = $self->_deserialize( $session_id );
-    return unless exists $store->{ $key };
-    return $store->{ $key };
-}
+    my ($self, $session_id) = @_;
 
-sub store {
-    my ($self, $session_id, $key, $data) = @_;
-    my $store = $self->_deserialize( $session_id );
-    $store->{ $key } = $data;
-    $self->_serialize( $session_id, $store );
+    my $file_path = $self->_get_session_file_path( $session_id );
+    return unless -f $file_path;
+
+    $self->deserializer->( $file_path );
 }
 
-sub delete {
-    my ($self, $session_id, $key) = @_;
-    my $store = $self->_deserialize( $session_id );
-    return unless exists $store->{ $key };
-    delete $store->{ $key };
-    $self->_serialize( $session_id, $store );
+sub store {
+    my ($self, $session_id, $session) = @_;
+    my $file_path = $self->_get_session_file_path( $session_id );
+    $self->serializer->( $session, $file_path );
 }
 
-sub cleanup {
+sub remove {
     my ($self, $session_id) = @_;
     unlink $self->_get_session_file_path( $session_id );
 }
@@ -61,27 +54,6 @@ sub _get_session_file_path {
     $self->dir . '/' . $session_id;
 }
 
-sub _serialize {
-    my ($self, $session_id, $value) = @_;
-    my $file_path = $self->_get_session_file_path( $session_id );
-    $self->serializer->( $value, $file_path );
-}
-
-sub _deserialize {
-    my ($self, $session_id) = @_;
-    my $file_path = $self->_get_session_file_path( $session_id );
-    $self->_serialize( $session_id, {} ) unless -f $file_path;
-    $self->deserializer->( $file_path );
-}
-
-sub dump_session {
-    my ($self, $session_id) = @_;
-    my $file_path = $self->_get_session_file_path( $session_id );
-    return {} unless -f $file_path;
-    $self->deserializer->( $file_path );
-}
-
-
 1;
 
 __END__
@@ -149,14 +121,14 @@ is provided then "/tmp" is used.
 
 =item B<serializer>
 
-This is a CORE reference that implements the serialization logic.
+This is a CODE reference that implements the serialization logic.
 The CODE ref gets two arguments, the C<$value>, which is a HASH
 reference to be serialized, and the C<$file_path> to save it to.
 It is not expected to return anything.
 
 =item B<deserializer>
 
-This is a CORE reference that implements the deserialization logic.
+This is a CODE reference that implements the deserialization logic.
 The CODE ref gets one argument, the C<$file_path> to load the data
 from. It is expected to return a HASH reference.