f81d6e63d7e1bb8791e5250c548f23b1638bff7c
[catagits/Catalyst-Plugin-Authentication.git] / lib / Catalyst / Plugin / Authentication / Store / Minimal.pm
1 package Catalyst::Plugin::Authentication::Store::Minimal;
2
3 use strict;
4 use warnings;
5 use MRO::Compat;
6
7 use Catalyst::Authentication::Store::Minimal ();
8
9 ## backwards compatibility
10 sub setup {
11     my $c = shift;
12
13     ### If a user does 'use Catalyst qw/Authentication::Store::Minimal/'
14     ### he will be proxied on to this setup routine (and only then --
15     ### non plugins should NOT have their setup routine invoked!)
16     ### Beware what we pass to the 'new' routine; it wants
17     ### a config has with a top level key 'users'. New style
18     ### configs do not have this, and split by realms. If we
19     ### blindly pass this to new, we will 1) overwrite what we
20     ### already passed and 2) make ->userhash undefined, which
21     ### leads to:
22     ###  Can't use an undefined value as a HASH reference at
23     ###  lib/Catalyst/Authentication/Store/Minimal.pm line 38.
24     ###
25     ### So only do this compatibility call if:
26     ### 1) we have a {users} config directive
27     ###
28     ### Ideally we could also check for:
29     ### 2) we don't already have a ->userhash
30     ### however, that's an attribute of an object we can't
31     ### access =/ --kane
32
33     my $cfg = $c->config->{'Plugin::Authentication'}->{users}
34                 ? $c->config->{'Plugin::Authentication'}
35                 : undef;
36
37     $c->default_auth_store( Catalyst::Authentication::Store::Minimal->new( $cfg, $c ) ) if $cfg;
38
39         $c->next::method(@_);
40 }
41
42 foreach my $method (qw/ get_user user_supports find_user from_session /) {
43     no strict 'refs';
44     *{$method} = sub { __PACKAGE__->default_auth_store->$method( @_ ) };
45 }
46
47 __PACKAGE__;
48
49 __END__
50
51 =pod
52
53 =head1 NAME
54
55 Catalyst::Plugin::Authentication::Store::Minimal - Compatibility shim
56
57 =head1 DESCRIPTION
58
59 THIS IS A COMPATIBILITY SHIM.  It allows old configurations of Catalyst
60 Authentication to work without code changes.  
61
62 B<DO NOT USE IT IN ANY NEW CODE!>
63
64 Please see L<Catalyst::Authentication::Store::Minimal> for more information.
65
66 =head1 METHODS
67
68 =over
69
70 =item find_user
71
72 =item from_session
73
74 =item get_user
75
76 =item setup
77
78 =item user_supports
79
80 =back
81
82 =cut