0.03 release
[catagits/Web-Session.git] / lib / Plack / Session / State.pm
index 8e196f0..b9787d0 100644 (file)
@@ -2,6 +2,9 @@ package Plack::Session::State;
 use strict;
 use warnings;
 
+our $VERSION   = '0.03';
+our $AUTHORITY = 'cpan:STEVAN';
+
 use Digest::SHA1 ();
 
 use Plack::Util::Accessor qw[
@@ -35,40 +38,36 @@ sub is_session_expired {
 
 sub check_expired {
     my ($self, $id) = @_;
-    return unless $id && not $self->is_session_expired( $id );
+    return if $self->is_session_expired( $id );
     return $id;
 }
 
-sub validate_request_session_id {
-    my ($self, $request) = @_;
-
-    my $reqest_session_id = $self->get_request_session_id($request);
-    my $sid_validator = $self->sid_validator;
-
-    defined $reqest_session_id && $reqest_session_id =~ m{$sid_validator};
+sub validate_session_id {
+    my ($self, $id) = @_;
+    $id =~ $self->sid_validator;
 }
 
 sub get_session_id {
     my ($self, $request) = @_;
-    (
-        $self->validate_request_session_id($request)
-        &&
-        $self->extract( $request )
-    )
+    $self->extract( $request )
         ||
     $self->generate( $request )
 }
 
-sub get_request_session_id {
-    my ($self, $request ) = @_;
-
+sub get_session_id_from_request {
+    my ($self, $request) = @_;
     $request->param( $self->session_key );
 }
 
 sub extract {
     my ($self, $request) = @_;
 
-    $self->check_expired( $self->get_request_session_id($request) );
+    my $id = $self->get_session_id_from_request( $request );
+    return unless defined $id;
+
+    $self->validate_session_id( $id )
+        &&
+    $self->check_expired( $id );
 }
 
 sub generate {
@@ -141,7 +140,7 @@ concerned or interested, just read the source.
 
 =item B<sid_validator>
 
-This is a regex used to validate requested session id,
+This is a regex used to validate requested session id.
 
 =back
 
@@ -156,15 +155,25 @@ if the is expired or does not exist, it will then generate a new
 session. The C<$request> is expected to be a L<Plack::Request> instance
 or an object with an equivalent interface.
 
-=item B<get_request_session_id ( $request )>
+=item B<get_session_id_from_request ( $request )>
+
+This is the method used to extract the session id from a C<$request>.
+Subclasses will often only need to override this method and the
+C<finalize> method.
+
+=item B<validate_session_id ( $session_id )>
+
+This will use the C<sid_validator> regex and confirm that the
+C<$session_id> is valid.
 
 =item B<extract ( $request )>
 
 This will attempt to extract the session from a C<$request> by looking
 for the C<session_key> in the C<$request> params. It will then check to
-see if the session has expired and return the session id if it is not.
-The C<$request> is expected to be a L<Plack::Request> instance or an
-object with an equivalent interface.
+see if the session is valid and that it has not expired. It will return
+the session id if everything is good or undef otherwise. The C<$request>
+is expected to be a L<Plack::Request> instance or an object with an
+equivalent interface.
 
 =item B<generate ( $request )>
 
@@ -216,7 +225,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>