Kill off Class::Accessor::Fast
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Authentication / Store / Minimal.pm
index 6dd4aba..921f8c4 100644 (file)
@@ -1,20 +1,23 @@
 package Catalyst::Authentication::Store::Minimal;
+use Moose;
+use namespace::autoclean;
 
-use strict;
-use warnings;
-
-use Catalyst::Authentication::User::Hash;
+with 'MooseX::Emulate::Class::Accessor::Fast';
 use Scalar::Util qw( blessed );
-use base qw/Class::Accessor::Fast/;
 
-BEGIN {
-    __PACKAGE__->mk_accessors(qw/userhash/);
-}
+__PACKAGE__->mk_accessors(qw/userhash userclass/);
 
 sub new {
     my ( $class, $config, $app, $realm) = @_;
 
-    bless { userhash => $config->{'users'} }, $class;
+    my $self = bless {
+        userhash => $config->{'users'},
+        userclass => $config->{'user_class'} || "Catalyst::Authentication::User::Hash",
+    }, $class;
+
+    Catalyst::Utils::ensure_class_loaded( $self->userclass );
+
+    return $self;
 }
 
 sub from_session {
@@ -41,7 +44,7 @@ sub find_user {
 
     if ( ref($user) eq "HASH") {
         $user->{id} ||= $id;
-        return bless $user, "Catalyst::Authentication::User::Hash";
+        return bless $user, $self->userclass;
     } elsif ( ref($user) && blessed($user) && $user->isa('Catalyst::Authentication::User::Hash')) {
         return $user;
     } else {
@@ -104,7 +107,7 @@ Catalyst::Authentication::Store::Minimal - Minimal authentication store
                                 },
                                 store => {
                                     class => 'Minimal',
-                                           users => {
+                                    users => {
                                         bob => {
                                             password => "s00p3r",
                                             editor => 'yes',
@@ -148,6 +151,12 @@ Catalyst::Authentication::Store::Minimal is loaded as the
 user store. For this module to be used, this must be set to
 'Minimal'.
 
+=item user_class
+
+The class used for the user object. If you don't specify a class name, the
+default L<Catalyst::Authentication::User::Hash> will be used. If you define your
+own class, it must inherit from L<Catalyst::Authentication::User::Hash>.
+
 =item users
 
 This is a simple hash of users, the keys are the usenames, and the values are