File Coverage

blib/lib/Catalyst/Plugin/Authentication/Store/UserXML/Folder.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Catalyst::Plugin::Authentication::Store::UserXML::Folder;
2              
3 1     1   637 use strict;
  1         1  
  1         31  
4 1     1   4 use warnings;
  1         1  
  1         39  
5              
6             our $VERSION = '0.02';
7              
8 1     1   239 use Moose;
  0            
  0            
9             use Catalyst::Plugin::Authentication::Store::UserXML::User;
10             use Path::Class 'file';
11              
12             has 'folder' => (is=>'rw', isa=>'Path::Class::Dir', required => 1);
13             has 'user_folder_file' => (is=>'rw', isa=>'Str', predicate => 'has_user_folder_file');
14              
15             sub find_user {
16             my ( $self, $authinfo, $c ) = @_;
17              
18             my $username = $authinfo->{username};
19             my $file = (
20             $self->has_user_folder_file
21             ? file($self->folder, $username, $self->user_folder_file)
22             : file($self->folder, $username.'.xml')
23             );
24             return undef unless -r $file;
25              
26             my $user = Catalyst::Plugin::Authentication::Store::UserXML::User->new({
27             xml_filename => $file
28             });
29              
30             die 'username in '.$file.' missmatch'
31             if $user->username ne $username;
32              
33             return $user;
34             }
35              
36             sub user_supports {
37             my $self = shift;
38             Catalyst::Plugin::Authentication::Store::UserXML::User->supports(@_);
39             }
40              
41             sub from_session {
42             my ( $self, $c, $username ) = @_;
43             $self->find_user( { username => $username }, $c );
44             }
45              
46             1;
47