File Coverage

blib/lib/KiokuX/User/Password.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 22 22 100.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package KiokuX::User::Password;
4 2     2   1048 use MooseX::Role::Parameterized;
  2         7  
  2         22  
5              
6 2     2   20316 use MooseX::Types::Authen::Passphrase qw(Passphrase);
  2         174435  
  2         12  
7              
8 2     2   2077 use KiokuX::User::Util qw(crypt_password);
  2         4  
  2         16  
9              
10 2     2   431 use namespace::clean -except => 'meta';
  2         6  
  2         19  
11              
12             parameter password_attribute => (
13             isa => 'Str',
14             default => 'password',
15             );
16              
17             role {
18             my ($p) = @_;
19             my $pw_attr = $p->password_attribute;
20              
21             has $pw_attr => (
22             isa => Passphrase,
23             is => 'rw',
24             coerce => 1,
25             required => 1,
26             #handles => { check_password => "match" },
27             );
28              
29             method check_password => sub {
30 12     12   3178 my $self = shift;
31 12         441 $self->$pw_attr->match(@_);
32             };
33              
34             method set_password => sub {
35 2     2   155997 my ( $self, @args ) = @_;
36 2         14 $self->$pw_attr( crypt_password(@args) );
37             };
38             };
39              
40             __PACKAGE__
41              
42             __END__
43              
44             =pod
45              
46             =head1 NAME
47              
48             KiokuX::User::Password - A role for users with a password attribute
49              
50             =head1 SYNOPSIS
51              
52             with qw(KiokuX::User::Password);
53              
54             =head1 DESCRIPTION
55              
56             This is a simple role for user objects that can check their own password.
57              
58             =head1 METHODS
59              
60             =over 4
61              
62             =item check_password
63              
64             Delegates to the L<Authen::Passphrase/match>.
65              
66             =back
67              
68             =head1 ATTRIBUTES
69              
70             =over 4
71              
72             =item password
73              
74             Uses L<MooseX::Types::Authen::Passphrase> to provide coercions.
75              
76             This is a required, read-write attribute.
77              
78             =back
79              
80             =cut
81              
82             # ex: set sw=4 et:
83