remove she-bang lines.
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication / User.pm
index 5961220..e2746eb 100644 (file)
@@ -1,34 +1,38 @@
-#!/usr/bin/perl
-
 package Catalyst::Plugin::Authentication::User;
 
 use strict;
 use warnings;
+use base qw/Class::Accessor::Fast/;
 
-
-## chances are you want to override this.
-sub id { shift->get('id'); }
-
-## returns the realm the user came from - not a good idea to override this.
-sub auth_realm {
-    my $self = shift;
-    $self->{'realm'};
+## auth_realm is the realm this user came from. 
+BEGIN {
+    __PACKAGE__->mk_accessors(qw/auth_realm store/);
 }
 
+## THIS IS NOT A COMPLETE CLASS! it is intended to provide base functionality only.  
+## translation - it won't work if you try to use it directly.
 
+## chances are you want to override this.
+sub id { shift->get('id'); }
 
+## this relies on 'supported_features' being implemented by the subclass.. 
+## but it is not an error if it is not.  it just means you support nothing.  
+## nihilist user objects are welcome here.
 sub supports {
     my ( $self, @spec ) = @_;
 
-    my $cursor = $self->supported_features;
+    my $cursor = undef;
+    if ($self->can('supported_features')) {
+        $cursor = $self->supported_features;
 
-    # traverse the feature list,
-    for (@spec) {
-        #die "bad feature spec: @spec" if ref($cursor) ne "HASH";
-        return if ref($cursor) ne "HASH";
+        # traverse the feature list,
+        for (@spec) {
+            #die "bad feature spec: @spec" if ref($cursor) ne "HASH";
+            return if ref($cursor) ne "HASH";
 
-        $cursor = $cursor->{$_};
-    }
+            $cursor = $cursor->{$_};
+        }
+    } 
 
     return $cursor;
 }
@@ -43,7 +47,7 @@ sub get {
     my ($self, $field) = @_;
     
     my $object;
-    if ($object = $self->get_object && $object->can($field)) {
+    if ($object = $self->get_object and $object->can($field)) {
         return $object->$field();
     } else {
         return undef;
@@ -60,19 +64,13 @@ sub get_object {
     return shift;
 }
 
-## this is an internal routine.  I suggest you don't rely on it's presence. 
-## sets the realm the user came from.
-sub _set_auth_realm {
-    my ($self, $realmname) = @_;
-    $self->{'realm'} = $realmname;
-}
-
 ## Backwards Compatibility
 ## you probably want auth_realm, in fact.  but this does work for backwards compatibility.
-sub store { 
-    my ($self) = @_;
-    return $self->auth_realm->{store};
-}
+## store should be a read-write accessor - so it was moved to mk_accessors
+##sub store { 
+##    my ($self) = @_;
+##    return $self->auth_realm->{store};
+##}
 
 __PACKAGE__;