| 1 | package HTML::FormHandler::Field::Email; | ||||||||||
| 2 | # ABSTRACT: validates email using Email::Valid | ||||||||||
| 3 | 4 | $HTML::FormHandler::Field::Email::VERSION = '0.410001'; | |||||||||
| 4 | 4 | ▶ | use HTML::FormHandler::Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | extends 'HTML::FormHandler::Field::Text'; | |||||||||
| 6 | 4 | ▶ | use Email::Valid; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 4 | our $class_messages = { | |||||||||
| 9 | 'email_format' => 'Email should be of the format [_1]', | ||||||||||
| 10 | }; | ||||||||||
| 11 | 4 | has '+html5_type_attr' => ( default => 'email' ); | |||||||||
| 12 | |||||||||||
| 13 | 4 | has 'email_valid_params' => ( | |||||||||
| 14 | is => 'rw', | ||||||||||
| 15 | isa => 'HashRef', | ||||||||||
| 16 | ); | ||||||||||
| 17 | |||||||||||
| 18 | 4 | has 'preserve_case' => ( | |||||||||
| 19 | is => 'rw', | ||||||||||
| 20 | isa => 'Bool', | ||||||||||
| 21 | ); | ||||||||||
| 22 | |||||||||||
| 23 | sub get_class_messages { | ||||||||||
| 24 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_class_messages: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 25 | return { | ||||||||||
| 26 | 0 | %{ $self->next::method }, | |||||||||
| 27 | %$class_messages, | ||||||||||
| 28 | } | ||||||||||
| 29 | } | ||||||||||
| 30 | |||||||||||
| 31 | apply( | ||||||||||
| 32 | [ | ||||||||||
| 33 | { | ||||||||||
| 34 | transform => sub { | ||||||||||
| 35 | 5 | ▶ | my ( $value, $field ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 36 | 5 | ▶ | return $value | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | if $field->preserve_case; | ||||||||||
| 38 | 3 | return lc( $value ); | |||||||||
| 39 | } | ||||||||||
| 40 | }, | ||||||||||
| 41 | { | ||||||||||
| 42 | check => sub { | ||||||||||
| 43 | 5 | ▶ | my ( $value, $field ) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||
| 44 | my $checked = Email::Valid->address( | ||||||||||
| 45 | 5 | ▶ | %{ $field->email_valid_params || {} }, | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | -address => $value, | ||||||||||
| 47 | ); | ||||||||||
| 48 | 5 | ▶ | $field->value($checked) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | if $checked; | ||||||||||
| 50 | }, | ||||||||||
| 51 | message => sub { | ||||||||||
| 52 | 0 | ▶ | my ( $value, $field ) = @_; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 53 | 0 | return [$field->get_message('email_format'), 'someuser@example.com']; | |||||||||
| 54 | }, | ||||||||||
| 55 | } | ||||||||||
| 56 | 4 | ] | |||||||||
| 57 | ); | ||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 61 | 4 | ▶ | use namespace::autoclean; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 62 | 4 | 1; | |||||||||
| 63 | |||||||||||
| 64 | __END__ | ||||||||||
| 65 | |||||||||||
| 66 | =pod | ||||||||||
| 67 | |||||||||||
| 68 | =encoding UTF-8 | ||||||||||
| 69 | |||||||||||
| 70 | =head1 NAME | ||||||||||
| 71 | |||||||||||
| 72 | HTML::FormHandler::Field::Email - validates email using Email::Valid | ||||||||||
| 73 | |||||||||||
| 74 | =head1 VERSION | ||||||||||
| 75 | |||||||||||
| 76 | version 0.410001 | ||||||||||
| 77 | |||||||||||
| 78 | =head1 DESCRIPTION | ||||||||||
| 79 | |||||||||||
| 80 | Validates that the input looks like an email address using L<Email::Valid>. | ||||||||||
| 81 | Widget type is 'text'. | ||||||||||
| 82 | |||||||||||
| 83 | If form has 'is_html5' flag active it will render <input type="email" ... /> | ||||||||||
| 84 | instead of type="text" | ||||||||||
| 85 | |||||||||||
| 86 | This field has an 'email_valid_params' attribute that accepts a hash | ||||||||||
| 87 | reference of extra values passed to L<Email::Valid/address> when | ||||||||||
| 88 | validating email addresses. | ||||||||||
| 89 | |||||||||||
| 90 | If you want to preserve the case of the email address, set the | ||||||||||
| 91 | 'preserve_case' attribute. | ||||||||||
| 92 | |||||||||||
| 93 | =head1 DEPENDENCIES | ||||||||||
| 94 | |||||||||||
| 95 | L<Email::Valid> | ||||||||||
| 96 | |||||||||||
| 97 | =head1 AUTHOR | ||||||||||
| 98 | |||||||||||
| 99 | FormHandler Contributors - see HTML::FormHandler | ||||||||||
| 100 | |||||||||||
| 101 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 102 | |||||||||||
| 103 | This software is copyright (c) 2017 by Gerda Shank. | ||||||||||
| 104 | |||||||||||
| 105 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 106 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 107 | |||||||||||
| 108 | =cut | ||||||||||