line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Rose::HTML::Form::Field::Email; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
126731
|
use strict; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
129
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
1281
|
use Email::Valid; |
|
3
|
|
|
|
|
192780
|
|
|
3
|
|
|
|
|
662
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
543
|
use Rose::HTML::Object::Errors qw(:email); |
|
3
|
|
|
|
|
22
|
|
|
3
|
|
|
|
|
107
|
|
8
|
|
|
|
|
|
|
|
9
|
3
|
|
|
3
|
|
42
|
use base 'Rose::HTML::Form::Field::Text'; |
|
3
|
|
|
|
|
18
|
|
|
3
|
|
|
|
|
1291
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our $VERSION = '0.606'; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub validate |
14
|
|
|
|
|
|
|
{ |
15
|
10
|
|
|
10
|
1
|
24
|
my($self) = shift; |
16
|
|
|
|
|
|
|
|
17
|
10
|
|
|
|
|
65
|
my $ok = $self->SUPER::validate(@_); |
18
|
10
|
100
|
|
|
|
37
|
return $ok unless($ok); |
19
|
|
|
|
|
|
|
|
20
|
8
|
|
|
|
|
29
|
my $value = $self->internal_value; |
21
|
8
|
50
|
|
|
|
28
|
return 1 unless(length $value); |
22
|
|
|
|
|
|
|
|
23
|
8
|
|
|
|
|
55
|
$ok = Email::Valid->address($value); |
24
|
|
|
|
|
|
|
|
25
|
8
|
100
|
|
|
|
5880
|
unless($ok) |
26
|
|
|
|
|
|
|
{ |
27
|
3
|
|
|
|
|
17
|
$self->add_error_id(EMAIL_INVALID); |
28
|
3
|
|
|
|
|
24
|
return 0; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
5
|
|
|
|
|
25
|
return 1; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
if(__PACKAGE__->localizer->auto_load_messages) |
35
|
|
|
|
|
|
|
{ |
36
|
|
|
|
|
|
|
__PACKAGE__->localizer->load_all_messages; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
3
|
|
|
3
|
|
36
|
use utf8; # The __DATA__ section contains UTF-8 text |
|
3
|
|
|
|
|
20
|
|
|
3
|
|
|
|
|
78
|
|
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
__DATA__ |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
[% LOCALE en %] |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
EMAIL_INVALID = "Invalid email address." |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
[% LOCALE de %] |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# oder "Ungültige Email." |
52
|
|
|
|
|
|
|
EMAIL_INVALID = "Ungültige Email-Adresse." |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
[% LOCALE fr %] |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
EMAIL_INVALID = "Adresse e-mail invalide." |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
[% LOCALE bg %] |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
EMAIL_INVALID = "Невалиден email адрес." |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
__END__ |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 NAME |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Rose::HTML::Form::Field::Email - Text field that only accepts valid email addresses. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head1 SYNOPSIS |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
$field = |
71
|
|
|
|
|
|
|
Rose::HTML::Form::Field::Email->new( |
72
|
|
|
|
|
|
|
label => 'Email', |
73
|
|
|
|
|
|
|
name => 'email', |
74
|
|
|
|
|
|
|
size => 30, |
75
|
|
|
|
|
|
|
maxlength => 255); |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
if($field->validate) |
78
|
|
|
|
|
|
|
{ |
79
|
|
|
|
|
|
|
$email = $field->internal_value; |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
else |
82
|
|
|
|
|
|
|
{ |
83
|
|
|
|
|
|
|
# Handle invalid email addresses |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
print $field->html; |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
... |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 DESCRIPTION |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
L<Rose::HTML::Form::Field::Email> is a subclass of L<Rose::HTML::Form::Field::Text> that uses L<Email::Valid> to allow only valid email addresses as input. It overrides the L<validate()|Rose::HTML::Form::Field/validate> method of its parent class, returning true if the L<internal_value()|Rose::HTML::Form::Field/internal_value> is a valid email address, or setting an error message and returning false otherwise. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
This is a good example of a custom field class that simply constrains the kinds of inputs that it accepts, but does not inflate/deflate values or aggregate other fields. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SEE ALSO |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Other examples of custom fields: |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=over 4 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item L<Rose::HTML::Form::Field::Time> |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Uses inflate/deflate to coerce input into a fixed format. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=item L<Rose::HTML::Form::Field::DateTime> |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Uses inflate/deflate to convert input to a L<DateTime> object. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item L<Rose::HTML::Form::Field::DateTime::Range> |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
A compound field whose internal value consists of more than one object. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item L<Rose::HTML::Form::Field::PhoneNumber::US::Split> |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
A simple compound field that coalesces multiple subfields into a single value. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item L<Rose::HTML::Form::Field::DateTime::Split::MonthDayYear> |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
A compound field that uses inflate/deflate convert input from multiple subfields into a L<DateTime> object. |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item L<Rose::HTML::Form::Field::DateTime::Split::MDYHMS> |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
A compound field that includes other compound fields and uses inflate/deflate convert input from multiple subfields into a L<DateTime> object. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 AUTHOR |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
John C. Siracusa (siracusa@gmail.com) |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 LICENSE |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Copyright (c) 2010 by John C. Siracusa. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |