File Coverage

blib/lib/HTML/Widget/JavaScript/Constraint/Email.pm
Criterion Covered Total %
statement 9 9 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 12 12 100.0


line stmt bran cond sub pod time code
1             package HTML::Widget::JavaScript::Constraint::Email;
2            
3 1     1   139303 use warnings;
  1         2  
  1         37  
4 1     1   7 use strict;
  1         2  
  1         38  
5            
6 1     1   6 use base 'HTML::Widget::Constraint::Email';
  1         2  
  1         688  
7            
8             =head1 NAME
9            
10             HTML::Widget::JavaScript::Constraint::Email - JavaScript Email Constraint
11            
12             =head1 VERSION
13            
14             Version 0.02
15            
16             =cut
17            
18             our $VERSION = '0.02';
19            
20             =head1 SYNOPSIS
21            
22             JavaScript Email Constraint.
23            
24             Note: this is a simplified check, since L check is just too long
25             to be used in JavaScript.
26            
27             =head1 METHODS
28            
29             See L.
30            
31             =head2 $self->emit_javascript($var_name)
32            
33             Emits this constraint's JavaScript validation code.
34            
35             =cut
36            
37             sub emit_javascript {
38             my ($self, $var_name) = @_;
39            
40             my @js_constraints;
41            
42             my $not = $self->not ? '' : '!';
43            
44             for my $param (@{$self->names}) {
45             push(@js_constraints, qq[ (${var_name}.${param}.value != '' && $not /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+\$/.test(${var_name}.${param}.value)) ]);
46             }
47            
48             return @js_constraints;
49             }
50            
51             =head1 AUTHOR
52            
53             Nilson Santos Figueiredo Júnior, C<< >>
54            
55             =head1 BUGS
56            
57             Please report any bugs or feature requests directly to the author.
58             If you ask nicely it will probably get fixed or implemented.
59            
60             =head1 COPYRIGHT & LICENSE
61            
62             Copyright 2006, 2009 Nilson Santos Figueiredo Júnior, all rights reserved.
63            
64             This program is free software; you can redistribute it and/or modify it
65             under the same terms as Perl itself.
66            
67             =cut
68            
69             1; # End of HTML::Widget::JavaScript::Constraint