Adding Wrapper class, missed in the last one
Matt S Trout [Tue, 17 Jul 2007 16:57:39 +0000 (16:57 +0000)]
r33940@cain (orig r5490):  jayk | 2006-11-10 22:31:16 +0000

lib/Catalyst/Plugin/Authentication/Credential/Wrapper.pm [new file with mode: 0644]

diff --git a/lib/Catalyst/Plugin/Authentication/Credential/Wrapper.pm b/lib/Catalyst/Plugin/Authentication/Credential/Wrapper.pm
new file mode 100644 (file)
index 0000000..cea68b0
--- /dev/null
@@ -0,0 +1,33 @@
+package Catalyst::Plugin::Authentication::Credential::Wrapper;
+
+use strict;
+use warnings;
+
+sub new {
+    my ($myclass, $hash, $app) = @_;
+    
+
+    if (!exists($hash->{'class'})) {
+        Carp::croak "Couldn't setup a wrapped Credential, no module specified";
+    }
+    my $data = {};
+    my $wrappedclass = $hash->{'class'};
+    my $authroutine = $hash->{'authroutine'} ||= 'authenticate';
+    $data->{authroutine} = $wrappedclass->can($authroutine);
+    
+    if (!$data->{'authroutine'}) {
+        Carp::croak "Couldn't set up a wrapped Credential, auth sub: $authroutine was not found";
+    }
+    
+    bless $data, $myclass;   
+}
+
+sub authenticate {
+    my ($self, $c, $store, $authinfo) = @_;
+    
+    return $self->{'authroutine'}->($c, $store, $authinfo);
+}
+
+__PACKAGE__;
+
+__END__
\ No newline at end of file