Changes to use Class::Accessor::Fast
[catagits/Catalyst-Authentication-Store-DBIx-Class.git] / lib / Catalyst / Plugin / Authentication / Store / DBIx / Class / Backend.pm
CommitLineData
5000f545 1package Catalyst::Plugin::Authentication::Store::DBIx::Class::Backend;
2
3use strict;
4use warnings;
5use base qw/Class::Accessor::Fast/;
6
b33ee900 7our $VERSION= "0.02";
8
9BEGIN {
10 __PACKAGE__->mk_accessors(qw/config/);
11}
12
13
5000f545 14sub new {
15 my ( $class, $config, $app ) = @_;
16
b33ee900 17 ## figure out if we are overriding the default store user class
18 $config->{'store_user_class'} = (exists($config->{'store_user_class'})) ? $config->{'store_user_class'} :
19 "Catalyst::Plugin::Authentication::Store::DBIx::Class::User";
20
5000f545 21 ## make sure the store class is loaded.
b33ee900 22 Catalyst::Utils::ensure_class_loaded( $config->{'store_user_class'} );
5000f545 23
b33ee900 24 ## fields can be specified to be ignored during user location. This allows
25 ## the backend to ignore certain fields in the authinfo hash.
5000f545 26
b33ee900 27 $config->{'ignore_fields_in_find'} ||= [ ];
28
29 my $self = {
30 config => $config
31 };
5000f545 32
33 bless $self, $class;
b33ee900 34
5000f545 35}
36
ba48c9c3 37## --jk note to self:
38## let's use DBICs get_columns method to return a hash and save / restore that
39## from the session. Then we can respond to get() calls, etc. in most cases without
40## resorting to a DB call. If user_object is called, THEN we can hit the DB and
41## return a real object.
5000f545 42sub from_session {
43 my ( $self, $c, $frozenuser ) = @_;
44
45 return $frozenuser if ref $frozenuser;
b33ee900 46
47 my $user = $self->config->{'store_user_class'}->new($self->{'config'}, $c);
48
49 return $user->from_session($frozenuser, $c);
5000f545 50}
51
52sub for_session {
53 my ($self, $c, $user) = @_;
54
55 return $user->for_session($c);
56}
57
58sub find_user {
59 my ( $self, $authinfo, $c ) = @_;
60
b33ee900 61 my $user = $self->config->{'store_user_class'}->new($self->{'config'}, $c);
5000f545 62
b33ee900 63 return $user->load($authinfo, $c);
64
65}
5000f545 66
67sub user_supports {
b33ee900 68 my $self = shift;
69 # this can work as a class method on the user class
70 $self->config->{'store_user_class'}->supports( @_ );
5000f545 71}
72
73__PACKAGE__;
74
75__END__
76
77=head1 NAME
78
79Catalyst::Plugin::Authentication::Store::DBIx::Class::Backend - A class to ...
80
81=head1 VERSION
82
83This documentation refers to version 0.01.
84
85=head1 SYNOPSIS
86
87use Catalyst::Plugin::Authentication::Store::DBIx::Class::Backend;
88
89=head1 DESCRIPTION
90
91The Catalyst::Plugin::Authentication::Store::DBIx::Class::Backend class implements ...
92
93=head1 SUBROUTINES / METHODS
94
95=head2 new (constructor)
96
97Parameters:
98 class
99 config
100 app
101
102Insert description of constructor here...
103
104=head2 from_session (method)
105
106Parameters:
107 c
108 frozenuser
109
110Insert description of method here...
111
112=head2 for_session (method)
113
114Parameters:
115 c
116 user
117
118Insert description of method here...
119
120=head2 find_user (method)
121
122Parameters:
123 authinfo
124 c
125
126Insert description of method here...
127
128=head2 user_supports
129
130Parameters:
131 none
132
133Insert description of subroutine here...
134
135=head1 DEPENDENCIES
136
137Modules used, version dependencies, core yes/no
138
139strict
140
141warnings
142
143=head1 NOTES
144
145...
146
147=head1 BUGS AND LIMITATIONS
148
149None known currently, please email the author if you find any.
150
151=head1 SEE ALSO
152
153L<Catalyst::Plugin::Authentication::Store::DBIC>, L<Catalyst::Plugin::Authentication>,
154L<Catalyst::Plugin::Authorization::Roles>
155
156=head1 AUTHOR
157
b33ee900 158Jason Kuri (jayk@cpan.org)
5000f545 159
160=head1 LICENCE
161
162Copyright 2006 by Jason Kuri.
163
164This software is free. It is licensed under the same terms as Perl itself.
165
166=cut