$user->supports("foo") will also return true for User::Hash if there is such a key
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication.pm
index 7887cad..32b23da 100644 (file)
@@ -15,6 +15,11 @@ use warnings;
 use Tie::RefHash;
 use Class::Inspector;
 
+BEGIN {
+       require constant;
+       constant->import(have_want => eval { require Want });
+}
+
 our $VERSION = "0.01";
 
 sub set_authenticated {
@@ -30,7 +35,7 @@ sub set_authenticated {
         $c->save_user_in_session($user);
     }
 
-       $c->NEXT::set_authenticated( $user );
+    $c->NEXT::set_authenticated($user);
 }
 
 sub user {
@@ -43,6 +48,7 @@ sub user {
     my $user = $c->_user;
 
     if ( $user and !Scalar::Util::blessed($user) ) {
+               return 1 if have_want() && Want::want("BOOL");
         return $c->auth_restore_user($user);
     }
 
@@ -85,7 +91,7 @@ sub get_user {
 sub prepare {
     my $c = shift->NEXT::prepare(@_);
 
-    if (    $c->isa("Catalyst::Plugin::Session")
+    if ( $c->isa("Catalyst::Plugin::Session")
         and !$c->user )
     {
         if ( $c->sessionid and my $frozen_user = $c->session->{__user} ) {
@@ -99,6 +105,11 @@ sub prepare {
 sub auth_restore_user {
     my ( $c, $frozen_user, $store_name ) = @_;
 
+    return
+      unless $c->isa("Catalyst::PLugin::Session")
+      and $c->config->{authentication}{use_session}
+      and $c->sessionid;
+
     $store_name  ||= $c->session->{__user_store};
     $frozen_user ||= $c->session->{__user};
 
@@ -155,12 +166,10 @@ sub auth_stores {
 sub auth_store_names {
     my $self = shift;
 
-    unless ( $self->_auth_store_names ) {
+    $self->_auth_store_names || do {
         tie my %hash, 'Tie::RefHash';
         $self->_auth_store_names( \%hash );
-    }
-
-    $self->_auth_store_names;
+      }
 }
 
 sub default_auth_store {
@@ -204,23 +213,54 @@ L<Catalyst::Plugin::Session> plugin,
 
 =over 4 
 
-=item logout
-
-Delete the currently logged in user from C<user> and the session.
-
 =item user
 
 Returns the currently logged user or undef if there is none.
 
+=item logout
+
+Delete the currently logged in user from C<user> and the session.
+
 =item get_user $uid
 
 Delegate C<get_user> to the default store.
 
+=back
+
+=head1 METHODS FOR STORE MANAGEMENT
+
 =item default_auth_store
 
-Returns C<< $c->config->{authentication}{store} >>.
+Return the store whose name is 'default'.
 
-=back
+This is set to C<<$c->config->{authentication}{store}>> if that value exists,
+or by using a Store plugin:
+
+       use Catalyst qw/Authentication Authentication::Store::Minimal/;
+
+Sets the default store to
+L<Catalyst::Plugin::Authentication::Store::Minimal::Backend>.
+
+
+=item get_auth_store $name
+
+Return the store whose name is $name.
+
+=item get_auth_store_name $store
+
+Return the name of the store $store.
+
+=item auth_stores
+
+A hash keyed by name, with the stores registered in the app.
+
+=item auth_store_names
+
+A ref-hash keyed by store, which contains the names of the stores.
+
+=item register_auth_stores %stores_by_name
+
+Register stores into the application.
 
 =head1 INTERNAL METHODS