dzilified this dist
[catagits/Catalyst-Authentication-Store-Htpasswd.git] / lib / Catalyst / Authentication / Store / Htpasswd / User.pm
CommitLineData
e8a7c384 1#!/usr/bin/perl
2
16585083 3package Catalyst::Authentication::Store::Htpasswd::User;
d2924b3f 4# ABSTRACT: A user object representing an entry in an htpasswd file.
5
16585083 6use base qw/Catalyst::Authentication::User Class::Accessor::Fast/;
e8a7c384 7
8use strict;
9use warnings;
10
66a5688d 11our $VERSION = '1.005';
12
8ba206fe 13BEGIN { __PACKAGE__->mk_accessors(qw/_user _store/) }
e8a7c384 14
7efcea1c 15use overload '""' => sub { shift->id }, fallback => 1;
47fb088e 16
e8a7c384 17sub new {
039544ff 18 my ( $class, $store, $user ) = @_;
e8a7c384 19
ad94190e 20 return unless $user;
21
8ba206fe 22 bless { _store => $store, _user => $user }, $class;
e8a7c384 23}
24
7efcea1c 25sub id {
26 my $self = shift;
8ba206fe 27 return $self->_user->username;
7efcea1c 28}
29
e8a7c384 30sub supported_features {
31 return {
3e35965a 32 password => {
33 self_check => 1,
47fb088e 34 },
3e35965a 35 session => 1,
8fade176 36 roles => 1,
e8a7c384 37 };
38}
39
40sub check_password {
41 my ( $self, $password ) = @_;
8ba206fe 42 return $self->_user->check_password( $password );
e8a7c384 43}
44
45sub roles {
46 my $self = shift;
8ba206fe 47 my $field = $self->_user->extra_info->[0];
cedb9fb4 48 return defined $field ? split /,/, $field : ();
e8a7c384 49}
50
8ba206fe 51*for_session = \&id;
52
53*get_object = \&_user;
47fb088e 54
039544ff 55sub AUTOLOAD {
56 my $self = shift;
57
58 ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ );
59
60 return if $method eq "DESTROY";
61
8ba206fe 62 $self->_user->$method;
47fb088e 63}
64
16585083 651;
e8a7c384 66
67__END__
68
69=pod
70
cedb9fb4 71=head1 DESCRIPTION
e8a7c384 72
cedb9fb4 73This object wraps an L<Authen::Htpasswd::User> object. An instance of it will be returned
16585083 74by C<< $c->user >> when using L<Catalyst::Authentication::Store::Htpasswd>. Methods
cedb9fb4 75not defined in this module are passed through to the L<Authen::Htpasswd::User> object. The
76object stringifies to the username.
e8a7c384 77
cedb9fb4 78=head1 METHODS
79
80=head2 new($store,$user)
81
82Creates a new object from a store object, normally an instance of
16585083 83L<Catalyst::Authentication::Store::Htpasswd::Backend>, and a user object,
cedb9fb4 84normally an instance of L<Authen::Htpasswd::User>.
85
86=head2 id
87
88Returns the username.
89
90=head2 check_password($password)
91
92Returns whether the password is valid.
93
94=head2 roles
95
96Returns an array of roles, which is extracted from a comma-separated list in the
97third field of the htpasswd file.
98
16585083 99=head2 for_session
100
101Returns the username, which is then stored in the session.
102
103=head2 supported_features
104
105Returns data about which featurs this user module supports.
106
8ba206fe 107=head2 get_object
108
109Returns the underlieing L<Authen::Htpasswd::User> object for this user
110
e8a7c384 111=cut