DOM/Element/Form.pm

filter: Statementstmt 95.2% 600 / 630 Branchbran 80.7% 247 / 306 Conditioncond 70.5% 110 / 156 MC/DCmcdc 41.1% 37 / 90 Subroutinesub 94.8% 129 / 136 Podpod 60.0% 12 / 20 totaltotal 84.8% 1135 / 1338 SCAR 58.5
CC
240
Cov
88%
find_input
37.1
param
21.1
HTML_Form_FileInput_form_name_value
19.9
CRAP 348.8
« DOM/_TreeBuilder.pm ↑ Summary DOM.pm »
1 package HTML::DOM::Element::Form;
2  
3 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 25 ▶no Carp();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 25 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 25 require HTML::DOM::Element;
10 25 require HTML::DOM::NodeList::Magic;
11 #require HTML::DOM::Collection::Elements;
12  
13 25 our $VERSION = '0.057';
14 25 our @ISA = qw'HTML::DOM::Element';
15  
16 use overload fallback => 1,
17 0 ▶'@{}' => sub { shift->elements },
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 '%{}' => sub {
19 5008 ▶ my $self = shift;
Subroutine __ANON__: called CC=3 SCAR=11.0
20 5008 ▶ $self->isa(scalar caller) || caller->isa('HTML::DOM::_TreeBuilder')
Branch: 1 branch
BranchTrueFalseTotal
$self->isa(scalar caller) || (caller)->isa("HTML::DOM::_TreeBuilder") and return $self 4985 23 5008
Condition100%3/3
$self->isa(scalar caller) or (caller)->isa("HTML::DOM::_TreeBuilder")
l!l&&r!l&&!r
430368223
MC/DC100%2/2
$self->isa(scalar caller) or (caller)->isa("HTML::DOM::_TreeBuilder")
$self->isa(scalar caller) (caller)->isa("HTML::DOM::_TreeBuilder")
Truth table100%3/3
A or B
A= $self->isa(scalar caller)B= (caller)->isa("HTML::DOM::_TreeBuilder")
ABresult
1X1
011
000
21 and return $self;
22 23 $self->elements;
23 25 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 25 my %elem_elems = (
26 input => 1,
27 button => 1,
28 select => 1,
29 textarea => 1,
30 );
31 sub elements {
32 56 ▶ my $self = shift;
Subroutine elements: called CC=3 SCAR=11.0
Pod documented
33 56 ▶ my $collection = $self->{_HTML_DOM_elems} ||= do {
Condition66%2/3
$self->{"_HTML_DOM_elems"} ||= do { my $collection = "HTML::DOM::Collection::Elements"->new(my $list = "HTML::DOM::NodeList::Magic"->new(sub { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} grep(($elem_elems{$_->tag} && $_->attr("type") ne "image"), $self->descendants), @{$self->{"_HTML_DOM_mg_elems"} or [];}; } )); $self->ownerDocument->_register_magic_node_list($list); $collection }
l!l&&r!l&&!r
42140
MC/DC0%0/2
$self->{"_HTML_DOM_elems"} ||= do { my $collection = "HTML::DOM::Collection::Elements"->new(my $list = "HTML::DOM::NodeList::Magic"->new(sub { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} grep(($elem_elems{$_->tag} && $_->attr("type") ne "image"), $self->descendants), @{$self->{"_HTML_DOM_mg_elems"} or [];}; } )); $self->ownerDocument->_register_magic_node_list($list); $collection }
$self->{"_HTML_DOM_elems"} do { my $collection = "HTML::DOM::Collection::Elements"->new(my $list = "HTML::DOM::NodeList::Magic"->new(sub { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} grep(($elem_elems{$_->tag} && $_->attr("type") ne "image"), $self->descendants), @{$self->{"_HTML_DOM_mg_elems"} or [];}; } )); $self->ownerDocument->_register_magic_node_list($list); $collection }
Truth table66%2/3
A ||= B
A= $self->{"_HTML_DOM_elems"}B= do { my $collection = "HTML::DOM::Collection::Elements"->new(my $list = "HTML::DOM::NodeList::Magic"->new(sub { BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x51\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"} grep(($elem_elems{$_->tag} && $_->attr("type") ne "image"), $self->descendants), @{$self->{"_HTML_DOM_mg_elems"} or [];}; } )); $self->ownerDocument->_register_magic_node_list($list); $collection }
ABresult
1X1
011
000
34 my $collection = HTML::DOM::Collection::Elements->new(
35 my $list = HTML::DOM::NodeList::Magic->new(
36 sub {
37 25 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
38 grep(
39 $elem_elems{tag $_} && attr $_ 'type', ne 'image',
40 $self->descendants
41 ),
42 25 ▶ @{ $self->{_HTML_DOM_mg_elems}||[] }
Subroutine __ANON__: called CC=3 SCAR=11.0
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_HTML_DOM_mg_elems"} or [] 17 8 25
Condition100%3/3
$elem_elems{$_->tag} && $_->attr('type') ne 'image'
!ll&&!rl&&r
105354
MC/DC100%2/2
$elem_elems{$_->tag} && $_->attr('type') ne 'image'
$elem_elems{$_->tag} $_->attr('type') ne 'image'
Truth table100%3/3
A && B
A= $elem_elems{$_->tag}B= $_->attr('type') ne 'image'
ABresult
0X0
100
111
43 }
44 14 ));
45 14 $self->ownerDocument-> _register_magic_node_list($list);
46 14 $collection;
47 };
48 56 weaken $self;
49 56 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 13 43 56
50 13 @$collection
51 }
52 else {
53 43 $collection;
54 }
55 }
56 sub add_element { # helper routine that formies use to add themselves to
57 9 ▶ my $self = shift; # the elements list
Subroutine add_element: called CC=3 SCAR=11.0
Pod undocumented
58 6 ▶ push @{ $self->{_HTML_DOM_mg_elems} ||= [] }, shift
Condition100%2/2
$self->{"_HTML_DOM_mg_elems"} ||= []
l!l
33
MC/DC100%1/1
$self->{"_HTML_DOM_mg_elems"} ||= []
$self->{"_HTML_DOM_mg_elems"}
Truth table100%2/2
A
A= $self->{"_HTML_DOM_mg_elems"}
Aresult
11
00
59 9 ▶ if $elem_elems{ $_[0]->tag };
Branch: 1 branch
BranchTrueFalseTotal
if $elem_elems{$_[0]->tag} 6 3 9
60 9 return;
61 }
62 sub remove_element { # and this is how formies remove themselves when they
63 7 ▶ my $self = shift; # get moved around the DOM
Subroutine remove_element: called CC=2 SCAR=7.0
Pod undocumented
64 7 my $removee = shift;
65 7 @{ $self->{_HTML_DOM_mg_elems} }
66 7 ▶ = grep $_ != $removee, @{ $self->{_HTML_DOM_elems} ||= [] }
Condition50%1/2
$self->{"_HTML_DOM_elems"} ||= []
l!l
70
MC/DC0%0/1
$self->{"_HTML_DOM_elems"} ||= []
$self->{"_HTML_DOM_elems"}
Truth table50%1/2
A
A= $self->{"_HTML_DOM_elems"}
Aresult
11
00
67 }
68  
69 2 ▶sub length { shift->elements -> length }
Subroutine length: called CC=1 SCAR=0.0
Pod documented
70 25 ▶sub name { no warnings; shift->_attr( name => @_) . '' }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine name: called CC=1 SCAR=0.0
Pod documented
71 49 ▶sub acceptCharset { shift->_attr('accept-charset' => @_) }
Subroutine acceptCharset: called CC=1 SCAR=0.0
Pod documented
72 sub action {
73 39 ▶ my $self = shift;
Subroutine action: called CC=2 SCAR=6.9
Pod documented
74 39 ▶ (my $base = $self->ownerDocument->base)
Branch: 1 branch
BranchTrueFalseTotal
my $base = $self->ownerDocument->base or return $self->_attr("action", @_) 22 17 39
75 or return $self->_attr('action', @_);
76 17 (new_abs URI
77 $self->_attr('action' => @_),
78 $self->ownerDocument->base)
79 ->as_string
80 }
81 sub enctype {
82 34 ▶ my $ret = shift->_attr('enctype' => @_);
Subroutine enctype: called CC=2 SCAR=7.2
Pod documented
83 34 ▶ defined $ret ? $ret : 'application/x-www-form-urlencoded'
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 34 0 34
84 }
85 25 *encoding=*enctype;
86 sub method {
87 48 ▶ my $ret = shift->_attr('method' => @_);
Subroutine method: called CC=2 SCAR=7.2
Pod documented
88 48 ▶ defined $ret ? lc $ret : 'get'
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 48 0 48
89 }
90 5 ▶sub target { shift->_attr('target' => @_) }
Subroutine target: called CC=1 SCAR=0.0
Pod documented
91  
92 3 ▶sub submit { shift->trigger_event('submit') }
Subroutine submit: called CC=1 SCAR=0.0
Pod documented
93  
94 sub reset {
95 2 ▶ shift->trigger_event('reset');
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
96 }
97  
98 sub trigger_event {
99 88 ▶ my ($a,$evnt) = (shift,shift);
Subroutine trigger_event: called CC=1 SCAR=0.0
Pod documented
100 $a->SUPER::trigger_event(
101 $evnt,
102 submit_default =>
103 $a->ownerDocument->
104 default_event_handler_for('submit'),
105 reset_default => sub {
106 4 ▶ $_->_reset for shift->target->elements
Subroutine __ANON__: called CC=2 SCAR=6.9
107 },
108 88 @_,
109 );
110 }
111  
112 # ------ HTML::Form compatibility methods ------ #
113  
114 sub inputs {
115 106 ▶ my @ret;
Subroutine inputs: called CC=8 SCAR=20.8
Pod undocumented
116 my %pos;
117 106 my $self = shift;
118 # This used to use ‘$self->elements’, but ->elements no longer
119 # includes image buttons.
120 106 for(
121 grep($elem_elems{tag $_}, $self->descendants),
122 106 ▶ @{ $self->{_HTML_DOM_mg_elems}||[] }
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_HTML_DOM_mg_elems"} or [] 106 0 106
123 ) {
124 #next if (my $tag = tag $_) eq 'button'; # HTML::Form doesn't deal
125 # with <button>s.
126 # NOW IT DOES :)
127 501 my $tag = tag $_;
128  
129 25 ▶ no warnings 'uninitialized'; # for 5.11.0
Subroutine BEGIN: called CC=1 SCAR=0.0
130 501 ▶ if(lc $_->attr('type') eq 'radio') {
Branch: 1 branch
BranchTrueFalseTotal
if (lc $_->attr("type") eq "radio") 104 397 501
131 104 my $name = name $_;
132 59 exists $pos{$name} ? push @{$ret[$pos{$name}]}, $_
133 :( push(@ret, [$_]),
134 104 ▶ $pos{$name} = $#ret );
Branch: 1 branch
BranchTrueFalseTotal
exists $pos{$name} ? : 59 45 104
135 next
136 104 }
137 397 ▶ push @ret, $tag eq 'select'
Branch: 2 branches
BranchTrueFalseTotal
$tag eq 'select' ? : 154 243 397
$_->attr('multiple') ? : 75 79 154
138 ? $_->attr('multiple')
139 ? $_->find('option')
140 : scalar $_->options
141 : $_
142 }
143 106 ▶ map ref $_ eq 'ARRAY' ? new HTML::DOM::NodeList::Radio $_ : $_,
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq 'ARRAY' ? : 45 509 554
144 @ret
145 }
146  
147 sub click # 22/Sep/7: stolen from HTML::Form and modified (particularly
148 { # the last line) so I don't have to mess with Hook::LexWrap
149 12 ▶ my $self = shift;
Subroutine click: called CC=13 SCAR=26.6
Pod documented
150 12 my $name;
151 12 ▶ $name = shift if (@_ % 2) == 1; # odd number of arguments
Branch: 1 branch
BranchTrueFalseTotal
if @_ % 2 == 1 0 12 12
152  
153 # try to find first submit button to activate
154 12 for ($self->inputs) {
155 24 ▶ my $type = $_->type; my $tag = eval { $_->tag } || '';
Condition100%2/2
eval { do { $_->tag } } || ''
l!l
231
MC/DC100%1/1
eval { do { $_->tag } } || ''
eval { do { $_->tag } }
Truth table100%2/2
A
A= eval { do { $_->tag } }
Aresult
11
00
156 24 ▶ next unless $tag eq 'input' && $type =~ /^(?:submit|image)\z/
Branch: 1 branch
BranchTrueFalseTotal
unless $tag eq "input" and $type =~ /^(?:submit|image)\z/ or $tag eq "button" and ($type || "submit") eq "submit" 18 6 24
Condition72%8/11
$tag eq "input" and $type =~ /^(?:submit|image)\z/ or $tag eq "button" and ($type || "submit") eq "submit"
l!l&&r!l&&!r
5190
$tag eq "input" and $type =~ /^(?:submit|image)\z/
!ll&&!rl&&r
3165
$tag eq "button" and ($type || "submit") eq "submit"
!ll&&!rl&&r
1801
$type || 'submit'
l!l
01
MC/DC25%1/4
$tag eq "input" and $type =~ /^(?:submit|image)\z/ or $tag eq "button" and ($type || "submit") eq "submit"
$tag eq "input" $type =~ /^(?:submit|image)\z/ $tag eq "button" $type
Truth table28%2/7
A and B or C and D
A= $tag eq "input"B= $type =~ /^(?:submit|image)\z/C= $tag eq "button"D= $type
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
157 || $tag eq 'button' && ($type || 'submit') eq 'submit';
158 6 ▶ next if $name && $_->name ne $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name and $_->name ne $name 0 6 6
Condition33%1/3
$name and $_->name ne $name
!ll&&!rl&&r
600
MC/DC0%0/2
$name and $_->name ne $name
$name $_->name ne $name
Truth table33%1/3
A and B
A= $nameB= $_->name ne $name
ABresult
0X0
100
111
159 6 ▶ next if $_->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $_->disabled 1 5 6
160 5 $_->click($self, @_);return
161 5 }
162 7 ▶ Carp::croak("No clickable input with name $name") if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 0 7 7
163 7 $self->trigger_event('submit');
164 }
165  
166 # These three were shamelessly stolen from HTML::Form:
167 sub value
168 {
169 package
170 HTML::Form;
171 15 ▶ my $self = shift;
Subroutine value: called CC=2 SCAR=7.0
Pod undocumented
172 15 my $key = shift;
173 15 my $input = $self->find_input($key);
174 15 ▶ Carp::croak("No such field '$key'") unless $input;
Branch: 1 branch
BranchTrueFalseTotal
unless $input 0 15 15
175 15 local $Carp::CarpLevel = 1;
176 15 $input->value(@_);
177 }
178  
179  
180 sub find_input
181 {
182 package
183 HTML::Form; # so caller tricks work
184 31 ▶ my($self, $name, $type, $no) = @_;
Subroutine find_input: called CC=18 SCAR=36.1
Pod undocumented
185 31 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 30 31
186 1 my @res;
187 my $c;
188 1 for ($self->inputs) {
189 2 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 0 2 2
190 0 ▶ next unless defined(my $n = $_->name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $n = $_->name) 0 0 0
191 0 ▶ next if $name ne $n;
Branch: 1 branch
BranchTrueFalseTotal
if $name ne $n 0 0 0
192 }
193 2 ▶ next if $type && $type ne $_->type;
Branch: 1 branch
BranchTrueFalseTotal
if $type and $type ne $_->type 0 2 2
Condition33%1/3
$type and $type ne $_->type
!ll&&!rl&&r
020
MC/DC0%0/2
$type and $type ne $_->type
$type $type ne $_->type
Truth table33%1/3
A and B
A= $typeB= $type ne $_->type
ABresult
0X0
100
111
194 2 $c++;
195 2 ▶ next if $no && $no != $c;
Branch: 1 branch
BranchTrueFalseTotal
if $no and $no != $c 0 2 2
Condition33%1/3
$no and $no != $c
!ll&&!rl&&r
200
MC/DC0%0/2
$no and $no != $c
$no $no != $c
Truth table33%1/3
A and B
A= $noB= $no != $c
ABresult
0X0
100
111
196 2 push(@res, $_);
197 }
198 1 return @res;
199
200 }
201 else {
202 30 ▶ $no ||= 1;
Condition50%1/2
$no ||= 1
l!l
030
MC/DC0%0/1
$no ||= 1
$no
Truth table50%1/2
A
A= $no
Aresult
11
00
203 30 for ($self->inputs) {
204 72 ▶ if (defined $name) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $name) 72 0 72
205 72 ▶ next unless defined(my $n = $_->name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $n = $_->name) 0 72 72
206 72 ▶ next if $name ne $n;
Branch: 1 branch
BranchTrueFalseTotal
if $name ne $n 42 30 72
207 }
208 30 ▶ next if $type && $type ne $_->type;
Branch: 1 branch
BranchTrueFalseTotal
if $type and $type ne $_->type 0 30 30
Condition33%1/3
$type and $type ne $_->type
!ll&&!rl&&r
3000
MC/DC0%0/2
$type and $type ne $_->type
$type $type ne $_->type
Truth table33%1/3
A and B
A= $typeB= $type ne $_->type
ABresult
0X0
100
111
209 30 ▶ next if --$no;
Branch: 1 branch
BranchTrueFalseTotal
if --$no 0 30 30
210 30 return $_;
211 }
212 0 return undef;
213 }
214 }
215  
216 sub param {
217 package
218 HTML::Form;
219 27 ▶ my $self = shift;
Subroutine param: called CC=21 SCAR=30.5
Pod undocumented
220 27 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 25 2 27
221 25 my $name = shift;
222 25 my @inputs;
223 25 for ($self->inputs) {
224 175 my $n = $_->name;
225 175 ▶ next if !defined($n) || $n ne $name;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $n or $n ne $name 132 43 175
Condition66%2/3
not defined $n or $n ne $name
l!l&&r!l&&!r
013243
MC/DC50%1/2
not defined $n or $n ne $name
not defined $n $n ne $name
Truth table66%2/3
not(A) or B
A= not defined $nB= $n ne $name
ABresult
1X1
011
000
226 43 push(@inputs, $_);
227 }
228  
229 25 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) { } 8 17 25
230 # set
231 8 ▶ die "No '$name' parameter exists" unless @inputs;
Branch: 1 branch
BranchTrueFalseTotal
unless @inputs 0 8 8
232 8 my @v = @_;
233 8 ▶ @v = @{$v[0]} if @v == 1 && ref($v[0]);
Branch: 1 branch
BranchTrueFalseTotal
if @v == 1 and ref $v[0] 3 5 8
Condition100%3/3
@v == 1 and ref $v[0]
!ll&&!rl&&r
143
MC/DC100%2/2
@v == 1 and ref $v[0]
@v == 1 ref $v[0]
Truth table100%3/3
A and B
A= @v == 1B= ref $v[0]
ABresult
0X0
100
111
234 8 ▶ while (@v) {
Branch: 1 branch
BranchTrueFalseTotal
if (@v) 8 7 15
235 8 my $v = shift @v;
236 8 my $err;
237 8 for my $i (0 .. @inputs-1) {
238 13 eval {
239 13 $inputs[$i]->value($v);
240 };
241 13 ▶ unless ($@) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($@) 7 6 13
242 7 undef($err);
243 7 splice(@inputs, $i, 1);
244 7 last;
245 }
246 6 ▶ $err ||= $@;
Condition66%2/3
$err ||= $@
l!l&&r!l&&!r
150
MC/DC0%0/2
$err ||= $@
$err $@
Truth table66%2/3
A ||= B
A= $errB= $@
ABresult
1X1
011
000
247 }
248 8 ▶ die $err if $err;
Branch: 1 branch
BranchTrueFalseTotal
if $err 1 7 8
249 }
250  
251 # the rest of the input should be cleared
252 7 for (@inputs) {
253 6 $_->value(undef);
254 }
255 }
256 else {
257 # get
258 17 my @v;
259 17 for (@inputs) {
260 28 ▶ if (defined(my $v = $_->value)) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $v = $_->value)) 16 12 28
261 16 push(@v, $v);
262 }
263 }
264 17 ▶ return wantarray ? @v : $v[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 12 5 17
265 }
266 }
267 else {
268 # list parameter names
269 2 my @n;
270 my %seen;
271 2 for ($self->inputs) {
272 14 my $n = $_->name;
273 14 ▶ next if !defined($n) || $seen{$n}++;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $n or $seen{$n}++ 6 8 14
Condition66%2/3
not defined $n or $seen{$n}++
l!l&&r!l&&!r
068
MC/DC50%1/2
not defined $n or $seen{$n}++
not defined $n $seen{$n}++
Truth table66%2/3
not(A) or B
A= not defined $nB= $seen{$n}++
ABresult
1X1
011
000
274 8 push(@n, $n);
275 }
276 2 return @n;
277 }
278 }
279  
280  
281 25 my $ascii_encodings_re;
282 my $encodings_re;
283  
284 sub _encoding_ok {
285 30 ▶ my ($enc,$xwfu) =@ _;
Subroutine _encoding_ok: called CC=4 SCAR=13.9
286 30 $enc =~ s/^(?:x-?)?mac-?/mac/i;
287 30 ▶ ($enc) x (Encode'resolve_alias($enc)||return)
Branch: 1 branch
BranchTrueFalseTotal
$xwfu ? : 14 6 20
Condition80%4/5
&Encode::resolve_alias($enc) || (return)
l!l
2010
$xwfu ? $ascii_encodings_re : $encodings_re ||= qr/^${\join("|", map(quotemeta($_), "Encode"->encodings("Byte")));}\z/
l!l&&r!l&&!r
1820
MC/DC100%1/1
&Encode::resolve_alias($enc) || (return)
&Encode::resolve_alias($enc)
MC/DC0%0/2
$xwfu ? $ascii_encodings_re : $encodings_re ||= qr/^${\join("|", map(quotemeta($_), "Encode"->encodings("Byte")));}\z/
$xwfu ? $ascii_encodings_re : $encodings_re qr/^${\join("|", map(quotemeta($_), "Encode"->encodings("Byte")));}\z/
Truth table100%2/2
A
A= &Encode::resolve_alias($enc)
Aresult
11
00
Truth table66%2/3
A ||= B
A= $xwfu ? $ascii_encodings_re : $encodings_reB= qr/^${\join("|", map(quotemeta($_), "Encode"->encodings("Byte")));}\z/
ABresult
1X1
011
000
288 =~ ($xwfu ? $ascii_encodings_re : $encodings_re ||=qr/^${\
289 2 join'|',map quotemeta,
290 encodings Encode 'Byte'
291 }\z/);
292 }
293  
294 sub _apply_charset {
295 36 ▶ my($charsets,$apply_to) = @_; # array refs
Subroutine _apply_charset: called CC=9 SCAR=22.0
296 36 my ($charset,@ret);
297 36 for(@$charsets) {
298 #use DDS; Dump $_ if @$apply_to == 1;
299 23 ▶ eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { @ret = (); foreach my $applyee (@$apply_to) { push @ret, ref $applyee ? $applyee : &Encode::encode($_, $applyee, 9); } ; $charset = $_ } } and last 10 13 23
300 23 @ret = ();
301 # Can’t use map here, because it could die. (In
302 # perl5.8.x, dying inside a map is a very
303 # bad idea.)
304 23 for my $applyee(@$apply_to) {
305 41 ▶ push @ret, ref $applyee
Branch: 1 branch
BranchTrueFalseTotal
ref $applyee ? : 2 39 41
306 ? $applyee
307 : Encode::encode(
308 $_,$applyee,9
309 ); # 1=croak, 8=leave src alone
310 }
311 # Phew, we survived!
312 10 $charset = $_;
313 } && last;
314 }
315 36 ▶ unless($charset) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($charset) 26 10 36
316 # If none of the charsets applied, we just use the first
317 # one in the list (or fall back to utf8, since that’s the
318 # sensible thing to do these days), replacing unknown
319 # chars with ?
320 26 my $fallback;
321 26 ▶ $charset = $$charsets[0]||(++$fallback,'utf8');
Condition66%2/3
$charsets->[0] || (++$fallback, 'utf8')
l!l&&r!l&&!r
4220
MC/DC0%0/2
$charsets->[0] || (++$fallback, 'utf8')
$charsets->[0] (++$fallback, 'utf8')
Truth table66%2/3
A || B
A= $charsets->[0]B= (++$fallback, 'utf8')
ABresult
1X1
011
000
322 26 ▶ @ret = map ref$_ ? $_ : Encode'encode($charset,$_),
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 1 96 97
323 @$apply_to;
324 26 ▶ $fallback and $charset = 'utf-8';
Branch: 1 branch
BranchTrueFalseTotal
$fallback and $charset = "utf-8" 22 4 26
325 }
326 36 $charset,\@ret;
327 }
328  
329 # ~~~ This does not take non-ASCII file names into account, but I can’t
330 # really do that yet, since perl itself doesn’t support those properly
331 # yet, either.
332 # This one was stolen from HTML::Form but then modified extensively.
333 sub make_request
334 {
335 33 ▶ my $self = shift;
Subroutine make_request: called CC=12 SCAR=24.8
Pod undocumented
336 33 my $method = $self->method;
337 33 my $uri = $self->action;
338 33 ▶ my $xwfu = $method eq 'get'
Condition100%3/3
$method eq 'get' || !($self->enctype =~ m[^multipart/form-data\z]i)
l!l&&r!l&&!r
1896
MC/DC0%0/2
$method eq 'get' || !($self->enctype =~ m[^multipart/form-data\z]i)
$method eq 'get' !($self->enctype =~ m[^multipart/form-data\z]i)
Truth table33%1/3
A || not(B)
A= $method eq 'get'B= !($self->enctype =~ m[^multipart/form-data\z]i)
ABresult
1X1
011
000
339 || $self->enctype !~ /^multipart\/form-data\z/i;
340 33 my @form = $self->form;
341  
342 # Get the charset and encode the form fields, if necessary. The HTML
343 # spec says that the a/x-w-f-u MIME type only accepts ASCII, but we’ll
344 # be more forgiving, for the sake of realism. But to be compliant with
345 # the spec in cases where it can apply (e.g., a UTF-16 page with just
346 # ASCII in its form data), we only accept ASCII-based encodings for
347 # this enctype.
348 33 my @charsets;
349 33 ▶ { push @charsets, split ' ', $self->acceptCharset||next}
Condition100%2/2
$self->acceptCharset || (next)
l!l
1617
MC/DC100%1/1
$self->acceptCharset || (next)
$self->acceptCharset
Truth table100%2/2
A
A= $self->acceptCharset
Aresult
11
00
350 33 require Encode;
351 33 @charsets = map _encoding_ok($_, $xwfu),
352 @charsets;
353 33 ▶ unless(@charsets){{
Branch: 1 branch
BranchTrueFalseTotal
unless (@charsets) 25 8 33
354 # We only revert to the doc charset when accept-charset doesn’t
355 # have any usable encodings (even encodings which will cause char
356 # substitutions are considered usable; it’s non-ASCII with GET that
357 # we don’t want).
358 25 ▶ push @charsets, _encoding_ok(
Condition75%3/4
($self->ownerDocument || (next))->charset || (next)
l!l
421
$self->ownerDocument || (next)
l!l
250
MC/DC100%1/1
($self->ownerDocument || (next))->charset || (next)
($self->ownerDocument || (next))->charset
MC/DC0%0/1
$self->ownerDocument || (next)
$self->ownerDocument
Truth table100%2/2
A
A= ($self->ownerDocument || (next))->charset
Aresult
11
00
Truth table50%1/2
A
A= $self->ownerDocument
Aresult
11
00
359 ($self->ownerDocument||next)->charset || next, $xwfu
360 )
361 }}
362  
363 33 ▶ if ($method ne "post") {
Branch: 1 branch
BranchTrueFalseTotal
if ($method ne 'post') { } 18 15 33
364 18 require HTTP::Request;
365 18 $uri = URI->new($uri, "http");
366 $uri->can('query_form')
367 18 ▶ and $uri->query_form(@{_apply_charset \@charsets, \@form});
Branch: 1 branch
BranchTrueFalseTotal
$uri->can("query_form") and $uri->query_form(@{_apply_charset(\@charsets, \@form);}) 17 1 18
368 18 return HTTP::Request->new(GET => $uri);
369 }
370 else {
371 15 require HTTP::Request::Common;
372 15 ▶ if($xwfu) {
Branch: 1 branch
BranchTrueFalseTotal
if ($xwfu) { } 9 6 15
373 9 my($charset,$form) = _apply_charset \@charsets, \@form;
374 9 return HTTP::Request::Common::POST($uri, $form,
375 Content_Type =>
376 "application/x-www-form-urlencoded; charset=\"$charset\"");
377 }
378 else {
379 6 my @new_form;
380 6 ▶ while(@form) {
Branch: 1 branch
BranchTrueFalseTotal
if (@form) 10 6 16
381 10 my($name,$val) = (shift @form, shift @form);
382 #my $origval = $val;
383 10 (my $charset, $val) = _apply_charset \@charsets, [$val];
384 #use DDS; Dump [$origval,$val, ];
385 10 my $enc = $name;
386 10 ▶ $enc = Encode'encode('MIME-B', $enc) if $enc =~ /[^ -~]/;
Branch: 1 branch
BranchTrueFalseTotal
if $enc =~ /[^ -~]/ 1 9 10
387 10 ▶ push @new_form, $enc,
Branch: 1 branch
BranchTrueFalseTotal
ref $val->[0] ? : 3 7 10
388 ref $$val[0] ? $$val[0] : [(undef)x2,
389 Content_Type => "text/plain; charset=\"$charset\"",
390 Content => @$val,
391 ];
392 }
393 6 return HTTP::Request::Common::POST($uri, \@new_form,
394 Content_Type => 'multipart/form-data'
395 );
396 }
397 }
398 }
399  
400 sub form
401 {
402 package
403 HTML::Form; # so caller tricks work
404 36 ▶ my $self = shift;
Subroutine form: called CC=1 SCAR=0.0
Pod undocumented
405 36 map { $_->form_name_value($self) } $self->inputs;
406 }
407  
408  
409  
410  
411 package HTML::DOM::NodeList::Radio; # solely for HTML::Form compatibility
412 # Usually ::Input is used, but ::Radio
413 # is for a set of radio buttons.
414 25 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
415 25 require HTML::DOM::NodeList;
416  
417 25 our $VERSION = '0.057';
418 25 our @ISA = qw'HTML::DOM::NodeList';
419  
420 0 ▶sub type { 'radio' }
Subroutine type: not called CC=1 SCAR=6.9
421  
422 sub name {
423 39 ▶ my $ret = (my $self = shift)->item(0)->attr('name');
Subroutine name: called CC=3 SCAR=12.0
424 39 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 39 39
425 0 $self->item($_)->attr(name=>@_) for 0..$self->length-1;
426 }
427 $ret
428 39 }
429  
430 sub value { # ~~~ do case-folding and what-not, as in HTML::Form::ListInput
431 9 ▶ my $self = shift;
Subroutine value: called CC=8 SCAR=20.8
432  
433 9 my $checked_elem;
434 9 for (0..$self->length-1) {
435 17 my $btn = $self->item($_);
436 17 ▶ $btn->checked and
Branch: 1 branch
BranchTrueFalseTotal
$btn->checked and $checked_elem = $btn, last 5 12 17
437 $checked_elem = $btn, last;
438 }
439  
440 9 ▶ if (@_) { for (0..$self->length-1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7 2 9
441 10 my $btn = $self->item($_);
442 10 ▶ $_[0] eq $btn->attr('value') and
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq $btn->attr("value") and $btn->disabled && croak("The value '$_[0]' has been disabled for field '${\$self->name;}'"), $btn->checked(1), last 7 3 10
Condition66%2/3
$btn->disabled and croak("The value '$_[0]' has been disabled for field '${\$self->name;}'")
!ll&&!rl&&r
430
MC/DC0%0/2
$btn->disabled and croak("The value '$_[0]' has been disabled for field '${\$self->name;}'")
$btn->disabled croak("The value '$_[0]' has been disabled for field '${\$self->name;}'")
Truth table66%2/3
A and B
A= $btn->disabledB= croak("The value '$_[0]' has been disabled for field '${\$self->name;}'")
ABresult
0X0
100
111
443 $btn->disabled && croak(
444 "The value '$_[0]' has been disabled for field '${\
445 3 $self->name}'"
446 ),
447 $btn->checked(1),
448 last;
449 }}
450  
451 6 ▶ $checked_elem && $checked_elem->attr('value')
Branch: 1 branch
BranchTrueFalseTotal
$checked_elem and $checked_elem->attr("value") 3 3 6
452 }
453  
454 sub possible_values {
455 0 ▶ my $self = shift;
Subroutine possible_values: not called CC=1 SCAR=6.9
456 0 map $self->item($_)->attr('value'), 0..$self->length-1
457 }
458  
459 sub disabled {
460 4 ▶ my $self = shift;
Subroutine disabled: called CC=3 SCAR=11.0
461 4 for(@$self) {
462 5 ▶ $_->disabled or return 0
Branch: 1 branch
BranchTrueFalseTotal
$_->disabled or return 0 3 2 5
463 }
464 1 return 1
465 }
466  
467 sub form_name_value
468 # Pilfered from HTML::Form with slight changes.
469 {
470 package
471 HTML::Form::Input;
472 7 ▶ my $self = shift;
Subroutine form_name_value: called CC=5 SCAR=16.8
473 7 my $name = $self->name;
474 7 ▶ return unless defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 7 7
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
007
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
475 7 ▶ return if $self->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->disabled 0 7 7
476 7 my $value = $self->value;
477 7 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 6 7
478 6 return ($name => $value);
479 }
480  
481  
482 package HTML::DOM::Collection::Elements;
483  
484 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
485 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
486  
487 25 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
488  
489 25 our $VERSION = '0.057';
490  
491 25 require HTML::DOM::Collection;
492 25 our @ISA = 'HTML::DOM::Collection';
493  
494 # Internals: \[$nodelist, $tie]
495  
496 # Field constants:
497 sub nodelist(){0}
498 sub tye(){1}
499 sub seen(){2} # whether this key has been seen
500 sub position(){3} # current (array) position used by NEXTKEY
501 sub ids(){4} # whether we are iterating through ids
502 25 ▶{ no warnings 'misc';
Subroutine BEGIN: called CC=1 SCAR=0.0
503 25 undef &nodelist; undef &tye; undef &seen; undef &position;
504 }
505  
506 sub namedItem {
507 30 ▶ my($self, $name) = @_;
Subroutine namedItem: called CC=6 SCAR=18.0
508 30 my $list = $$self->[nodelist];
509 30 my $elem;
510 my @list;
511 30 for(0..$list->length - 1) {
512 25 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
513 166 ▶ push @list, $elem if
Branch: 1 branch
BranchTrueFalseTotal
if ($elem = $list->item($_))->id eq $name or $elem->attr("name") eq $name 43 123 166
Condition66%2/3
($elem = $list->item($_))->id eq $name or $elem->attr("name") eq $name
l!l&&r!l&&!r
043123
MC/DC50%1/2
($elem = $list->item($_))->id eq $name or $elem->attr("name") eq $name
($elem = $list->item($_))->id eq $name $elem->attr("name") eq $name
Truth table66%2/3
A or B
A= ($elem = $list->item($_))->id eq $nameB= $elem->attr("name") eq $name
ABresult
1X1
011
000
514 ($elem = $list->item($_))->id eq $name
515 or
516 $elem->attr('name') eq $name;
517 }
518 30 ▶ if(@list > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@list > 1) 13 17 30
519 # ~~~ Perhaps this should cache the new nodelist
520 # and return the same one each item. (Incident-
521 # ally, Firefox returns the same one but Safari
522 # makes a new one each time.)
523 my $ret = HTML::DOM::NodeList::Magic->new(sub {
524 25 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
525 11 ▶ grep $_->id eq $name ||
Subroutine __ANON__: called CC=2 SCAR=7.2
Condition66%2/3
$_->id eq $name || $_->attr('name') eq $name
l!l&&r!l&&!r
02222
MC/DC50%1/2
$_->id eq $name || $_->attr('name') eq $name
$_->id eq $name $_->attr('name') eq $name
Truth table66%2/3
A || B
A= $_->id eq $nameB= $_->attr('name') eq $name
ABresult
1X1
011
000
526 $_->attr('name') eq $name, @$list;
527 13 });
528 13 return $ret;
529 }
530 17 ▶ @list ? $list[0] :()
Branch: 1 branch
BranchTrueFalseTotal
@list ? : 17 0 17
531 }
532  
533  
534  
535 # ----------------- Docs ----------------- #
536  
537 =head1 NAME
538  
539 HTML::DOM::Element::Form - A Perl class for representing 'form' elements in an HTML DOM tree
540  
541 =head1 VERSION
542  
543 Version 0.057
544  
545 =head1 SYNOPSIS
546  
547 use HTML::DOM;
548 $doc = HTML::DOM->new;
549 $elem = $doc->createElement('form');
550  
551 $elem->method('GET') # set attribute
552 $elem->method; # get attribute
553 $elem->enctype;
554 $elem->tagName;
555 # etc
556  
557 =head1 DESCRIPTION
558  
559 This class implements 'form' elements in an HTML::DOM tree. It
560 implements the HTMLFormElement DOM interface and inherits from
561 L<HTML::DOM::Element> (q.v.).
562  
563 A form object can be used as a hash or an array, to access its input
564 fields, so S<<< C<< $form->[0] >> >>> and S<<< C<< $form->{name} >> >>>
565 are shorthand for
566 S<<< C<< $form->elements->[0] >> >>> and
567 S<< C<<< $form->elements->{name} >>> >>, respectively.
568  
569 This class also tries to mimic L<HTML::Form>, but is not entirely
570 compatible
571 with its interface. See L</WWW::Mechanize COMPATIBILITY>, below.
572  
573 =head1 DOM METHODS
574  
575 In addition to those inherited from HTML::DOM::Element and
576 HTML::DOM::Node, this class implements the following DOM methods:
577  
578 =over 4
579  
580 =item elements
581  
582 Returns a collection (L<HTML::DOM::Collection::Elements> object) in scalar
583 context,
584 or a list in list context, of all the input
585 fields this form contains. This differs slightly from the C<inputs> method
586 (part of the HTML::Form interface) in that it includes 'button' elements,
587 whereas C<inputs> does not (though it does include 'input' elements with
588 'button' for the type).
589  
590 =item length
591  
592 Same as C<< $form->elements->length >>.
593  
594 =item name
595  
596 =item acceptCharset
597  
598 =item action
599  
600 =item enctype
601  
602 =item method
603  
604 =item target
605  
606 Each of these returns the corresponding HTML attribute (C<acceptCharset>
607 corresponds to the 'accept-charset' attribute). If you pass an
608 argument, it will become the new value of the attribute, and the old value
609 will be returned.
610  
611 =item submit
612  
613 This triggers the form's 'submit' event, calling the default event handler
614 (see L<HTML::DOM/EVENT HANDLING>). It is up to the default event handler to
615 take any further action. The form's C<make_request> method may come in
616 handy.
617  
618 This method is actually just short for $form->trigger_event('submit'). (See
619 L<HTML::DOM::EventTarget>.)
620  
621 =item reset
622  
623 This triggers the form's 'reset' event.
624  
625 =item trigger_event
626  
627 This class overrides the superclasses' method to trigger the default event
628 handler for form submissions, when the submit event occurs, and reset the
629 form when a reset event occurs.
630  
631 =back
632  
633 =head1 WWW::Mechanize COMPATIBILITY
634  
635 In order to work with L<WWW::Mechanize>, this module mimics, and is
636 partly compatible with the
637 interface of, L<HTML::Form>.
638  
639 HTML::Form's class methods do not apply. If you call
640 C<< HTML::DOM::Element::Form->parse >>, for instance, you'll just get an
641 error, because it doesn't exist.
642  
643 The C<dump> and C<try_others> methods do not exist either.
644  
645 The C<click> method behaves differently from HTML::Form's, in that it does
646 not call C<make_request>, but triggers a 'click' event if there is a
647 button to click, or a 'submit' event otherwise.
648  
649 The C<method>, C<action>, C<enctype>, C<attr>, C<inputs>, C<find_input>,
650 C<value>, C<param>, C<make_request> and C<form>
651 methods should
652 work as expected.
653  
654 =head1 SEE ALSO
655  
656 L<HTML::DOM>
657  
658 L<HTML::DOM::Element>
659  
660 L<HTML::DOM::Collection::Elements>
661  
662 L<HTML::Form>
663  
664 =cut
665  
666  
667 # ------- HTMLSelectElement interface ---------- #
668  
669 package HTML::DOM::Element::Select;
670 25 our $VERSION = '0.057';
671 25 our @ISA = 'HTML::DOM::Element';
672  
673 25 ▶use overload fallback=>1, '@{}' => sub { shift->options };
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
674 # ~~~ Don't I need %{} as well?
675  
676 25 ▶use Scalar'Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
677  
678 22 ▶sub type { 'select-' . qw/one multiple/[!!shift->attr('multiple')] }
Subroutine type: called CC=1 SCAR=0.0
679 sub selectedIndex {
680 # Unfortunately, we cannot cache this (as in v. 0.040 and earlier)
681 # as any change to the DOM will require it to be reset.
682 10 ▶ my $self = shift;
Subroutine selectedIndex: called CC=6 SCAR=17.9
683 10 my $ret;
684 10 ▶ if(defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 8 2 10
685 8 my $x=0;
686 # ~~~ I can optimise this by using $self->traverse since
687 # I don't need the rest of the list once I've found
688 # a selected item.
689 8 for($self->options) {
690 13 ▶ $_->selected and
Branch: 1 branch
BranchTrueFalseTotal
$_->selected and $ret = $x, last 7 6 13
691 $ret = $x,
692 last;
693 6 $x++;
694 }
695 8 ▶ defined $ret or
Branch: 1 branch
BranchTrueFalseTotal
defined $ret or $ret = -1 1 7 8
696 $ret = -1,
697 }
698 10 ▶ @_ and ($self->options)[$_[0]]->selected(1);
Branch: 1 branch
BranchTrueFalseTotal
@_ and ($self->options)[$_[0]]->selected(1) 2 8 10
699 10 return $ret;
700 }
701 2 ▶sub value { shift->options->value(@_) }
Subroutine value: called CC=1 SCAR=0.0
702 1 ▶sub length { scalar(()= shift->options ) }
Subroutine length: called CC=1 SCAR=0.0
703 sub form {
704 78 ▶ my $self = shift;
Subroutine form: called CC=8 SCAR=20.9
705 my $ret = ($self->look_up(_tag => 'form'))[0] || $$self{_HTML_DOM_f}
706 78 ▶ if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 60 18 78
Condition100%3/3
($self->look_up('_tag', 'form'))[0] || $self->{'_HTML_DOM_f'}
l!l&&r!l&&!r
28923
MC/DC100%2/2
($self->look_up('_tag', 'form'))[0] || $self->{'_HTML_DOM_f'}
($self->look_up('_tag', 'form'))[0] $self->{'_HTML_DOM_f'}
Truth table100%3/3
A || B
A= ($self->look_up('_tag', 'form'))[0]B= $self->{'_HTML_DOM_f'}
ABresult
1X1
011
000
707 @_ and defined $_[0]
708 ? ( weaken($$self{_HTML_DOM_f} = $_[0]), shift->add_element($self) )
709 78 ▶ : (delete $$self{_HTML_DOM_f} or return $ret || ())
Branch: 2 branches
BranchTrueFalseTotal
@_ and defined $_[0] ? (builtin::weaken($self->{"_HTML_DOM_f"} = $_[0]), (shift())->add_element($self)) : (delete $self->{"_HTML_DOM_f"} || (return $ret || ()))->remove_element($self) 18 60 78
defined $_[0] ? : 9 9 18
Condition60%3/5
delete $self->{'_HTML_DOM_f'} || (return $ret || ())
l!l
72
$ret || ()
l!l&&r!l&&!r
020
MC/DC100%1/1
delete $self->{'_HTML_DOM_f'} || (return $ret || ())
delete $self->{'_HTML_DOM_f'}
MC/DC0%0/2
$ret || ()
$ret ()
Truth table100%2/2
A
A= delete $self->{'_HTML_DOM_f'}
Aresult
11
00
Truth table33%1/3
A || B
A= $retB= ()
ABresult
1X1
011
000
710 ->remove_element($self);
711 76 ▶ $ret || ();
Branch: 1 branch
BranchTrueFalseTotal
$ret or () 39 37 76
712 }
713 sub options { # ~~~ I need to make this cache the resulting collection obj
714 # but when I do so I need to weaken references to $self
715 # and make ::Options do the same.
716 114 ▶ my $self = shift;
Subroutine options: called CC=2 SCAR=6.9
717 114 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 17 97 114
718 17 return grep tag $_ eq 'option', $self->descendants;
719 }
720 else {
721 my $collection = HTML::DOM::Collection::Options->new(
722 my $list = HTML::DOM::NodeList::Magic->new(
723 24 ▶ sub { grep tag $_ eq 'option', $self->descendants }
Subroutine __ANON__: called CC=1 SCAR=0.0
724 97 ), $self);
725 97 $self->ownerDocument-> _register_magic_node_list($list);
726 97 $collection;
727 }
728 }
729 sub disabled {
730 126 ▶ shift->_attr( disabled => @_ ? $_[0] ? 'disabled' : undef : () )
Subroutine disabled: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 19 107 126
$_[0] ? : 12 7 19
731 }
732 sub multiple {
733 17 ▶ shift->_attr( multiple => @_ ? (undef,'multiple')[!!$_[0]] : () )
Subroutine multiple: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 5 12 17
734 }
735 25 *name = \&HTML::DOM::Element::Form::name;
736 11 ▶sub size { shift->_attr( size => @_) }
Subroutine size: called CC=1 SCAR=0.0
737 21 ▶sub tabIndex { shift->_attr( tabindex => @_) }
Subroutine tabIndex: called CC=1 SCAR=0.0
738  
739 sub add {
740 2 ▶ my ($sel,$opt,$b4) = @_;
Subroutine add: called CC=1 SCAR=0.0
741 # ~~~ does the following always work or will an optgroup break it?
742 2 eval{$sel->insertBefore($opt,$b4)};
743 2 return;
744 }
745 sub remove {
746 1 ▶ my $self = shift;
Subroutine remove: called CC=2 SCAR=7.0
747 # ~~~ and how about this one?
748 1 ▶ eval{$self->removeChild($self->options->item(shift) || return)};
Condition50%1/2
$self->options->item(shift()) || (return)
l!l
10
MC/DC0%0/1
$self->options->item(shift()) || (return)
$self->options->item(shift())
Truth table50%1/2
A
A= $self->options->item(shift())
Aresult
11
00
749 1 return;
750 }
751  
752 3 ▶sub blur { shift->trigger_event('blur') }
Subroutine blur: called CC=1 SCAR=0.0
753 3 ▶sub focus { shift->trigger_event('focus') }
Subroutine focus: called CC=1 SCAR=0.0
754 2 ▶sub _reset { my $self = shift;
Subroutine _reset: called CC=2 SCAR=6.9
755 2 $_->_reset for $self->options }
756  
757  
758 package HTML::DOM::Collection::Options;
759  
760 25 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
761 25 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
762  
763 25 our $VERSION = '0.057';
764  
765 25 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
766 25 ▶use constant sel => 5; # must not conflict with super
Subroutine BEGIN: called CC=1 SCAR=0.0
767 25 ▶{ no strict 'refs'; delete ${__PACKAGE__."::"}{sel} } # after compilation
Subroutine BEGIN: called CC=1 SCAR=0.0
768  
769 25 require HTML::DOM::Exception;
770 25 require HTML::DOM::Collection;
771 25 our @ISA = qw'HTML::DOM::Collection';
772  
773 sub new {
774 97 ▶ my $self = shift->SUPER::new(shift);
Subroutine new: called CC=1 SCAR=0.0
775 97 $$$self[sel] = shift;
776 97 $self
777 }
778  
779 2 ▶sub type { 'option' }
Subroutine type: called CC=1 SCAR=0.0
780 sub possible_values {
781 0 ▶ map $_->value, @{+shift};
Subroutine possible_values: not called CC=1 SCAR=6.9
782 }
783  
784 sub value { # ~~~ do case-folding and what-not, as in HTML::Form::ListInput
785 5 ▶ my $self = shift;
Subroutine value: called CC=8 SCAR=21.5
786  
787 5 my $sel_elem;
788 5 for (0..$self->length-1) {
789 11 my $opt = $self->item($_);
790 11 ▶ $opt->selected and
Branch: 1 branch
BranchTrueFalseTotal
$opt->selected and $sel_elem = $opt, last 3 8 11
791 $sel_elem = $opt, last;
792 }
793  
794 5 ▶ if (@_) { for (0..$self->length-1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 4 5
795 3 my $opt = $self->item($_);
796 3 my $v = $opt->value;
797 3 ▶ $_[0] eq $v and
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq $v and $opt->disabled && croak("The value '$_[0]' has been disabled for field '${\$self->name;}'"), $opt->selected(1), last 0 3 3
Condition0%0/3
$opt->disabled and croak("The value '$_[0]' has been disabled for field '${\$self->name;}'")
!ll&&!rl&&r
000
MC/DC0%0/2
$opt->disabled and croak("The value '$_[0]' has been disabled for field '${\$self->name;}'")
$opt->disabled croak("The value '$_[0]' has been disabled for field '${\$self->name;}'")
Truth table0%0/3
A and B
A= $opt->disabledB= croak("The value '$_[0]' has been disabled for field '${\$self->name;}'")
ABresult
0X0
100
111
798 $opt->disabled && croak(
799 "The value '$_[0]' has been disabled for field '${\
800 0 $self->name}'"
801 ),
802 $opt->selected(1),
803 last;
804 }}
805  
806 5 ▶ !defined $sel_elem # Shouldn't happen in well-formed documents, but
Branch: 1 branch
BranchTrueFalseTotal
defined $sel_elem or $sel_elem = $self->item(0) 2 3 5
807 and $sel_elem # how many documents are well-formed?
808 = $self->item(0);
809  
810 5 $sel_elem->value;
811 }
812  
813 sub name {
814 21 ▶ $${+shift}[sel]->name
Subroutine name: called CC=1 SCAR=0.0
815 }
816  
817 sub disabled {
818 6 ▶ (my $self = shift)->item(0)->look_up(_tag => 'select')->disabled
Subroutine disabled: called CC=4 SCAR=13.9
Branch: 1 branch
BranchTrueFalseTotal
(my $self = shift())->item(0)->look_up("_tag", "select")->disabled and return 1 1 5 6
819 and return 1;
820 5 for (@$self) {
821 6 ▶ $_->disabled || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$_->disabled or return 0 4 2 6
822 }
823 1 return 1
824 }
825  
826 sub length { # override
827 8 ▶ my $self = shift;
Subroutine length: called CC=2 SCAR=6.9
828 8 ▶ die new HTML::DOM::Exception
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 7 8
829 HTML::DOM::Exception::NOT_SUPPORTED_ERR,
830 "This implementation does not allow length to be set"
831 if @_;
832 7 $self->SUPER::length;
833 }
834  
835 25 *form_name_value = \& HTML::DOM::NodeList::Radio::form_name_value;
836  
837  
838 # ------- HTMLOptGroupElement interface ---------- #
839  
840 package HTML::DOM::Element::OptGroup;
841 25 our $VERSION = '0.057';
842 25 our @ISA = 'HTML::DOM::Element';
843  
844 10 ▶sub label { shift->_attr( label => @_) }
Subroutine label: called CC=1 SCAR=0.0
845 25 *disabled = \&HTML::DOM::Element::Select::disabled;
846  
847  
848 # ------- HTMLOptionElement interface ---------- #
849  
850 package HTML::DOM::Element::Option;
851 25 our $VERSION = '0.057';
852 25 our @ISA = qw'HTML::DOM::Element';
853  
854 25 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
855 25 require HTML::DOM::Exception;
856  
857 25 *form = \&HTML::DOM::Element::Select::form;
858 sub defaultSelected {
859 8 ▶ shift->_attr( selected => @_ ? $_[0] ? 'selected' : undef : () )
Subroutine defaultSelected: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 5 3 8
$_[0] ? : 3 2 5
860 }
861  
862 sub text {
863 shift->as_text
864 8 ▶}
Subroutine text: called CC=1 SCAR=0.0
865  
866 sub index {
867 2 ▶ my $self = shift;
Subroutine index: called CC=7 SCAR=25.7
868 2 my $indx = 0;
869 2 my @options = (my $sel = $self->look_up(_tag => 'select'))
870 ->options;
871 2 for(@options){
872 3 ▶ last if $self == $_;
Branch: 1 branch
BranchTrueFalseTotal
if $self == $_ 2 1 3
873 1 $indx++;
874 }
875 # This should not happen, unless the tree is horribly mangled:
876 2 ▶ defined $indx or die new HTML::DOM::Exception
Branch: 1 branch
BranchTrueFalseTotal
defined $indx or die "HTML::DOM::Exception"->new(3, "It seems this option element is not a descendant of its ancestor.") 0 2 2
877 HTML::DOM::Exception::HIERARCHY_REQUEST_ERR,
878 "It seems this option element is not a descendant of its ancestor."
879 ;
880 2 ▶ if ( @_ ) {{
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 2 2
881 0 my $new_indx= shift;
882 0 ▶ last if $new_indx == $indx;
Branch: 1 branch
BranchTrueFalseTotal
if $new_indx == $indx 0 0 0
883 0 ▶ if ($new_indx == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($new_indx == 0) 0 0 0
884 0 $sel->insertBefore($self, $options[0]);
885 0 last;
886 }
887 0 $options[$new_indx-1]->parentNode->insertBefore(
888 $self, $options[$new_indx-1]->nextSibling
889 );
890 }}
891 2 $indx;
892 }
893  
894 25 *disabled = \&HTML::DOM::Element::Select::disabled;
895 25 *label = \&HTML::DOM::Element::OptGroup::label;
896  
897 sub selected {
898 51 ▶ my $self = shift;
Subroutine selected: called CC=10 SCAR=23.0
899 51 my $ret;
900  
901 51 ▶ if(!defined $self->{_HTML_DOM_sel}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'_HTML_DOM_sel'}) { } 37 14 51
902 37 ▶ $ret = $self->attr('selected')||0;
Condition100%2/2
$self->attr('selected') || 0
l!l
1423
MC/DC100%1/1
$self->attr('selected') || 0
$self->attr('selected')
Truth table100%2/2
A
A= $self->attr('selected')
Aresult
11
00
903 }
904 else {
905 $ret = $self->{_HTML_DOM_sel}
906 14 }
907 51 ▶ if(@_ && !$ret != !$_[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and !$ret != !$_[0]) 11 40 51
Condition66%2/3
@_ and !$ret != !$_[0]
!ll&&!rl&&r
40011
MC/DC50%1/2
@_ and !$ret != !$_[0]
@_ !$ret != !$_[0]
Truth table66%2/3
A and not(B)
A= @_B= !$ret != !$_[0]
ABresult
0X0
100
111
908 11 my $sel = $self->look_up(_tag => 'select');
909 11 ▶ if(!$sel || $sel->multiple) {
Branch: 2 branches
BranchTrueFalseTotal
if (not $sel or $sel->multiple) { } 8 3 11
elsif ($_[0]) { } 2 1 3
Condition100%3/3
not $sel or $sel->multiple
l!l&&r!l&&!r
173
MC/DC100%2/2
not $sel or $sel->multiple
not $sel $sel->multiple
Truth table100%3/3
not(A) or B
A= not $selB= $sel->multiple
ABresult
1X1
011
000
910 8 $self->{_HTML_DOM_sel} = shift;
911 }
912 elsif($_[0]) { # You can't deselect the only selected
913 # option if exactly one option must be
914 # selected at any given time.
915 2 $self->{_HTML_DOM_sel} = shift;
916 $_ != $self and $_->{_HTML_DOM_sel} = 0
917 2 ▶ for $sel->options;
Branch: 1 branch
BranchTrueFalseTotal
$_ != $self and $_->{"_HTML_DOM_sel"} = 0 4 2 6
918 }
919 }
920 $ret
921 51 }
922  
923 sub value { # ~~~ do case-folding and what-not, as in HTML::Form::ListInput
924  
925 22 ▶ my $self = shift;
Subroutine value: called CC=7 SCAR=20.5
926 22 my $ret;
927  
928 22 ▶ if(caller =~ /^(?:HTML::Form(?:::Input)?|WWW::Mechanize)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ((caller) =~ /^(?:HTML::Form(?:::Input)?|WWW::Mechanize)\z/) 9 13 22
929 # ~~~ I can optimise this to call ->value once.
930 9 ▶ $ret = $self->selected ? $self->value : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->selected ? : 2 7 9
931 9 ▶ @_ and defined $_[0]
Branch: 3 branches
BranchTrueFalseTotal
@_ and defined $_[0] ? $_[0] eq $self->value ? $self->selected(1) : croak("Invalid value '$_[0]' for option " . $self->name) : $self->selected(0) 0 9 9
defined $_[0] ? : 0 0 0
$_[0] eq $self->value ? : 0 0 0
932 ? $_[0] eq $self->value
933 ? $self->selected(1)
934 : croak "Invalid value '$_[0]' for option "
935 . $self->name
936 : $self->selected(0);
937 9 return $ret;
938 }
939  
940 13 ▶ defined($ret = $self->attr(value => @_)) or
Branch: 1 branch
BranchTrueFalseTotal
defined($ret = $self->attr("value", @_)) or $ret = $self->text 3 10 13
941 $ret = $self->text;
942  
943 13 return $ret;
944 }
945  
946 sub type() { 'option' }
947  
948 sub possible_values {
949 (undef, shift->value)
950 0 ▶}
Subroutine possible_values: not called CC=1 SCAR=6.9
951  
952 sub name {
953 86 ▶ shift->look_up(_tag => 'select')->name
Subroutine name: called CC=1 SCAR=0.0
954 }
955  
956 8 ▶sub _reset { delete shift->{_HTML_DOM_sel} }
Subroutine _reset: called CC=1 SCAR=0.0
957  
958 25 *form_name_value = \& HTML::DOM::NodeList::Radio::form_name_value;
959  
960  
961 # ------- HTMLInputElement interface ---------- #
962  
963 package HTML::DOM::Element::Input;
964 25 our $VERSION = '0.057';
965 25 our @ISA = qw'HTML::DOM::Element';
966  
967 25 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
968  
969 122 ▶sub defaultValue { shift->_attr( value => @_) }
Subroutine defaultValue: called CC=1 SCAR=0.0
970 sub defaultChecked {
971 67 ▶ shift->_attr( checked => @_ ? $_[0] ? 'checked' : undef : () )
Subroutine defaultChecked: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 4 63 67
$_[0] ? : 3 1 4
972 }
973 25 *form = \&HTML::DOM::Element::Select::form;
974 5 ▶sub accept { shift->_attr( accept => @_) }
Subroutine accept: called CC=1 SCAR=0.0
975 25 ▶sub accessKey { shift->_attr( accesskey => @_) }
Subroutine accessKey: called CC=1 SCAR=0.0
976 10 ▶sub align { lc shift->_attr( align => @_) }
Subroutine align: called CC=1 SCAR=0.0
977 5 ▶sub alt { shift->_attr( alt => @_) }
Subroutine alt: called CC=1 SCAR=0.0
978 sub checked {
979 109 ▶ my $self = shift;
Subroutine checked: called CC=12 SCAR=24.9
980 109 my $ret;
981 109 ▶ if(!defined $self->{_HTML_DOM_checked}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'_HTML_DOM_checked'}) { } 43 66 109
982 43 $ret = $self->defaultChecked
983 }
984 else {
985 $ret = $self->{_HTML_DOM_checked}
986 66 }
987 109 ▶ if( @_ && !$ret != not $self->{_HTML_DOM_checked} = shift
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and !$ret != !($self->{"_HTML_DOM_checked"} = shift()) and not $ret and $self->type eq "radio") 8 101 109
Condition100%9/9
@_ and !$ret != !($self->{"_HTML_DOM_checked"} = shift()) and not $ret and $self->type eq "radio"
!ll&&!rl&&r
9478
@_ and !$ret != !($self->{"_HTML_DOM_checked"} = shift()) and not $ret
!ll&&!rl&&r
86815
@_ and !$ret != !($self->{"_HTML_DOM_checked"} = shift())
!ll&&!rl&&r
681823
MC/DC100%4/4
@_ and !$ret != !($self->{"_HTML_DOM_checked"} = shift()) and not $ret and $self->type eq "radio"
@_ !$ret != !($self->{"_HTML_DOM_checked"} = shift()) not $ret $self->type eq "radio"
Truth table100%5/5
A and not(B) and not(C) and D
A= @_B= !$ret != !($self->{"_HTML_DOM_checked"} = shift())C= not $retD= $self->type eq "radio"
ABCDresult
0XXX0
10XX0
110X0
11100
11111
988 and !$ret and $self->type eq 'radio' ) {
989 8 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if (my $form = $self->form and defined(my $name = $self->name)) 8 0 8
Condition33%1/3
my $form = $self->form and defined(my $name = $self->name)
!ll&&!rl&&r
008
MC/DC0%0/2
my $form = $self->form and defined(my $name = $self->name)
my $form = $self->form defined(my $name = $self->name)
Truth table33%1/3
A and B
A= my $form = $self->formB= defined(my $name = $self->name)
ABresult
0X0
100
111
990 my $form = $self->form and defined(my $name = $self->name)
991 ) {
992 25 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
993 $_ != $self && $_->type eq 'radio'
994 && $_->name eq $name
995 and $_->{_HTML_DOM_checked} = 0
996 8 ▶ for $form->elements;
Branch: 1 branch
BranchTrueFalseTotal
$_ != $self and $_->type eq "radio" and $_->name eq $name and $_->{"_HTML_DOM_checked"} = 0 10 44 54
Condition100%6/6
$_ != $self and $_->type eq "radio" and $_->name eq $name
!ll&&!rl&&r
36810
$_ != $self and $_->type eq "radio"
!ll&&!rl&&r
82818
MC/DC100%3/3
$_ != $self and $_->type eq "radio" and $_->name eq $name
$_ != $self $_->type eq "radio" $_->name eq $name
Truth table100%4/4
A and B and C
A= $_ != $selfB= $_->type eq "radio"C= $_->name eq $name
ABCresult
0XX0
10X0
1100
1111
997 }
998 }
999 109 return $ret;
1000 }
1001 25 *disabled = \&HTML::DOM::Element::Select::disabled;
1002 5 ▶sub maxLength { shift->_attr( maxlength => @_) }
Subroutine maxLength: called CC=1 SCAR=0.0
1003 25 *name = \&HTML::DOM::Element::Form::name;
1004 12 ▶sub readOnly { shift->_attr(readonly => @_ ? $_[0]?'readonly':undef : ()) }
Subroutine readOnly: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 8 4 12
$_[0] ? : 4 4 8
1005 25 *size = \&HTML::DOM::Element::Select::size;
1006 5 ▶sub src { shift->_attr( src => @_) }
Subroutine src: called CC=1 SCAR=0.0
1007 25 *tabIndex = \&HTML::DOM::Element::Select::tabIndex;
1008 sub type {
1009 351 ▶ my $ret = shift->_attr('type', @_);
Subroutine type: called CC=2 SCAR=7.2
1010 351 ▶ return defined $ret ? lc $ret : 'text'
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 351 0 351
1011 }
1012 5 ▶sub useMap { shift->_attr( usemap => @_) }
Subroutine useMap: called CC=1 SCAR=0.0
1013 sub value {
1014 187 ▶ my $self = shift;
Subroutine value: called CC=12 SCAR=24.9
1015 187 my($ret,$type);
1016  
1017 187 ▶ if(caller =~ /^(?:HTML::Form(?:::Input)?|WWW::Mechanize)\z/ and
Branch: 1 branch
BranchTrueFalseTotal
if ((caller) =~ /^(?:HTML::Form(?:::Input)?|WWW::Mechanize)\z/ and ($type = $self->type) =~ /^(?:button|reset)\z/ && (return) || $type eq "checkbox") 40 145 185
Condition87%7/8
(caller) =~ /^(?:HTML::Form(?:::Input)?|WWW::Mechanize)\z/ and ($type = $self->type) =~ /^(?:button|reset)\z/ && (return) || $type eq "checkbox"
!ll&&!rl&&r
866140
($type = $self->type) =~ /^(?:button|reset)\z/ and return or $type eq "checkbox"
l!l&&r!l&&!r
04059
($type = $self->type) =~ /^(?:button|reset)\z/ and return
!ll
992
MC/DC66%2/3
(caller) =~ /^(?:HTML::Form(?:::Input)?|WWW::Mechanize)\z/ and ($type = $self->type) =~ /^(?:button|reset)\z/ && (return) || $type eq "checkbox"
(caller) =~ /^(?:HTML::Form(?:::Input)?|WWW::Mechanize)\z/ ($type = $self->type) =~ /^(?:button|reset)\z/ $type eq "checkbox"
Truth table75%3/4
A and B or C
A= (caller) =~ /^(?:HTML::Form(?:::Input)?|WWW::Mechanize)\z/B= ($type = $self->type) =~ /^(?:button|reset)\z/C= $type eq "checkbox"
ABCresult
0XX0
1000
11X1
1011
1018 ($type = $self->type) =~ /^(?:button|reset)\z/ && return ||
1019 $type eq 'checkbox') {
1020 # ~~~ Do case-folding as in HTML::Input::ListInput
1021 40 my $value = $self->value;
1022 40 ▶ length $value or $value = 'on';
Branch: 1 branch
BranchTrueFalseTotal
length $value or $value = "on" 1 39 40
1023 40 ▶ $ret = $self->checked
Branch: 1 branch
BranchTrueFalseTotal
$self->checked ? : 25 15 40
1024 ? $value
1025 : undef;
1026 40 ▶ @_ and defined $_[0]
Branch: 3 branches
BranchTrueFalseTotal
@_ and defined $_[0] ? $_[0] eq $value ? $self->checked(1) : croak("Invalid value '$_[0]' for checkbox " . $self->name) : $self->checked(0) 19 21 40
defined $_[0] ? : 12 7 19
$_[0] eq $value ? : 6 6 12
1027 ? $_[0] eq $value
1028 ? $self->checked(1)
1029 : croak
1030 "Invalid value '$_[0]' for checkbox "
1031 . $self->name
1032 : $self->checked(0);
1033 34 return $ret;
1034 }
1035  
1036 # ~~~ shouldn't I make sure that modifying the value attribute
1037 # (=defaultValue) leaves the value alone, even if the value has not
1038 # yet been accessed? (The same goes for checked and $option->selected)
1039 145 ▶ if(!defined $self->{_HTML_DOM_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'_HTML_DOM_value'}) { } 100 45 145
1040 100 $ret = $self->defaultValue
1041 }
1042 else {
1043 $ret = $self->{_HTML_DOM_value}
1044 45 }
1045 145 ▶ @_ and $self->{_HTML_DOM_value} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"_HTML_DOM_value"} = shift() 37 108 145
1046 25 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1047 145 return "$ret";
1048 }
1049 sub _reset {
1050 17 ▶ my $self = shift;
Subroutine _reset: called CC=1 SCAR=0.0
1051 17 $self->checked($self->defaultChecked);
1052 17 $self->value($self->defaultValue);
1053 }
1054  
1055 25 *blur = \&HTML::DOM::Element::Select::blur;
1056 25 *focus = \&HTML::DOM::Element::Select::focus;
1057 2 ▶sub select { shift->trigger_event('select') }
Subroutine select: called CC=1 SCAR=0.0
1058 7 ▶sub click { for(shift){
Subroutine click: called CC=5 SCAR=16.4
1059 7 my(undef,$x,$y) = @_;
1060 7 ▶ defined or $_ = 1 for $x, $y;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or $_ = 1 14 0 14
1061 7 local($$_{_HTML_DOM_clicked}) = [$x,$y];
1062 7 ▶ $_->type eq 'checkbox' && $_->checked(!$_->checked);
Branch: 1 branch
BranchTrueFalseTotal
$_->type eq "checkbox" and $_->checked(!$_->checked) 0 7 7
1063 7 $_->trigger_event('click');
1064 7 return;
1065 }}
1066  
1067 sub trigger_event {
1068 100 ▶ my ($a,$evnt) = (shift,shift);
Subroutine trigger_event: called CC=2 SCAR=7.1
1069 100 my $input_type = $a->type;
1070 $a->SUPER::trigger_event(
1071 $evnt,
1072 $input_type =~ /^(?:(submi)|rese)t\z/
1073 ?( DOMActivate_default =>
1074 # I’m not using a closure here, because we
1075 # don’t want the overhead of cloning it
1076 # when it might not even be used.
1077 (sub { (shift->target->form||return)
1078 3 ▶ ->trigger_event('submit') },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
(shift())->target->form || (return)
l!l
30
MC/DC0%0/1
(shift())->target->form || (return)
(shift())->target->form
Truth table50%1/2
A
A= (shift())->target->form
Aresult
11
00
1079 sub { (shift->target->form||return)
1080 1 ▶ ->trigger_event('reset') })
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
(shift())->target->form || (return)
l!l
10
MC/DC0%0/1
(shift())->target->form || (return)
(shift())->target->form
Truth table50%1/2
A
A= (shift())->target->form
Aresult
11
00
1081 100 ▶ [!$1]
Branch: 1 branch
BranchTrueFalseTotal
$input_type =~ /^(?:(submi)|rese)t\z/ ? : 9 91 100
1082 ) :(),
1083 @_
1084 );
1085 }
1086  
1087 sub possible_values {
1088 0 ▶ $_[0]->type eq 'checkbox' ? wantarray ? (undef, shift->value) : 2
Subroutine possible_values: not called CC=3 SCAR=24.8
Branch: 2 branches
BranchTrueFalseTotal
$_[0]->type eq 'checkbox' ? : 0 0 0
wantarray ? : 0 0 0
1089 : ()
1090 }
1091 sub form_name_value
1092 {
1093 64 ▶ my $self = shift;
Subroutine form_name_value: called CC=6 SCAR=17.9
1094 64 my $type = $self->type;
1095 64 ▶ if ($type =~ /^(image|submit)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type =~ /^(image|submit)\z/) 6 58 64
1096 6 ▶ return unless $self->{_HTML_DOM_clicked};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_HTML_DOM_clicked"} 2 4 6
1097 4 ▶ if($1 eq 'image') {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 eq "image") 2 2 4
1098 2 my $name = $self->name;
1099 2 ▶ $name = length $name ? "$name." : '';
Branch: 1 branch
BranchTrueFalseTotal
length $name ? : 1 1 2
1100 return "${name}x" => $self->{_HTML_DOM_clicked}[0],
1101 2 "${name}y" => $self->{_HTML_DOM_clicked}[1]
1102 }
1103 }
1104 60 ▶ return $type eq 'file'
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'file' ? : 5 55 60
1105 ? $self->HTML_Form_FileInput_form_name_value(@_)
1106 : $self->HTML_Form_Input_form_name_value(@_);
1107 }
1108  
1109 # These two were stolen from HTML::Form with a few tweaks:
1110 sub HTML_Form_Input_form_name_value
1111 {
1112 package
1113 HTML::Form::Input;
1114 56 ▶ my $self = shift;
Subroutine HTML_Form_Input_form_name_value: called CC=5 SCAR=16.1
1115 56 my $name = $self->name;
1116 56 ▶ return unless defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 2 54 56
Condition66%2/3
defined $name and length $name
!ll&&!rl&&r
0254
MC/DC50%1/2
defined $name and length $name
defined $name length $name
Truth table66%2/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
1117 54 ▶ return if $self->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->disabled 1 53 54
1118 53 my $value = $self->value;
1119 53 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 51 53
1120 51 return ($name => $value);
1121 }
1122  
1123 sub HTML_Form_FileInput_form_name_value {
1124 package
1125 HTML::Form::ListInput;
1126 5 ▶ my($self, $form) = @_;
Subroutine HTML_Form_FileInput_form_name_value: called CC=11 SCAR=29.9
1127 5 ▶ return $self-> HTML_Form_Input_form_name_value($form)
Branch: 1 branch
BranchTrueFalseTotal
if uc $form->method ne "POST" or lc $form->enctype ne "multipart/form-data" 1 4 5
Condition66%2/3
uc $form->method ne "POST" or lc $form->enctype ne "multipart/form-data"
l!l&&r!l&&!r
014
MC/DC50%1/2
uc $form->method ne "POST" or lc $form->enctype ne "multipart/form-data"
uc $form->method ne "POST" lc $form->enctype ne "multipart/form-data"
Truth table66%2/3
A or B
A= uc $form->method ne "POST"B= lc $form->enctype ne "multipart/form-data"
ABresult
1X1
011
000
1128 if uc $form->method ne "POST" ||
1129 lc $form->enctype ne "multipart/form-data";
1130  
1131 4 my $name = $self->name;
1132 4 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 4 4
1133 4 ▶ return if $self->{disabled};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"disabled"} 0 4 4
1134  
1135 4 my $file = $self->file;
1136 4 my $filename = $self->filename;
1137 4 my @headers = $self->headers;
1138 4 my $content = $self->content;
1139 4 ▶ if (defined $content) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $content) { } 0 4 4
elsif (not defined $file or length $file == 0) { } 1 3 4
1140 0 ▶ $filename = $file unless defined $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 0 0 0
1141 0 $file = undef;
1142 0 unshift(@headers, "Content" => $content);
1143 }
1144 ▶ elsif (!defined($file) || length($file) == 0) {
Condition66%2/3
not defined $file or length $file == 0
l!l&&r!l&&!r
013
MC/DC50%1/2
not defined $file or length $file == 0
not defined $file length $file == 0
Truth table66%2/3
not(A) or B
A= not defined $fileB= length $file == 0
ABresult
1X1
011
000
1145 1 return;
1146 }
1147  
1148 # legacy (this used to be the way to do it)
1149 3 ▶ if (ref($file) eq "ARRAY") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file eq "ARRAY") 0 3 3
1150 0 my $f = shift @$file;
1151 0 my $fn = shift @$file;
1152 0 push(@headers, @$file);
1153 0 $file = $f;
1154 0 ▶ $filename = $fn unless defined $filename;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $filename 0 0 0
1155 }
1156  
1157 3 return ($name => [$file, $filename, @headers]);
1158 }
1159  
1160  
1161  
1162 25 *file = \&value;
1163  
1164 sub filename {
1165 4 ▶ my $self = shift;
Subroutine filename: called CC=3 SCAR=11.3
1166 4 my $old = $self->{_HTML_DOM_filename};
1167 4 ▶ $self->{_HTML_DOM_filename} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
1168 4 ▶ $old = $self->file unless defined $old;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old 4 0 4
1169 4 $old;
1170 }
1171  
1172 ▶sub headers { } # ~~~ Do I want to complete this?
Subroutine headers: called CC=1 SCAR=0.0
1173  
1174 sub content {
1175 4 ▶ my $self = shift;
Subroutine content: called CC=2 SCAR=7.0
1176 4 my $old = $self->{_HTML_DOM_content};
1177 4 ▶ $self->{_HTML_DOM_content} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 0 4 4
1178 4 $old;
1179 }
1180  
1181  
1182  
1183 # ------- HTMLTextAreaElement interface ---------- #
1184  
1185 package HTML::DOM::Element::TextArea;
1186 25 our $VERSION = '0.057';
1187 25 our @ISA = qw'HTML::DOM::Element';
1188  
1189 sub defaultValue { # same as HTML::DOM::Element::Title::text
1190 11 ▶ ($_[0]->firstChild or
Subroutine defaultValue: called CC=3 SCAR=12.0
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 and $_[0]->appendChild((shift())->ownerDocument->createTextNode(shift())) 0 1 1
Condition66%2/3
$_[0]->firstChild || (@_ > 1 && $_[0]->appendChild((shift())->ownerDocument->createTextNode(shift())), (return ''))
l!l&&r!l&&!r
1010
MC/DC0%0/2
$_[0]->firstChild || (@_ > 1 && $_[0]->appendChild((shift())->ownerDocument->createTextNode(shift())), (return ''))
$_[0]->firstChild (@_ > 1 && $_[0]->appendChild((shift())->ownerDocument->createTextNode(shift())), (return ''))
Truth table33%1/3
A || B
A= $_[0]->firstChildB= (@_ > 1 && $_[0]->appendChild((shift())->ownerDocument->createTextNode(shift())), (return ''))
ABresult
1X1
011
000
1191 @_ > 1 && $_[0]->appendChild(
1192 shift->ownerDocument->createTextNode(shift)
1193 ),
1194 return '',
1195 )->data(@_[1..$#_]);
1196 }
1197 25 *form = \&HTML::DOM::Element::Select::form;
1198 25 *accessKey = \&HTML::DOM::Element::Input::accessKey;
1199 5 ▶sub cols { shift->_attr( cols => @_) }
Subroutine cols: called CC=1 SCAR=0.0
1200 25 *disabled = \&HTML::DOM::Element::Select::disabled;
1201 25 *name = \&HTML::DOM::Element::Select::name;
1202 25 *readOnly = \&HTML::DOM::Element::Input::readOnly;
1203 5 ▶sub rows {shift->_attr( rows => @_) }
Subroutine rows: called CC=1 SCAR=0.0
1204 25 *tabIndex = \&HTML::DOM::Element::Select::tabIndex;
1205 1 ▶sub type { 'textarea' }
Subroutine type: called CC=1 SCAR=0.0
1206 sub value {
1207 5 ▶ my $self = shift;
Subroutine value: called CC=3 SCAR=11.0
1208 5 my $ret;
1209  
1210 5 ▶ if(!defined $self->{_HTML_DOM_value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $self->{'_HTML_DOM_value'}) { } 4 1 5
1211 4 $ret = $self->defaultValue
1212 }
1213 else {
1214 $ret = $self->{_HTML_DOM_value}
1215 1 }
1216 5 ▶ @_ and $self->{_HTML_DOM_value} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"_HTML_DOM_value"} = shift() 1 4 5
1217 5 return $ret;
1218 }
1219 25 *blur = \&HTML::DOM::Element::Select::blur;
1220 25 *focus = \&HTML::DOM::Element::Select::focus;
1221 25 *select = \&HTML::DOM::Element::Input::select;
1222  
1223 sub _reset {
1224 0 ▶ my $self = shift;
Subroutine _reset: not called CC=1 SCAR=6.9
1225 0 $self->value($self->defaultValue);
1226 }
1227  
1228 25 *form_name_value = \& HTML::DOM::NodeList::Radio::form_name_value;
1229  
1230  
1231 # ------- HTMLButtonElement interface ---------- #
1232  
1233 package HTML::DOM::Element::Button;
1234 25 our $VERSION = '0.057';
1235 25 our @ISA = qw'HTML::DOM::Element';
1236  
1237 25 *form = \&HTML::DOM::Element::Select::form;
1238 25 *accessKey = \&HTML::DOM::Element::Input::accessKey;
1239 25 *disabled = \&HTML::DOM::Element::Select::disabled;
1240 25 *name = \&HTML::DOM::Element::Form::name;
1241 25 *tabIndex = \&HTML::DOM::Element::Select::tabIndex;
1242 25 ▶sub type { no warnings 'uninitialized'; lc shift->attr('type') }
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine type: called CC=1 SCAR=0.0
1243 5 ▶sub value { shift->attr( value => @_) }
Subroutine value: called CC=1 SCAR=0.0
1244  
1245 sub form_name_value
1246 {
1247 8 ▶ my $self = shift;
Subroutine form_name_value: called CC=8 SCAR=21.7
1248 8 my $type = $self->type;
1249 8 ▶ return unless !$type or $type eq 'submit';
Branch: 1 branch
BranchTrueFalseTotal
unless not $type or $type eq "submit" 4 4 8
Condition66%2/3
not $type or $type eq "submit"
l!l&&r!l&&!r
404
MC/DC50%1/2
not $type or $type eq "submit"
not $type $type eq "submit"
Truth table66%2/3
not(A) or B
A= not $typeB= $type eq "submit"
ABresult
1X1
011
000
1250 4 ▶ return unless $self->{_HTML_DOM_clicked};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_HTML_DOM_clicked"} 2 2 4
1251 2 my $name = $self->name;
1252 2 ▶ return unless defined $name && length $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name and length $name 0 2 2
Condition33%1/3
defined $name and length $name
!ll&&!rl&&r
002
MC/DC0%0/2
defined $name and length $name
defined $name length $name
Truth table33%1/3
A and B
A= defined $nameB= length $name
ABresult
0X0
100
111
1253 2 ▶ return if $self->disabled;
Branch: 1 branch
BranchTrueFalseTotal
if $self->disabled 0 2 2
1254 2 my $value = $self->value;
1255 2 ▶ return unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 2 2
1256 2 return ($name => $value);
1257 }
1258  
1259  
1260 4 ▶sub click { for(shift){
Subroutine click: called CC=2 SCAR=6.9
1261 4 local($$_{_HTML_DOM_clicked}) = 1;
1262 4 $_->trigger_event('click');
1263 4 return;
1264 }}
1265  
1266 sub trigger_event {
1267 27 ▶ my ($a,$evnt) = (shift,shift);
Subroutine trigger_event: called CC=3 SCAR=11.3
1268 27 ▶ my $input_type = $a->type || 'submit';
Condition100%2/2
$a->type || 'submit'
l!l
225
MC/DC100%1/1
$a->type || 'submit'
$a->type
Truth table100%2/2
A
A= $a->type
Aresult
11
00
1269 $a->SUPER::trigger_event(
1270 $evnt,
1271 $input_type =~ /^(?:(submi)|rese)t\z/
1272 ?( DOMActivate_default =>
1273 # I’m not using a closure here, because we
1274 # don’t want the overhead of cloning it
1275 # when it might not even be used.
1276 (sub { (shift->target->form||return)
1277 3 ▶ ->trigger_event('submit') },
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
(shift())->target->form || (return)
l!l
30
MC/DC0%0/1
(shift())->target->form || (return)
(shift())->target->form
Truth table50%1/2
A
A= (shift())->target->form
Aresult
11
00
1278 sub { (shift->target->form||return)
1279 1 ▶ ->trigger_event('reset') })
Subroutine __ANON__: called CC=2 SCAR=7.6
Condition50%1/2
(shift())->target->form || (return)
l!l
10
MC/DC0%0/1
(shift())->target->form || (return)
(shift())->target->form
Truth table50%1/2
A
A= (shift())->target->form
Aresult
11
00
1280 27 ▶ [!$1]
Branch: 1 branch
BranchTrueFalseTotal
$input_type =~ /^(?:(submi)|rese)t\z/ ? : 27 0 27
1281 ) :(),
1282 @_
1283 );
1284 }
1285  
1286 ▶sub _reset {}
Subroutine _reset: called CC=1 SCAR=0.0
1287  
1288 # ------- HTMLLabelElement interface ---------- #
1289  
1290 package HTML::DOM::Element::Label;
1291 25 our $VERSION = '0.057';
1292 25 our @ISA = qw'HTML::DOM::Element';
1293  
1294 25 *form = \&HTML::DOM::Element::Select::form;
1295 25 *accessKey = \&HTML::DOM::Element::Input::accessKey;
1296 5 ▶sub htmlFor { shift->_attr( for => @_) }
Subroutine htmlFor: called CC=1 SCAR=0.0
1297  
1298 # ------- HTMLFieldSetElement interface ---------- #
1299  
1300 package HTML::DOM::Element::FieldSet;
1301 25 our $VERSION = '0.057';
1302 25 our @ISA = qw'HTML::DOM::Element';
1303  
1304 25 *form = \&HTML::DOM::Element::Select::form;
1305  
1306 # ------- HTMLLegendElement interface ---------- #
1307  
1308 package HTML::DOM::Element::Legend;
1309 25 our $VERSION = '0.057';
1310 25 our @ISA = qw'HTML::DOM::Element';
1311  
1312 25 *form = \&HTML::DOM::Element::Select::form;
1313 25 *accessKey = \&HTML::DOM::Element::Input::accessKey;
1314 25 *align = \*HTML::DOM::Element::Input::align;
1315  
1316  
1317 25 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1318 25 !+~()#%$-*
« DOM/_TreeBuilder.pm ↑ Summary DOM.pm »