X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FPlugin%2FAuthentication%2FUser%2FHash.pm;h=839f5f4145b70de6a020ac5d3b0836c3fb8f3667;hb=4b69b736d1545152c823a97885b15cbe457a80f0;hp=f7cbe5a9e2b86daf7c9186dcfb88f68462d9a21c;hpb=0c4ddd064218a77c17d1bd59fa2963ee31f594b4;p=catagits%2FCatalyst-Plugin-Authentication.git diff --git a/lib/Catalyst/Plugin/Authentication/User/Hash.pm b/lib/Catalyst/Plugin/Authentication/User/Hash.pm index f7cbe5a..839f5f4 100644 --- a/lib/Catalyst/Plugin/Authentication/User/Hash.pm +++ b/lib/Catalyst/Plugin/Authentication/User/Hash.pm @@ -9,13 +9,31 @@ use warnings; sub new { my $class = shift; - bless { @_ }, $class; + bless { ( @_ > 1 ) ? @_ : %{ $_[0] } }, $class; } sub AUTOLOAD { my $self = shift; ( my $key ) = ( our $AUTOLOAD =~ m/([^:]*)$/ ); + $self->_accessor( $key, @_ ); +} + +sub id { + my $self = shift; + $self->_accessor( "id", @_ ); +} + +## deprecated. Let the base class handle this. +# sub store { +# my $self = shift; +# $self->_accessor( "store", @_ ) || ref $self; +# } + +sub _accessor { + my $self = shift; + my $key = shift; + if (@_) { my $arr = $self->{__hash_obj_key_is_array}{$key} = @_ > 1; $self->{$key} = $arr ? [@_] : shift; @@ -23,7 +41,7 @@ sub AUTOLOAD { my $data = $self->{$key}; ( $self->{__hash_obj_key_is_array}{$key} || $key =~ /roles/ ) - ? @$data + ? @{ $data || [] } : $data; } @@ -43,10 +61,11 @@ sub supports { my $cursor = \%features; + return 1 if @spec == 1 and exists $self->{ $spec[0] }; + # traverse the feature list, for (@spec) { - die "bad feature spec: @spec" - if ref($cursor) ne "HASH"; + return if ref($cursor) ne "HASH"; $cursor = $cursor->{$_}; } @@ -67,14 +86,12 @@ sub supports { sub for_session { my $self = shift; - - return $self; # let's hope we're serialization happy + return $self->store && $self->id || $self; # if we have a store and an ID we serialize by ref, otherwise we serialize the whole user } sub from_session { my ( $self, $c, $user ) = @_; - - return $user; # if we're serialization happy this should work + $user; } __PACKAGE__; @@ -125,6 +142,12 @@ Just passes returns the unserialized object, hoping it's intact. Accessor for the key whose name is the method. +=item id + +=item store + +Accessors that override superclass's dying virtual methods. + =back =head1 SEE ALSO