Allow user_class to be configured for Catalyst::Authentication::Store::Minimal
Tomas Doran [Sat, 5 May 2012 13:27:18 +0000 (14:27 +0100)]
Changes
lib/Catalyst/Authentication/Store/Minimal.pm

diff --git a/Changes b/Changes
index 6717b5f..f47ad6b 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 Revision history for Perl extension Catalyst::Plugin::Authentication
 
+     - Allow user_class to be configured for Catalyst::Authentication::Store::Minimal
+       (Jochen Lutz <jlu@akk.org>)
+
 0.10019 14 April 2012
      - Upgrade code to use Moose compatibility layer (jnap)
      - Added some rules to .gitignore for people using macs (jnap)
index 7c03198..63a0afd 100644 (file)
@@ -3,18 +3,24 @@ package Catalyst::Authentication::Store::Minimal;
 use strict;
 use warnings;
 
-use Catalyst::Authentication::User::Hash;
 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 +47,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 {
@@ -148,6 +154,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