line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Class::CGI::Email::Valid; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
37164
|
use base 'Class::CGI::Handler'; |
|
2
|
|
|
|
|
151
|
|
|
2
|
|
|
|
|
2320
|
|
4
|
2
|
|
|
2
|
|
1921
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
86
|
|
5
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
9
|
|
|
2
|
|
|
|
|
56
|
|
6
|
2
|
|
|
2
|
|
5436
|
use Email::Valid; |
|
2
|
|
|
|
|
433914
|
|
|
2
|
|
|
|
|
478
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 NAME |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Class::CGI::Email::Valid - Validate email from forms |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 VERSION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Version 0.01 |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=cut |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Class::CGI handlers => { |
23
|
|
|
|
|
|
|
email => 'Class::CGI::Email::Valid', |
24
|
|
|
|
|
|
|
}; |
25
|
|
|
|
|
|
|
my $cgi = Class::CGI->new; |
26
|
|
|
|
|
|
|
my $email = $cgi->param('email'); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
if ( my %error_for = $cgi->errors ) { |
29
|
|
|
|
|
|
|
if ( $error_for{email} ) { |
30
|
|
|
|
|
|
|
... |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Normally we fetch email from forms, run it through C or |
37
|
|
|
|
|
|
|
something similar, untaint it, if necessary, and save it somewhere. This |
38
|
|
|
|
|
|
|
class handles the email validation via C and optionally handles |
39
|
|
|
|
|
|
|
untainting. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Unlike other C handlers, this handler returns the email address |
42
|
|
|
|
|
|
|
unchanged; the C method does not return an object. If the email |
43
|
|
|
|
|
|
|
address failed to validate, the error message will be in the error hash |
44
|
|
|
|
|
|
|
returned by the C method. As usual, the error key will be the name of |
45
|
|
|
|
|
|
|
the param used. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 Basic usage |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
use Class::CGI handlers => { |
50
|
|
|
|
|
|
|
email_address => 'Class::CGI::Email::Valid', |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
my $cgi = Class::CGI->new; |
53
|
|
|
|
|
|
|
my $email = $cgi->param('email_address'); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Any parameter name may be validated as an email address. If the value of the |
56
|
|
|
|
|
|
|
parameter does not appear to be a valid email address, |
57
|
|
|
|
|
|
|
B! This makes it easy to create |
58
|
|
|
|
|
|
|
"sticky" forms. |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head2 Untainting |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
This handler does not provide any untainting facilities. It merely checks |
63
|
|
|
|
|
|
|
that the email address entered validated with C. This is |
64
|
|
|
|
|
|
|
because email addresses often get used in the shell and it is very difficult |
65
|
|
|
|
|
|
|
to ensure that the full range of email addresses allowed are safe for such |
66
|
|
|
|
|
|
|
use. It is the responsibility of the programmer to ensure that a valid email |
67
|
|
|
|
|
|
|
address is safe for such use. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 Overridding the error message |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
If you prefer, you can override the default error message by setting the |
72
|
|
|
|
|
|
|
"error" parameter in the C hash. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
use Class::CGI handlers => { |
75
|
|
|
|
|
|
|
email => 'Class::CGI::Email::Valid', |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
my $cgi = Class::CGI->new; |
78
|
|
|
|
|
|
|
$cgi->args( email => { error => "You gave me a bad email address, dummy!" } ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
my $email = $cgi->param('email'); |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub handle { |
85
|
2
|
|
|
2
|
1
|
2290
|
my $self = shift; |
86
|
2
|
|
|
|
|
5
|
my $cgi = $self->cgi; |
87
|
2
|
|
|
|
|
11
|
my $param = $self->param; |
88
|
2
|
|
|
|
|
12
|
my $email = $cgi->raw_param($param); |
89
|
2
|
|
50
|
|
|
30
|
my $args = $cgi->args($param) || {}; |
90
|
2
|
|
50
|
|
|
36
|
my $error = $args->{error} |
91
|
|
|
|
|
|
|
|| "The email address did not appear to be valid"; |
92
|
2
|
100
|
|
|
|
10
|
unless ( Email::Valid->address($email) ) { |
93
|
1
|
|
|
|
|
117
|
$cgi->add_error( $param, $error ); |
94
|
|
|
|
|
|
|
} |
95
|
2
|
|
|
|
|
2508
|
return $email; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Curtis "Ovid" Poe, C<< >> |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 BUGS |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Please report any bugs or feature requests to |
105
|
|
|
|
|
|
|
C, or through the web interface at |
106
|
|
|
|
|
|
|
L. |
107
|
|
|
|
|
|
|
I will be notified, and then you'll automatically be notified of progress on |
108
|
|
|
|
|
|
|
your bug as I make changes. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Copyright 2006 Curtis "Ovid" Poe, all rights reserved. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
117
|
|
|
|
|
|
|
under the same terms as Perl itself. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=cut |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
1; # End of Class::CGI::Email::Valid |