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 $user->{store} = $self;
41 return bless $user, "Catalyst::Plugin::Authentication::User::Hash";
44 Catalyst::Exception->throw( "The user '$id' is a reference of type "
46 . " but should be a HASH" );
50 Catalyst::Exception->throw(
51 "The user '$id' is has to be a hash reference or an object");
60 # choose a random user
61 scalar keys %{ $self->{hash} };
62 ( undef, my $user ) = each %{ $self->{hash} };
75 Catalyst::Plugin::Authentication::Store::Minimal::Backend - Minimal
76 authentication storage backend.
80 # you probably just want Store::Minimal under most cases,
81 # but if you insist you can instantiate your own store:
83 use Catalyst::Plugin::Authentication::Store::Minimal::Backend;
87 Authentication::Credential::Password
91 user => { password => "s3cr3t" },
94 our $users = Catalyst::Plugin::Authentication::Store::Minimal::Backend->new(\%users);
97 my ( $self, $c ) = @_;
99 $c->login( $users->get_user( $c->req->param("login") ),
100 $c->req->param("password") );
105 You probably want L<Catalyst::Plugin::Authentication::Store::Minimal>, unless
106 you are mixing several stores in a single app and one of them is Minimal.
108 Otherwise, this lets you create a store manually.
116 Constructs a new store object, which uses the supplied hash ref as it's backing
121 Keys the hash by $id and returns the value.
123 If the return value is unblessed it will be blessed as
124 L<Catalyst::Plugin::Authentication::User::Hash>.
128 Chooses a random user from the hash and delegates to it.