line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::FormHandler::Field::Email; |
2
|
|
|
|
|
|
|
# ABSTRACT: validates email using Email::Valid |
3
|
|
|
|
|
|
|
$HTML::FormHandler::Field::Email::VERSION = '0.40068'; |
4
|
4
|
|
|
4
|
|
3392
|
use HTML::FormHandler::Moose; |
|
4
|
|
|
|
|
11
|
|
|
4
|
|
|
|
|
37
|
|
5
|
|
|
|
|
|
|
extends 'HTML::FormHandler::Field::Text'; |
6
|
4
|
|
|
4
|
|
12951
|
use Email::Valid; |
|
4
|
|
|
|
|
353791
|
|
|
4
|
|
|
|
|
1163
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $class_messages = { |
9
|
|
|
|
|
|
|
'email_format' => 'Email should be of the format [_1]', |
10
|
|
|
|
|
|
|
}; |
11
|
|
|
|
|
|
|
has '+html5_type_attr' => ( default => 'email' ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'email_valid_params' => ( |
14
|
|
|
|
|
|
|
is => 'rw', |
15
|
|
|
|
|
|
|
isa => 'HashRef', |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'preserve_case' => ( |
19
|
|
|
|
|
|
|
is => 'rw', |
20
|
|
|
|
|
|
|
isa => 'Bool', |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub get_class_messages { |
24
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
25
|
|
|
|
|
|
|
return { |
26
|
0
|
|
|
|
|
|
%{ $self->next::method }, |
|
0
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
%$class_messages, |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
apply( |
32
|
|
|
|
|
|
|
[ |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
transform => sub { |
35
|
|
|
|
|
|
|
my ( $value, $field ) = @_; |
36
|
|
|
|
|
|
|
return $value |
37
|
|
|
|
|
|
|
if $field->preserve_case; |
38
|
|
|
|
|
|
|
return lc( $value ); |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
}, |
41
|
|
|
|
|
|
|
{ |
42
|
|
|
|
|
|
|
check => sub { |
43
|
|
|
|
|
|
|
my ( $value, $field ) = @_; |
44
|
|
|
|
|
|
|
my $checked = Email::Valid->address( |
45
|
|
|
|
|
|
|
%{ $field->email_valid_params || {} }, |
46
|
|
|
|
|
|
|
-address => $value, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
$field->value($checked) |
49
|
|
|
|
|
|
|
if $checked; |
50
|
|
|
|
|
|
|
}, |
51
|
|
|
|
|
|
|
message => sub { |
52
|
|
|
|
|
|
|
my ( $value, $field ) = @_; |
53
|
|
|
|
|
|
|
return [$field->get_message('email_format'), 'someuser@example.com']; |
54
|
|
|
|
|
|
|
}, |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
] |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
61
|
4
|
|
|
4
|
|
57
|
use namespace::autoclean; |
|
4
|
|
|
|
|
13
|
|
|
4
|
|
|
|
|
69
|
|
62
|
|
|
|
|
|
|
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.40068 |
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 |