File Coverage

blib/lib/Catalyst/Authentication/Store/Htpasswd/User.pm
Criterion Covered Total %
statement 26 29 89.6
branch 2 6 33.3
condition n/a
subroutine 11 12 91.6
pod 5 5 100.0
total 44 52 84.6


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package Catalyst::Authentication::Store::Htpasswd::User;
4             # ABSTRACT: A user object representing an entry in an htpasswd file.
5              
6 4     4   27 use base qw/Catalyst::Authentication::User Class::Accessor::Fast/;
  4         9  
  4         1699  
7              
8 4     4   1562318 use strict;
  4         16  
  4         93  
9 4     4   24 use warnings;
  4         18  
  4         267  
10              
11             our $VERSION = '1.005';
12              
13 4     4   44 BEGIN { __PACKAGE__->mk_accessors(qw/_user _store/) }
14              
15 4     4   29347 use overload '""' => sub { shift->id }, fallback => 1;
  4     2   10  
  4         43  
  2         17326  
16              
17             sub new {
18 4     4 1 65 my ( $class, $store, $user ) = @_;
19              
20 4 50       60 return unless $user;
21              
22 4         58 bless { _store => $store, _user => $user }, $class;
23             }
24              
25             sub id {
26 4     4 1 2580 my $self = shift;
27 4         28 return $self->_user->username;
28             }
29              
30             sub supported_features {
31             return {
32 4     4 1 84 password => {
33             self_check => 1,
34             },
35             session => 1,
36             roles => 1,
37             };
38             }
39              
40             sub check_password {
41 3     3 1 1610 my ( $self, $password ) = @_;
42 3         17 return $self->_user->check_password( $password );
43             }
44              
45             sub roles {
46 0     0 1 0 my $self = shift;
47 0         0 my $field = $self->_user->extra_info->[0];
48 0 0       0 return defined $field ? split /,/, $field : ();
49             }
50              
51             *for_session = \&id;
52              
53             *get_object = \&_user;
54              
55             sub AUTOLOAD {
56 2     2   144 my $self = shift;
57            
58 2         15 ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ );
59              
60 2 50       11 return if $method eq "DESTROY";
61            
62 2         6 $self->_user->$method;
63             }
64              
65             1;
66              
67             __END__
68              
69             =pod
70              
71             =encoding UTF-8
72              
73             =head1 NAME
74              
75             Catalyst::Authentication::Store::Htpasswd::User - A user object representing an entry in an htpasswd file.
76              
77             =head1 VERSION
78              
79             version 1.005
80              
81             =head1 DESCRIPTION
82              
83             This object wraps an L<Authen::Htpasswd::User> object. An instance of it will be returned
84             by C<< $c->user >> when using L<Catalyst::Authentication::Store::Htpasswd>. Methods
85             not defined in this module are passed through to the L<Authen::Htpasswd::User> object. The
86             object stringifies to the username.
87              
88             =head1 METHODS
89              
90             =head2 new($store,$user)
91              
92             Creates a new object from a store object, normally an instance of
93             L<Catalyst::Authentication::Store::Htpasswd::Backend>, and a user object,
94             normally an instance of L<Authen::Htpasswd::User>.
95              
96             =head2 id
97              
98             Returns the username.
99              
100             =head2 check_password($password)
101              
102             Returns whether the password is valid.
103              
104             =head2 roles
105              
106             Returns an array of roles, which is extracted from a comma-separated list in the
107             third field of the htpasswd file.
108              
109             =head2 for_session
110              
111             Returns the username, which is then stored in the session.
112              
113             =head2 supported_features
114              
115             Returns data about which featurs this user module supports.
116              
117             =head2 get_object
118              
119             Returns the underlieing L<Authen::Htpasswd::User> object for this user
120              
121             =head1 SUPPORT
122              
123             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=Catalyst-Authentication-Store-Htpasswd>
124             (or L<bug-Catalyst-Authentication-Store-Htpasswd@rt.cpan.org|mailto:bug-Catalyst-Authentication-Store-Htpasswd@rt.cpan.org>).
125              
126             There is also a mailing list available for users of this distribution, at
127             L<http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst>.
128              
129             There is also an irc channel available for users of this distribution, at
130             L<C<#catalyst> on C<irc.perl.org>|irc://irc.perl.org/#catalyst>.
131              
132             =head1 AUTHOR
133              
134             יובל קוג'מן (Yuval Kogman) <nothingmuch@woobling.org>
135              
136             =head1 COPYRIGHT AND LICENCE
137              
138             This software is copyright (c) 2005 by יובל קוג'מן (Yuval Kogman).
139              
140             This is free software; you can redistribute it and/or modify it under
141             the same terms as the Perl 5 programming language system itself.
142              
143             =cut