File Coverage

blib/lib/Catalyst/Plugin/Authentication/Store/Htpasswd/Backend.pm
Criterion Covered Total %
statement 24 24 100.0
branch 1 2 50.0
condition n/a
subroutine 10 10 100.0
pod 3 4 75.0
total 38 40 95.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package Catalyst::Plugin::Authentication::Store::Htpasswd::Backend;
4 2     2   59698 use base qw/Class::Accessor::Fast/;
  2         3  
  2         868  
5              
6 2     2   6324 use strict;
  2         3  
  2         27  
7 2     2   5 use warnings;
  2         6  
  2         33  
8              
9 2     2   769 use Authen::Htpasswd;
  2         15256  
  2         6  
10 2     2   799 use Catalyst::Plugin::Authentication::Store::Htpasswd::User;
  2         13  
  2         21  
11              
12 2     2   76 BEGIN { __PACKAGE__->mk_accessors(qw/file/) }
13              
14             sub new {
15 2     2 1 18372 my ( $class, $file, %extra ) = @_;
16              
17 2 50       17 bless { file => ( ref $file ? $file : Authen::Htpasswd->new($file, \%extra) ) }, $class;
18             }
19              
20             sub get_user {
21 3     3 1 1375 my ( $self, $id ) = @_;
22 3         8 Catalyst::Plugin::Authentication::Store::Htpasswd::User->new( $self, $self->file->lookup_user($id) );
23             }
24              
25             sub user_supports {
26 3     3 1 9328 my $self = shift;
27              
28             # this can work as a class method
29 3         33 Catalyst::Plugin::Authentication::Store::Htpasswd::User->supports(@_);
30             }
31              
32             sub from_session {
33 1     1 0 81 my ( $self, $c, $id ) = @_;
34 1         2 $self->get_user( $id );
35             }
36              
37             __PACKAGE__;
38              
39             __END__
40              
41             =pod
42              
43             =head1 NAME
44              
45             Catalyst::Plugin::Authentication::Store::Htpasswd::Backend - Htpasswd
46             authentication storage backend.
47              
48             =head1 SYNOPSIS
49              
50             # you probably just want Store::Htpasswd under most cases,
51             # but if you insist you can instantiate your own store:
52              
53             use Catalyst::Plugin::Authentication::Store::Htpasswd::Backend;
54              
55             use Catalyst qw/
56             Authentication
57             Authentication::Credential::Password
58             /;
59              
60             my %users = (
61             user => { password => "s3cr3t" },
62             );
63            
64             our $users = Catalyst::Plugin::Authentication::Store::Htpasswd::Backend->new(\%users);
65              
66             sub action : Local {
67             my ( $self, $c ) = @_;
68              
69             $c->login( $users->get_user( $c->req->param("login") ),
70             $c->req->param("password") );
71             }
72              
73             =head1 DESCRIPTION
74              
75             You probably want L<Catalyst::Plugin::Authentication::Store::Htpasswd>, unless
76             you are mixing several stores in a single app and one of them is Htpasswd.
77              
78             Otherwise, this lets you create a store manually.
79              
80             =head1 METHODS
81              
82             =head2 new $hash_ref
83              
84             Constructs a new store object, which uses the supplied hash ref as it's backing
85             structure.
86              
87             =head2 get_user $id
88              
89             Keys the hash by $id and returns the value.
90              
91             If the return value is unblessed it will be blessed as
92             L<Catalyst::Plugin::Authentication::User::Hash>.
93              
94             =head2 user_supports
95              
96             Chooses a random user from the hash and delegates to it.
97              
98             =head1 COPYRIGHT & LICENSE
99              
100             Copyright (c) 2005 the aforementioned authors. All rights
101             reserved. This program is free software; you can redistribute
102             it and/or modify it under the same terms as Perl itself.
103              
104             =cut
105              
106