line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::FormValidator::Util::HTML; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
21389
|
use 5.005; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
61
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
7
|
|
|
|
|
|
|
require HTML::TokeParser::Simple; |
8
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION @ISA @EXPORT); |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
113
|
|
9
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
12
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
13
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
@EXPORT = qw(add_error_tokens); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$VERSION = '0.10'; |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
20
|
1
|
|
|
1
|
|
864
|
use HTML::TokeParser::Simple; |
|
1
|
|
|
|
|
23506
|
|
|
1
|
|
|
|
|
34
|
|
21
|
1
|
|
|
1
|
|
950
|
use Params::Validate; |
|
1
|
|
|
|
|
11330
|
|
|
1
|
|
|
|
|
470
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub add_error_tokens { |
24
|
7
|
|
|
7
|
0
|
3434
|
my %styles = ( |
25
|
|
|
|
|
|
|
'ht_comment' => { |
26
|
|
|
|
|
|
|
prepend => ' ', |
28
|
|
|
|
|
|
|
}, |
29
|
|
|
|
|
|
|
'ht_tag' => { |
30
|
|
|
|
|
|
|
prepend => '
|
31
|
|
|
|
|
|
|
append => '"> ', |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
7
|
|
|
|
|
246
|
my %in = validate(@_, { |
36
|
|
|
|
|
|
|
html => { default => *STDIN }, |
37
|
|
|
|
|
|
|
prefix => { default => 'err_' }, |
38
|
|
|
|
|
|
|
style => { default => 'ht_comment' }, |
39
|
|
|
|
|
|
|
prepend => 0, |
40
|
|
|
|
|
|
|
append => 0, |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
7
|
100
|
|
|
|
72
|
defined $styles{$in{style}} or die "unknown style: $in{style}"; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Default to style if none is provided |
47
|
6
|
100
|
|
|
|
26
|
$in{prepend} = $styles{$in{style}}->{prepend} unless defined $in{prepend}; |
48
|
6
|
100
|
|
|
|
22
|
$in{append} = $styles{$in{style}}->{append} unless defined $in{append}; |
49
|
|
|
|
|
|
|
|
50
|
6
|
|
50
|
|
|
29
|
my $p = HTML::TokeParser::Simple->new($in{html}) || |
51
|
|
|
|
|
|
|
die "failed to create HTML::TokeParser::Simple object: $!"; |
52
|
|
|
|
|
|
|
|
53
|
6
|
|
|
|
|
861
|
my $select_name; |
54
|
|
|
|
|
|
|
my $out; |
55
|
6
|
|
|
|
|
21
|
while ( my $token = $p->get_token ) { |
56
|
6
|
50
|
33
|
|
|
413
|
if ( ( $token->is_start_tag( 'input' ) ) && |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
57
|
|
|
|
|
|
|
( $token->return_attr->{type} !~ m/^(button|submit|image)$/i )) { |
58
|
6
|
|
|
|
|
198
|
my $name = $token->return_attr->{name}; |
59
|
6
|
|
|
|
|
88
|
$out .= $token->as_is.qq/$in{prepend}$in{prefix}$name$in{append}/; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
elsif ( $token->is_start_tag( 'select' ) ) { |
62
|
0
|
|
|
|
|
0
|
$select_name = $token->return_attr->{name}; |
63
|
0
|
|
|
|
|
0
|
$out .= $token->as_is; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif ( $token->is_end_tag('select') ) { |
66
|
0
|
|
|
|
|
0
|
$out .= $token->as_is.qq/$in{prepend}$in{prefix}$select_name$in{append}/; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
elsif ( $token->is_start_tag( 'textarea' ) ) { |
69
|
0
|
|
|
|
|
0
|
my $name = $token->return_attr->{name}; |
70
|
0
|
|
|
|
|
0
|
$out .= qq/$in{prepend}$in{prefix}$name$in{append}/.$token->as_is; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
else { |
73
|
0
|
|
|
|
|
0
|
$out .= $token->as_is; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
6
|
|
|
|
|
220
|
return $out; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
1; |
84
|
|
|
|
|
|
|
__END__ |