implement id() in Auth::Store::Htpasswd and change other methods to use it
[catagits/Catalyst-Authentication-Store-Htpasswd.git] / lib / Catalyst / Plugin / Authentication / Store / Htpasswd / User.pm
1 #!/usr/bin/perl
2
3 package Catalyst::Plugin::Authentication::Store::Htpasswd::User;
4 use base qw/Catalyst::Plugin::Authentication::User Class::Accessor::Fast/;
5
6 use strict;
7 use warnings;
8
9 BEGIN { __PACKAGE__->mk_accessors(qw/user store/) }
10
11 use overload '""' => sub { shift->id }, fallback => 1;
12
13 sub new {
14         my ( $class, $store, $user ) = @_;
15
16         bless { store => $store, user => $user }, $class;
17 }
18
19 sub id {
20     my $self = shift;
21     return $self->user->username;
22 }
23
24 sub supported_features {
25         return {
26                 password => {
27                         self_check => 1,
28                 },
29                 session => 1
30         };
31 }
32
33 sub check_password {
34         my ( $self, $password ) = @_;
35         return $self->user->check_password( $password );
36 }
37
38 sub roles {
39         my $self = shift;
40         split( /,/, $self->user->extra_info );
41 }
42
43 sub for_session {
44     my $self = shift;
45     return $self->id;
46 }
47
48 sub AUTOLOAD {
49         my $self = shift;
50         
51         ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ );
52
53         return if $method eq "DESTROY";
54         
55         $self->user->$method;
56 }
57
58 __PACKAGE__;
59
60 __END__
61
62 =pod
63
64 =head1 NAME
65
66 Catalyst::Plugin::Authentication::Store::Htpasswd::User - A user object
67 representing an entry in an htpasswd file.
68
69 =head1 SYNOPSIS
70
71         use Catalyst::Plugin::Authentication::Store::Htpasswd::User;
72
73 =head1 DESCRIPTION
74
75 =cut
76
77