Adding Wrapper class, missed in the last one
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication / Credential / Wrapper.pm
1 package Catalyst::Plugin::Authentication::Credential::Wrapper;
2
3 use strict;
4 use warnings;
5
6 sub new {
7     my ($myclass, $hash, $app) = @_;
8     
9
10     if (!exists($hash->{'class'})) {
11         Carp::croak "Couldn't setup a wrapped Credential, no module specified";
12     }
13     my $data = {};
14     my $wrappedclass = $hash->{'class'};
15     my $authroutine = $hash->{'authroutine'} ||= 'authenticate';
16     $data->{authroutine} = $wrappedclass->can($authroutine);
17     
18     if (!$data->{'authroutine'}) {
19         Carp::croak "Couldn't set up a wrapped Credential, auth sub: $authroutine was not found";
20     }
21     
22     bless $data, $myclass;   
23 }
24
25 sub authenticate {
26     my ($self, $c, $store, $authinfo) = @_;
27     
28     return $self->{'authroutine'}->($c, $store, $authinfo);
29 }
30
31 __PACKAGE__;
32
33 __END__