3 package Catalyst::Plugin::Authentication::Store::Minimal::Backend;
8 use Catalyst::Plugin::Authentication::User::Hash;
12 my ( $class, $hash ) = @_;
14 bless { hash => $hash }, $class;
18 my ( $self, $c, $id ) = @_;
20 return $id if ref $id;
22 $self->get_user( $id );
26 my ( $self, $id ) = @_;
28 return unless exists $self->{hash}{$id};
30 my $user = $self->{hash}{$id};
33 if ( Scalar::Util::blessed($user) ) {
34 $user->store( $self );
38 elsif ( ref $user eq "HASH" ) {
39 return bless $user, "Catalyst::Plugin::Authentication::User::Hash";
42 Catalyst::Exception->throw( "The user '$id' is a reference of type "
44 . " but should be a HASH" );
48 Catalyst::Exception->throw(
49 "The user '$id' is has to be a hash reference or an object");
58 # choose a random user
59 scalar keys %{ $self->{hash} };
60 ( undef, my $user ) = each %{ $self->{hash} };
73 Catalyst::Plugin::Authentication::Store::Minimal::Backend - Minimal
74 authentication storage backend.
78 # you probably just want Store::Minimal under most cases,
79 # but if you insist you can instantiate your own store:
81 use Catalyst::Plugin::Authentication::Store::Minimal::Backend;
85 Authentication::Credential::Password
89 user => { password => "s3cr3t" },
92 our $users = Catalyst::Plugin::Authentication::Store::Minimal::Backend->new(\%users);
95 my ( $self, $c ) = @_;
97 $c->login( $users->get_user( $c->req->param("login") ),
98 $c->req->param("password") );
103 You probably want L<Catalyst::Plugin::Authentication::Store::Minimal>, unless
104 you are mixing several stores in a single app and one of them is Minimal.
106 Otherwise, this lets you create a store manually.
114 Constructs a new store object, which uses the supplied hash ref as it's backing
119 Keys the hash by $id and returns the value.
121 If the return value is unblessed it will be blessed as
122 L<Catalyst::Plugin::Authentication::User::Hash>.
124 =item from_session $id
126 Delegates to C<get_user>.
130 Chooses a random user from the hash and delegates to it.