Checking in changes prior to tagging of version 0.10. Changelog diff is:
[catagits/Web-Session.git] / lib / Plack / Session / Store / File.pm
index 0e5918d..b93ca4c 100644 (file)
@@ -2,6 +2,9 @@ package Plack::Session::Store::File;
 use strict;
 use warnings;
 
+our $VERSION   = '0.10';
+our $AUTHORITY = 'cpan:STEVAN';
+
 use Storable ();
 
 use parent 'Plack::Session::Store';
@@ -20,35 +23,28 @@ sub new {
     die "Storage directory (" . $params{'dir'} . ") is not writeable"
         unless -w $params{'dir'};
 
-    $params{'serializer'}   ||= sub { Storable::nstore( @_ ) };
-    $params{'deserializer'} ||= sub { Storable::retrieve( @_ ) };
+    $params{'serializer'}   ||= sub { Storable::lock_nstore( @_ ) };
+    $params{'deserializer'} ||= sub { Storable::lock_retrieve( @_ ) };
 
     bless { %params } => $class;
 }
 
 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 );
 }
@@ -58,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__
@@ -124,7 +99,7 @@ Plack::Session::Store::File - Basic file-based session store
 
 This implements a basic file based storage for session data. By
 default it will use L<Storable> to serialize and deserialize the
-data, but this can be configured easily.
+data, but this can be configured easily. 
 
 This is a subclass of L<Plack::Session::Store> and implements
 it's full interface.
@@ -171,7 +146,7 @@ Stevan Little E<lt>stevan.little@iinteractive.comE<gt>
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright 2009 Infinity Interactive, Inc.
+Copyright 2009, 2010 Infinity Interactive, Inc.
 
 L<http://www.iinteractive.com>