From: Yuval Kogman Date: Mon, 21 Nov 2005 22:34:46 +0000 (+0000) Subject: Refactor Authentication + some slight doc + perltidy X-Git-Tag: v0.01~12 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=e300c5b6a16c997d81fbeb87dd323c4ef9ce98ab;hp=7bb06c917947fac855ed24e728a09ec63d9fd58c;p=catagits%2FCatalyst-Plugin-Authentication.git Refactor Authentication + some slight doc + perltidy --- diff --git a/lib/Catalyst/Plugin/Authentication.pm b/lib/Catalyst/Plugin/Authentication.pm index 9a34f44..9c61bf8 100644 --- a/lib/Catalyst/Plugin/Authentication.pm +++ b/lib/Catalyst/Plugin/Authentication.pm @@ -21,6 +21,7 @@ sub set_authenticated { my ( $c, $user ) = @_; $c->user($user); + $c->request->{user} = $user; # compatibility kludge if ( $c->isa("Catalyst::Plugin::Session") and $c->config->{authentication}{use_session} @@ -31,23 +32,23 @@ sub set_authenticated { } sub user { - my $c = shift; + my $c = shift; - if ( @_ ) { - return $c->_user( @_ ); - } + if (@_) { + return $c->_user(@_); + } - my $user = $c->_user; + my $user = $c->_user; - if ( $user and !Scalar::Util::blessed( $user ) ) { - return $c->auth_restore_user( $user ); - } + if ( $user and !Scalar::Util::blessed($user) ) { + return $c->auth_restore_user($user); + } - return $user; + return $user; } sub save_user_in_session { - my ( $c, $user ) = @_; + my ( $c, $user ) = @_; my $store = $user->store || ref $user; $c->session->{__user_store} = $c->get_auth_store_name($store) || $store; @@ -87,7 +88,7 @@ sub prepare { and !$c->user ) { if ( $c->sessionid and my $frozen_user = $c->session->{__user} ) { - $c->_user( $frozen_user ); + $c->_user($frozen_user); } } @@ -95,16 +96,15 @@ sub prepare { } sub auth_restore_user { - my ( $c, $frozen_user, $store_name ) = @_; + my ( $c, $frozen_user, $store_name ) = @_; - $store_name ||= $c->session->{__user_store}; - $frozen_user ||= $c->session->{__user}; + $store_name ||= $c->session->{__user_store}; + $frozen_user ||= $c->session->{__user}; - my $store = $c->get_auth_store( $store_name ); - $c->_user( my $user = $store->from_session( $c, $frozen_user ) ); - $c->request->{user} = $user; # compatibility kludge + my $store = $c->get_auth_store($store_name); + $c->_user( my $user = $store->from_session( $c, $frozen_user ) ); - return $user; + return $user; } @@ -232,6 +232,15 @@ authentication. This involves setting C and the internal data in C if L is loaded. +=item auth_restore_user $user + +Used to restore a user from the session, by C only when it's actually +needed. + +=item save_user_in_session $user + +Used to save the user in a session. + =item prepare Revives a user from the session object if there is one. diff --git a/lib/Catalyst/Plugin/Authentication/User/Hash.pm b/lib/Catalyst/Plugin/Authentication/User/Hash.pm index 49f92eb..db1783e 100644 --- a/lib/Catalyst/Plugin/Authentication/User/Hash.pm +++ b/lib/Catalyst/Plugin/Authentication/User/Hash.pm @@ -9,7 +9,7 @@ use warnings; sub new { my $class = shift; - bless { @_ }, $class; + bless { ( @_ > 1 ) ? @_ : %{ $_[0] } }, $class; } sub AUTOLOAD {