Port from NEXT to C3.
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication / Store / Minimal.pm
index af17d4b..f81d6e6 100644 (file)
@@ -1,19 +1,47 @@
-#!/usr/bin/perl
-
 package Catalyst::Plugin::Authentication::Store::Minimal;
 
 use strict;
 use warnings;
+use MRO::Compat;
 
-use Catalyst::Plugin::Authentication::Store::Minimal::Backend;
+use Catalyst::Authentication::Store::Minimal ();
 
+## backwards compatibility
 sub setup {
     my $c = shift;
 
-    $c->config->{authentication}{store} =
-      Catalyst::Plugin::Authentication::Store::Minimal::Backend->new(
-        $c->config->{authentication}{users} );
+    ### If a user does 'use Catalyst qw/Authentication::Store::Minimal/'
+    ### he will be proxied on to this setup routine (and only then --
+    ### non plugins should NOT have their setup routine invoked!)
+    ### Beware what we pass to the 'new' routine; it wants
+    ### a config has with a top level key 'users'. New style
+    ### configs do not have this, and split by realms. If we
+    ### blindly pass this to new, we will 1) overwrite what we
+    ### already passed and 2) make ->userhash undefined, which
+    ### leads to:
+    ###  Can't use an undefined value as a HASH reference at
+    ###  lib/Catalyst/Authentication/Store/Minimal.pm line 38.
+    ###
+    ### So only do this compatibility call if:
+    ### 1) we have a {users} config directive
+    ###
+    ### Ideally we could also check for:
+    ### 2) we don't already have a ->userhash
+    ### however, that's an attribute of an object we can't
+    ### access =/ --kane
+
+    my $cfg = $c->config->{'Plugin::Authentication'}->{users}
+                ? $c->config->{'Plugin::Authentication'}
+                : undef;
+
+    $c->default_auth_store( Catalyst::Authentication::Store::Minimal->new( $cfg, $c ) ) if $cfg;
+
+       $c->next::method(@_);
+}
 
+foreach my $method (qw/ get_user user_supports find_user from_session /) {
+    no strict 'refs';
+    *{$method} = sub { __PACKAGE__->default_auth_store->$method( @_ ) };
 }
 
 __PACKAGE__;
@@ -24,53 +52,31 @@ __END__
 
 =head1 NAME
 
-Catalyst::Plugin::Authentication::Store::Minimal - Authentication
-database in C<<$c->config>>.
-
-=head1 SYNOPSIS
+Catalyst::Plugin::Authentication::Store::Minimal - Compatibility shim
 
-    use Catalyst qw/
-      Authentication
-      Authentication::Store::Minimal
-      Authentication::Credential::Password
-      /;
-
-    __PACKAGE__->config->{authentication}{users} = {
-        name => {
-            password => "s3cr3t",
-            roles    => [qw/admin editor/],
-            ...
-        },
-    };
+=head1 DESCRIPTION
 
-    sub login : Global {
-        my ( $self, $c ) = @_;
+THIS IS A COMPATIBILITY SHIM.  It allows old configurations of Catalyst
+Authentication to work without code changes.  
 
-        $c->login( $c->req->param("login"), $c->req->param("password"), );
-    }
+B<DO NOT USE IT IN ANY NEW CODE!>
 
-=head1 DESCRIPTION
+Please see L<Catalyst::Authentication::Store::Minimal> for more information.
 
-This authentication store plugin lets you create a very quick and dirty user
-database in your application's config hash.
+=head1 METHODS
 
-It's purpose is mainly for testing, and it should probably be replaced by a
-more "serious" store for production.
+=over
 
-The hash in the config, as well as the user objects/hashes are freely mutable
-at runtime.
+=item find_user
 
-=head1 METHODS
+=item from_session
 
-=over 4
+=item get_user
 
 =item setup
 
-This method will popultate C<< $c->config->{authentication}{store} >> so that
-L<Catalyst::Plugin::Authentication/default_auth_store> can use it.
+=item user_supports
 
 =back
 
 =cut
-
-