| 1 | package HTML::FormHandler::Field::PasswordConf; | ||||||||||||
| 2 | # ABSTRACT: password confirmation | ||||||||||||
| 3 | 3 | $HTML::FormHandler::Field::PasswordConf::VERSION = '0.410000'; | |||||||||||
| 4 | 3 | ▶ | use HTML::FormHandler::Moose; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 3 | extends 'HTML::FormHandler::Field::Text'; | |||||||||||
| 6 | |||||||||||||
| 7 | |||||||||||||
| 8 | 3 | has '+widget' => ( default => 'Password' ); | |||||||||||
| 9 | 3 | has '+password' => ( default => 1 ); | |||||||||||
| 10 | 3 | has '+required' => ( default => 1 ); | |||||||||||
| 11 | 3 | has 'password_field' => ( isa => 'Str', is => 'rw', default => 'password' ); | |||||||||||
| 12 | 3 | has 'pass_conf_message' => ( isa => 'Str', is => 'rw' ); | |||||||||||
| 13 | |||||||||||||
| 14 | 3 | 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 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
get_class_messages: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||
| 21 | my $messages = { | ||||||||||||
| 22 | 2 | %{ $self->next::method }, | |||||||||||
| 23 | %$class_messages, | ||||||||||||
| 24 | }; | ||||||||||||
| 25 | 2 | ▶ | $messages->{pass_conf_not_matched} = $self->pass_conf_message | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 26 | if $self->pass_conf_message; | ||||||||||||
| 27 | 2 | return $messages; | |||||||||||
| 28 | } | ||||||||||||
| 29 | |||||||||||||
| 30 | |||||||||||||
| 31 | sub validate { | ||||||||||||
| 32 | 3 | ▶ | my $self = shift; | ||||||||||
|
Subroutine
validate: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 33 | |||||||||||||
| 34 | 3 | my $value = $self->value; | |||||||||||
| 35 | 3 | ▶ | my $password = $self->form->field( $self->password_field )->value || ''; | ||||||||||
|
Condition100%2/2
$self->form->field($self->password_field)->value || ''
MC/DC100%1/1
$self->form->field($self->password_field)->value || ''
$self->form->field($self->password_field)->value
Truth table100%2/2
A
A= $self->form->field($self->password_field)->value
| |||||||||||||
| 36 | 3 | ▶ | if ( $password ne $self->value ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 37 | 2 | $self->add_error( $self->get_message('pass_conf_not_matched') ); | |||||||||||
| 38 | 2 | return; | |||||||||||
| 39 | } | ||||||||||||
| 40 | 1 | return 1; | |||||||||||
| 41 | } | ||||||||||||
| 42 | |||||||||||||
| 43 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||||
| 44 | 3 | ▶ | use namespace::autoclean; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 45 | 3 | 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.410000 | ||||||||||||
| 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 | ||||||||||||