1 package Catalyst::Authentication::User;
3 use namespace::autoclean;
5 with 'MooseX::Emulate::Class::Accessor::Fast';
6 use Scalar::Util qw/refaddr/;
8 ## auth_realm is the realm this user came from.
9 __PACKAGE__->mk_accessors(qw/auth_realm store/);
11 ## THIS IS NOT A COMPLETE CLASS! it is intended to provide base functionality only.
12 ## translation - it won't work if you try to use it directly.
14 ## chances are you want to override this.
15 sub id { shift->get('id'); }
17 ## this relies on 'supported_features' being implemented by the subclass..
18 ## but it is not an error if it is not. it just means you support nothing.
19 ## nihilist user objects are welcome here.
21 my ( $self, @spec ) = @_;
24 if ($self->can('supported_features')) {
25 $cursor = $self->supported_features;
27 # traverse the feature list,
29 #die "bad feature spec: @spec" if ref($cursor) ne "HASH";
30 return if ref($cursor) ne "HASH";
32 $cursor = $cursor->{$_};
40 ## get should return the value of the field specified as it's single argument from the underlying
41 ## user object. This is here to provide a simple, standard way of accessing individual elements of a user
42 ## object - ensuring no overlap between C::P::A::User methods and actual fieldnames.
43 ## this is not the most effecient method, since it uses introspection. If you have an underlying object
44 ## you most likely want to write this yourself.
46 my ($self, $field) = @_;
49 if ($object = $self->get_object and $object->can($field)) {
50 return $object->$field();
57 ## get_object should return the underlying user object. This is for when more advanced uses of the
58 ## user is required. Modifications to the existing user, etc. Changes in the object returned
59 ## by this routine may not be reflected in the C::P::A::User object - if this is required, re-authenticating
60 ## the user is probably the best route to take.
61 ## note that it is perfectly acceptable to return $self in cases where there is no underlying object.
66 ## obj is shorthand for get_object. This is originally from the DBIx::Class store, but
67 ## as it has become common usage, this makes things more compatible. Plus, it's shorter.
70 return $self->get_object(@_);
75 (my $method) = (our $AUTOLOAD =~ /([^:]+)$/);
76 return if $method eq "DESTROY";
79 # Don't bother unless we have a backing object
80 return if refaddr($obj) eq refaddr($self);
93 Catalyst::Authentication::User - Base class for user objects.
97 package MyStore::User;
98 use base qw/Catalyst::Authentication::User/;
102 This is the base class for authentication user objects.
104 THIS IS NOT A COMPLETE CLASS! it is intended to provide base functionality only.
106 It provides the base methods listed below, and any additional methods
107 are proxied onto the user object fetched from the underlieing store.
109 =head1 NOTES TO STORE IMPLEMENTORS
111 Please read the comments in the source code of this class to work out
112 which methods you should override.
118 A unique ID by which a user can be retrieved from the store.
122 Should return a class name that can be used to refetch the user using it's
127 An introspection method used to determine what features a user object has, to support credential and authorization plugins.
131 Returns the value for the $field provided.
135 Returns the underlying object storing the user data. The return value of this
136 method will vary depending
137 on the storage module used.
141 Shorthand for get_object( )
145 Delegates any unknown methods onto the user object returned by ->obj