File Coverage

blib/lib/Data/MuForm/Field/Email.pm
Criterion Covered Total %
statement 17 22 77.2
branch 4 6 66.6
condition n/a
subroutine 6 8 75.0
pod 0 2 0.0
total 27 38 71.0


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