File Coverage

blib/lib/HTML/FormHandler/Field/PasswordConf.pm
Criterion Covered Total %
statement 18 18 100.0
branch 3 4 75.0
condition 2 2 100.0
subroutine 4 4 100.0
pod 1 2 50.0
total 28 30 93.3


line stmt bran cond sub pod time code
1             package HTML::FormHandler::Field::PasswordConf;
2             # ABSTRACT: password confirmation
3             $HTML::FormHandler::Field::PasswordConf::VERSION = '0.40068';
4 3     3   2826 use HTML::FormHandler::Moose;
  3         11  
  3         38  
5             extends 'HTML::FormHandler::Field::Text';
6              
7              
8             has '+widget' => ( default => 'Password' );
9             has '+password' => ( default => 1 );
10             has '+required' => ( default => 1 );
11             has 'password_field' => ( isa => 'Str', is => 'rw', default => 'password' );
12             has 'pass_conf_message' => ( isa => 'Str', is => 'rw' );
13              
14             our $class_messages = {
15             required => 'Please enter a password confirmation',
16             pass_conf_not_matched => 'The password confirmation does not match the password',
17             };
18              
19             sub get_class_messages {
20 2     2 0 5 my $self = shift;
21             my $messages = {
22 2         6 %{ $self->next::method },
  2         12  
23             %$class_messages,
24             };
25 2 50       78 $messages->{pass_conf_not_matched} = $self->pass_conf_message
26             if $self->pass_conf_message;
27 2         18 return $messages;
28             }
29              
30              
31             sub validate {
32 3     3 1 7 my $self = shift;
33              
34 3         13 my $value = $self->value;
35 3   100     73 my $password = $self->form->field( $self->password_field )->value || '';
36 3 100       18 if ( $password ne $self->value ) {
37 2         15 $self->add_error( $self->get_message('pass_conf_not_matched') );
38 2         7 return;
39             }
40 1         4 return 1;
41             }
42              
43             __PACKAGE__->meta->make_immutable;
44 3     3   9081 use namespace::autoclean;
  3         7  
  3         32  
45             1;
46              
47             __END__
48              
49             =pod
50              
51             =encoding UTF-8
52              
53             =head1 NAME
54              
55             HTML::FormHandler::Field::PasswordConf - password confirmation
56              
57             =head1 VERSION
58              
59             version 0.40068
60              
61             =head1 DESCRIPTION
62              
63             This field needs to be declared after the related Password field (or more
64             precisely it needs to come after the Password field in the list returned by
65             the L<HTML::FormHandler/fields> method).
66              
67             =head2 password_field
68              
69             Set this attribute to the name of your password field (default 'password')
70              
71             Customize error message 'pass_conf_not_matched' or 'required'
72              
73             has_field '_password' => ( type => 'PasswordConf',
74             messages => { required => 'You must enter the password a second time' },
75             );
76              
77             =head1 AUTHOR
78              
79             FormHandler Contributors - see HTML::FormHandler
80              
81             =head1 COPYRIGHT AND LICENSE
82              
83             This software is copyright (c) 2017 by Gerda Shank.
84              
85             This is free software; you can redistribute it and/or modify it under
86             the same terms as the Perl 5 programming language system itself.
87              
88             =cut