line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::DisableForm; |
2
|
6
|
|
|
6
|
|
156198
|
use strict; |
|
6
|
|
|
|
|
15
|
|
|
6
|
|
|
|
|
236
|
|
3
|
6
|
|
|
6
|
|
33
|
use warnings; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
317
|
|
4
|
6
|
|
|
6
|
|
33
|
use base qw/HTML::Parser/; |
|
6
|
|
|
|
|
16
|
|
|
6
|
|
|
|
|
6355
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = 0.01; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
my %can_disable = ( |
9
|
|
|
|
|
|
|
input => 1, |
10
|
|
|
|
|
|
|
textarea => 1, |
11
|
|
|
|
|
|
|
select => 1, |
12
|
|
|
|
|
|
|
); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
5
|
|
|
5
|
1
|
92
|
my $class = shift; |
16
|
5
|
|
|
|
|
54
|
my $self = $class->SUPER::new(api_version => 3); |
17
|
5
|
|
|
|
|
321
|
$self->handler(start => \&_handle_start, "self, tagname, attr, text"); |
18
|
5
|
|
|
|
|
29
|
$self->handler(end => \&_handle_end, "self, tagname, text"); |
19
|
5
|
|
|
|
|
27
|
$self->handler(default => \&_handle_default, "self, text"); |
20
|
5
|
|
|
|
|
31
|
$self->attr_encoded(1); |
21
|
5
|
|
|
|
|
16
|
bless $self, $class; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub readonly_form { |
25
|
1
|
|
|
1
|
1
|
7
|
my ($self, %option) = @_; |
26
|
1
|
|
|
|
|
5
|
$self->disable_form(%option, readonly => 1); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub disable_form { |
30
|
5
|
|
|
5
|
1
|
1008
|
my ($self, %option) = @_; |
31
|
5
|
100
|
|
|
|
26
|
$self->{target} = $option{target} if $option{target}; |
32
|
5
|
100
|
|
|
|
24
|
$self->{readonly} = 1 if $option{readonly}; |
33
|
5
|
|
|
|
|
32
|
$self->_set_options_map($_, $option{$_}) for qw/ignore_fields ignore_forms/; |
34
|
5
|
|
|
|
|
37
|
$self->_parse(%option); |
35
|
5
|
|
|
|
|
41
|
delete $self->{output}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub _set_options_map { |
39
|
10
|
|
|
10
|
|
27
|
my ($self, $name, $value) = @_; |
40
|
10
|
100
|
|
|
|
59
|
return unless defined $value; |
41
|
2
|
100
|
|
|
|
14
|
my %options_map = map { $_ => 1 } ref $value eq 'ARRAY' ? @$value : $value; |
|
3
|
|
|
|
|
21
|
|
42
|
2
|
|
|
|
|
20
|
$self->{$name} = \%options_map; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub _parse { |
46
|
5
|
|
|
5
|
|
10
|
my $self = shift; |
47
|
5
|
|
|
|
|
13
|
my %option = @_; |
48
|
5
|
50
|
|
|
|
31
|
if (my $file = $option{file}){ |
|
|
50
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
49
|
0
|
|
|
|
|
0
|
$self->parse_file($file); |
50
|
|
|
|
|
|
|
} elsif (my $scalarref = $option{scalarref}){ |
51
|
5
|
|
|
|
|
93
|
$self->parse($$scalarref); |
52
|
|
|
|
|
|
|
} elsif (my $arrayref = $option{arrayref}){ |
53
|
0
|
|
|
|
|
0
|
$self->parse($_) for @$arrayref; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub _can_disable { |
58
|
57
|
|
|
57
|
|
75
|
my ($self, $tagname, $attr) = @_; |
59
|
57
|
100
|
|
|
|
157
|
$can_disable{$tagname} or return; |
60
|
24
|
100
|
100
|
|
|
98
|
return 0 if defined $self->{target} && !$self->{current_form}; |
61
|
21
|
100
|
|
|
|
50
|
if (my $current_form = $self->{current_form}) { |
62
|
9
|
100
|
|
|
|
18
|
if (defined $self->{target}) { |
63
|
6
|
100
|
|
|
|
20
|
$current_form eq $self->{target} ? return 1 : return 0; |
64
|
|
|
|
|
|
|
} |
65
|
3
|
50
|
|
|
|
13
|
return 0 if $self->{ignore_forms}->{$current_form}; |
66
|
|
|
|
|
|
|
} |
67
|
12
|
50
|
|
|
|
43
|
if ($attr->{name}) { |
68
|
12
|
100
|
|
|
|
47
|
return 0 if $self->{ignore_fields}->{$attr->{name}}; |
69
|
|
|
|
|
|
|
} |
70
|
10
|
|
|
|
|
31
|
return 1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _handle_start { |
74
|
57
|
|
|
57
|
|
96
|
my ($self, $tagname, $attr, $text) = @_; |
75
|
57
|
100
|
100
|
|
|
224
|
$self->{current_form} = $attr->{name} || $attr->{id} || '' |
76
|
|
|
|
|
|
|
if $tagname eq 'form'; |
77
|
|
|
|
|
|
|
|
78
|
57
|
100
|
|
|
|
120
|
if ($self->_can_disable($tagname, $attr)) { |
79
|
13
|
|
|
|
|
29
|
$self->{output} .= "<$tagname"; |
80
|
13
|
|
|
|
|
76
|
while (my ($key, $value) = each %$attr) { |
81
|
35
|
100
|
|
|
|
110
|
next if $key eq '/'; |
82
|
26
|
|
|
|
|
130
|
$self->{output} .= sprintf qq( %s="%s"), $key, $value; |
83
|
|
|
|
|
|
|
} |
84
|
13
|
100
|
|
|
|
35
|
$self->{output} .= $self->{readonly} ? ' readonly="readonly"' : ' disabled="disabled"'; |
85
|
13
|
100
|
|
|
|
39
|
$self->{output} .= ' /' if $attr->{'/'}; |
86
|
13
|
|
|
|
|
72
|
$self->{output} .= '>'; |
87
|
|
|
|
|
|
|
} else { |
88
|
44
|
|
|
|
|
201
|
$self->{output} .= $text; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub _handle_end { |
93
|
41
|
|
|
41
|
|
59
|
my ($self, $tagname, $text) = @_; |
94
|
41
|
100
|
66
|
|
|
140
|
delete $self->{current_form} |
95
|
|
|
|
|
|
|
if $tagname eq 'form' and exists $self->{current_form}; |
96
|
41
|
|
|
|
|
147
|
$self->{output} .= $text; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub _handle_default { |
100
|
80
|
|
|
80
|
|
107
|
my ($self, $text) = @_; |
101
|
80
|
|
|
|
|
433
|
$self->{output} .= $text; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
1; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
__END__ |