DOM/Element.pm

filter: Statementstmt 97.5% 597 / 612 Branchbran 86.2% 195 / 226 Conditioncond 78.4% 73 / 93 MC/DCmcdc 38.0% 19 / 50 Subroutinesub 98.0% 149 / 152 Podpod 72.4% 21 / 29 totaltotal 90.7% 1054 / 1162 SCAR 50.8
CC
153
Cov
93%
trigger_event
15.1
setAttributeNode
12.0
getAttributeNode
10.0
CRAP 161.3
« DOM.pm ↑ Summary DOM/EventTarget.pm »
1 package HTML::DOM::Element;
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 use HTML::DOM::Exception qw 'INVALID_CHARACTER_ERR
7 25 ▶ INUSE_ATTRIBUTE_ERR NOT_FOUND_ERR SYNTAX_ERR';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 25 ▶use HTML::DOM::Node 'ELEMENT_NODE';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 25 ▶use HTML'Entities;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 25 ▶use Scalar::Util qw'refaddr blessed weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 25 require HTML::DOM::Attr;
13 25 require HTML::DOM::Element::Form;
14 25 require HTML::DOM::Element::Table;
15 25 require HTML::DOM::NamedNodeMap;
16 25 require HTML::DOM::Node;
17 25 require HTML::DOM::NodeList::Magic;
18  
19 25 our @ISA = qw'HTML::DOM::Node';
20 25 our $VERSION = '0.057';
21  
22  
23 {
24 # ~~~ Perhaps I should make class_for into a class method, rather
25 # than a function, so Element.pm can be subclassed. Maybe I'll
26 # wait until someone tries to subclass it. (Applies to Event.pm
27 # as well.) If a potential subclasser is reading this, will he
28 # please give me a holler?
29  
30 25 my %class_for = (
31 '~text' => 'HTML::DOM::Text',
32 html => 'HTML::DOM::Element::HTML',
33 head => 'HTML::DOM::Element::Head',
34 link => 'HTML::DOM::Element::Link',
35 title => 'HTML::DOM::Element::Title',
36 meta => 'HTML::DOM::Element::Meta',
37 base => 'HTML::DOM::Element::Base',
38 isindex=> 'HTML::DOM::Element::IsIndex',
39 style => 'HTML::DOM::Element::Style',
40 body => 'HTML::DOM::Element::Body',
41 form => 'HTML::DOM::Element::Form',
42 select => 'HTML::DOM::Element::Select',
43 optgroup=> 'HTML::DOM::Element::OptGroup',
44 option => 'HTML::DOM::Element::Option',
45 input => 'HTML::DOM::Element::Input',
46 textarea=> 'HTML::DOM::Element::TextArea',
47 button => 'HTML::DOM::Element::Button',
48 label => 'HTML::DOM::Element::Label',
49 fieldset=> 'HTML::DOM::Element::FieldSet',
50 legend => 'HTML::DOM::Element::Legend',
51 ul => 'HTML::DOM::Element::UL',
52 ol => 'HTML::DOM::Element::OL',
53 dl => 'HTML::DOM::Element::DL',
54 dir => 'HTML::DOM::Element::Dir',
55 menu => 'HTML::DOM::Element::Menu',
56 li => 'HTML::DOM::Element::LI',
57 div => 'HTML::DOM::Element::Div',
58 p => 'HTML::DOM::Element::P',
59 map((
60 "h$_" => 'HTML::DOM::Element::Heading'
61 ), 1..6),
62 q => 'HTML::DOM::Element::Quote',
63 blockquote=> 'HTML::DOM::Element::Quote',
64 pre => 'HTML::DOM::Element::Pre',
65 br => 'HTML::DOM::Element::Br',
66 basefont => 'HTML::DOM::Element::BaseFont',
67 font => 'HTML::DOM::Element::Font',
68 hr => 'HTML::DOM::Element::HR',
69 ins => 'HTML::DOM::Element::Mod',
70 del => 'HTML::DOM::Element::Mod',
71 a => 'HTML::DOM::Element::A',
72 img => 'HTML::DOM::Element::Img',
73 object => 'HTML::DOM::Element::Object',
74 param => 'HTML::DOM::Element::Param',
75 applet => 'HTML::DOM::Element::Applet',
76 map => 'HTML::DOM::Element::Map',
77 area => 'HTML::DOM::Element::Area',
78 script => 'HTML::DOM::Element::Script',
79 table => 'HTML::DOM::Element::Table',
80 caption => 'HTML::DOM::Element::Caption',
81 col => 'HTML::DOM::Element::TableColumn',
82 colgroup=> 'HTML::DOM::Element::TableColumn',
83 thead => 'HTML::DOM::Element::TableSection',
84 tfoot => 'HTML::DOM::Element::TableSection',
85 tbody => 'HTML::DOM::Element::TableSection',
86 tr => 'HTML::DOM::Element::TR',
87 th => 'HTML::DOM::Element::TableCell',
88 td => 'HTML::DOM::Element::TableCell',
89 frameset=> 'HTML::DOM::Element::FrameSet',
90 frame => 'HTML::DOM::Element::Frame',
91 iframe => 'HTML::DOM::Element::IFrame',
92 );
93 sub class_for {
94 1310 ▶ $class_for{lc$_[0]} || __PACKAGE__
Subroutine class_for: called CC=2 SCAR=6.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
$class_for{lc $_[0]} or __PACKAGE__ 70 1240 1310
95 }
96 }
97  
98  
99 =head1 NAME
100  
101 HTML::DOM::Element - A Perl class for representing elements in an HTML DOM tree
102  
103 =head1 VERSION
104  
105 Version 0.057
106  
107 =head1 SYNOPSIS
108  
109 use HTML::DOM;
110 $doc = HTML::DOM->new;
111 $elem = $doc->createElement('a');
112  
113 $elem->setAttribute('href', 'http://www.perl.org/');
114 $elem->getAttribute('href');
115 $elem->tagName;
116 # etc
117  
118 =head1 DESCRIPTION
119  
120 This class represents elements in an HTML::DOM tree. It is the base class
121 for other element classes (see
122 L<HTML::DOM/CLASSES AND DOM INTERFACES>.) It implements the Element and
123 HTMLElement DOM interfaces.
124  
125 =head1 METHODS
126  
127 =head2 Constructor
128  
129 You should normally use HTML::DOM's C<createElement> method. This is listed
130 here only for completeness:
131  
132 $elem = new HTML::DOM::Element $tag_name;
133  
134 C<$elem> will automatically be blessed into the appropriate class for
135 C<$tag_name>.
136  
137 =cut
138  
139 25 sub new {
140 1316 ▶ my $tagname = $_[1];
Subroutine new: called CC=4 SCAR=14.0
Pod undocumented
141  
142 # Hack to make parsing comments work
143 1316 ▶ $tagname eq '~comment'
Branch: 1 branch
BranchTrueFalseTotal
$tagname eq "~comment" and require HTML::DOM::Comment, (return "HTML::DOM::Comment"->new) 7 1309 1316
144 and require HTML'DOM'Comment, return new HTML'DOM'Comment;
145  
146 # ~~~ The DOM spec does not specify which characters are invaleid.
147 # I think I need to check the HTML spec. For now, I'm simply
148 # letting HTML::Element do the insanity checking, and I'm turn-
149 # ing its errors into HTML::DOM::Exceptions.
150 1309 my $ret;
151 1309 eval {
152 1309 $ret = bless shift->SUPER::new(@_), class_for $tagname;
153  
154 # require can sometimes fail if it’s part of a tainted
155 # statement. That’s why it’s in a do block.
156 $tagname =~ /^html\z/i
157 1309 ▶ and do { require HTML'DOM }; # paranoia
Branch: 1 branch
BranchTrueFalseTotal
$tagname =~ /^html\z/i and do { require HTML::DOM } 147 1162 1309
158 };
159 1309 ▶ $@ or return $ret;
Branch: 1 branch
BranchTrueFalseTotal
$@ or return $ret 1309 0 1309
160 0 die HTML::DOM::Exception->new( INVALID_CHARACTER_ERR, $@);
161 }
162  
163  
164 =head2 Attributes
165  
166 The following DOM attributes are supported:
167  
168 =over 4
169  
170 =item tagName
171  
172 Returns the tag name.
173  
174 =item id
175  
176 =item title
177  
178 =item lang
179  
180 =item dir
181  
182 =item className
183  
184 These five get (optionally set) the corresponding HTML attributes. Note
185 that C<className> corresponds to the C<class> attribute.
186  
187 =cut
188  
189 sub tagName {
190 441 ▶ uc $_[0]->tag;
Subroutine tagName: called CC=1 SCAR=0.0
Pod documented
191 }
192  
193 2713 ▶sub id { shift->_attr(id => @_) }
Subroutine id: called CC=1 SCAR=0.0
Pod documented
194  
195 5 ▶sub title { shift->_attr(title => @_) }
Subroutine title: called CC=1 SCAR=0.0
Pod documented
196 5 ▶sub lang { shift->_attr(lang => @_) }
Subroutine lang: called CC=1 SCAR=0.0
Pod documented
197 5 ▶sub dir { lc shift->_attr(dir => @_) }
Subroutine dir: called CC=1 SCAR=0.0
Pod documented
198 5 ▶sub className { shift->_attr(class => @_) }
Subroutine className: called CC=1 SCAR=0.0
Pod documented
199  
200 =item style
201  
202 This returns a L<CSS::DOM::Style> object, representing the contents
203 of the 'style' HTML attribute.
204  
205 =cut
206  
207 sub style {
208 38 ▶ my $self = shift;
Subroutine style: called CC=2 SCAR=7.0
Pod documented
209 38 ▶ ($self->getAttributeNode('style') || do {
Condition66%2/3
$self->getAttributeNode('style') || do { $self->setAttribute('style', ''); $self->getAttributeNode('style') }
l!l&&r!l&&!r
18200
MC/DC0%0/2
$self->getAttributeNode('style') || do { $self->setAttribute('style', ''); $self->getAttributeNode('style') }
$self->getAttributeNode('style') do { $self->setAttribute('style', ''); $self->getAttributeNode('style') }
Truth table66%2/3
A || B
A= $self->getAttributeNode('style')B= do { $self->setAttribute('style', ''); $self->getAttributeNode('style') }
ABresult
1X1
011
000
210 20 $self->setAttribute('style','');
211 20 $self->getAttributeNode('style');
212 }) -> style;
213 }
214  
215 =back
216  
217 And there is also the following non-DOM attribute:
218  
219 =over 4
220  
221 =item content_offset
222  
223 This contains the offset (in characters) within the HTML source of the
224 element's first child node, if it is a text node. This is set (indirectly)
225 by HTML::DOM's C<write> method. You can also set it yourself.
226  
227 =back
228  
229 =cut
230  
231 sub content_offset {
232 502 ▶ my $old = (my $self = shift)->{_HTML_DOM_offset};
Subroutine content_offset: called CC=2 SCAR=6.9
Pod documented
233 502 ▶ @_ and $self->{_HTML_DOM_offset} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"_HTML_DOM_offset"} = shift() 500 2 502
234 502 $old;
235 }
236  
237  
238 =head2 Other Methods
239  
240 =over 4
241  
242 =item getAttribute ( $name )
243  
244 Returns the attribute's value as a string.
245  
246 =item setAttribute ( $name, $value )
247  
248 Sets the attribute named C<$name> to C<$value>.
249  
250 =item removeAttribute ( $name )
251  
252 Deletes the C<$name>d attribute.
253  
254 =item getAttributeNode ( $name )
255  
256 Returns an attribute node (L<HTML::DOM::Attr>).
257  
258 =item setAttributeNode ( $attr )
259  
260 Sets the attribute whose name is C<< $attr->nodeName >> to the attribute
261 object itself. If it replaces another attribute object, the latter is
262 returned.
263  
264 =item removeAttributeNode ( $attr )
265  
266 Removes and returns the C<$attr>.
267  
268 =item getElementsByTagName ( $tagname)
269  
270 This finds all elements with that tag name under the current element,
271 returning them as a list in list context or a node list object in scalar
272 context.
273  
274 =item getElementsByClassName ( $names )
275  
276 This finds all elements whose class attribute contains all the names in
277 C<$names>, which is a space-separated list; returning the elements as a
278 list in list context or a node list object in scalar
279 context.
280  
281 =item hasAttribute ( $name )
282  
283 Returns true or false, indicating whether this element has an attribute
284 named C<$name>, even one that is implied.
285  
286 =item click() (HTML 5)
287  
288 This triggers a click event on the element; nothing more.
289  
290 =item trigger_event
291  
292 This overrides L<HTML::DOM::Node>'s method to trigger a DOMActivate event
293 after a click.
294  
295 =back
296  
297 =cut
298  
299 25 my %attr_defaults = (
300 br => { clear => 'none' },
301 td => { colspan => '1', rowspan=>1},
302 th => { colspan => 1, rowspan=>1},
303 form => {
304 enctype => 'application/x-www-form-urlencoded',
305 method => 'GET',
306 },
307 frame =>{frameborder => 1,scrolling=> 'auto'},
308 iframe=> {frameborder => 1,scrolling=>'auto'},
309 'area'=> {'shape' => 'rect',},
310 'a' =>{'shape' => 'rect',},
311 'col'=>{ 'span' => 1,},
312 'colgroup'=>{ 'span' => 1,},
313 'input',{ 'type' => 'TEXT',},
314 'button' =>{'type' => 'submit',},
315 'param' =>{'valuetype' => 'DATA'},
316 );
317 # Note: The _HTML_DOM_unspecified key used below points to a hash that
318 # stores Attr objects for implicit attributes in this list.
319  
320 sub getAttribute {
321 5012 ▶ my $ret = $_[0]->attr($_[1]);
Subroutine getAttribute: called CC=9 SCAR=22.1
Pod documented
322 5012 ▶ defined $ret ? "$ret" : do{
Branch: 1 branch
BranchTrueFalseTotal
defined $ret ? : 3850 1162 5012
323 1162 my $tag = $_[0]->tag;
324 1162 ▶if(!$_[0]->tag){warn $_[0]->as_HTML; Carp::cluck}
Branch: 1 branch
BranchTrueFalseTotal
unless ($_[0]->tag) 0 1162 1162
325 return '' unless exists $attr_defaults{$tag}
326 and exists $attr_defaults{$tag}{$_[1]}
327 or $tag eq 'html' and $_[1] eq 'version'
328 1162 ▶ and exists $_[0]->{_HTML_DOM_version};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$_[1]} or $tag eq "html" and $_[1] eq "version" and exists $_[0]{"_HTML_DOM_version"} 32 198 230
Condition100%12/12
exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$_[1]} or $tag eq "html" and $_[1] eq "version" and exists $_[0]{"_HTML_DOM_version"}
l!l&&r!l&&!r
1964962
exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$_[1]}
!ll&&!rl&&r
613353196
$tag eq "html" and $_[1] eq "version" and exists $_[0]{"_HTML_DOM_version"}
!ll&&!rl&&r
96312
$tag eq "html" and $_[1] eq "version"
!ll&&!rl&&r
932313
MC/DC40%2/5
exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$_[1]} or $tag eq "html" and $_[1] eq "version" and exists $_[0]{"_HTML_DOM_version"}
exists $attr_defaults{$tag} exists $attr_defaults{$tag}{$_[1]} $tag eq "html" $_[1] eq "version" exists $_[0]{"_HTML_DOM_version"}
Truth table33%3/9
A and B or C and D and E
A= exists $attr_defaults{$tag}B= exists $attr_defaults{$tag}{$_[1]}C= $tag eq "html"D= $_[1] eq "version"E= exists $_[0]{"_HTML_DOM_version"}
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
329 $_[1] eq 'version'
330 ? $_[0]->{_HTML_DOM_version}
331 198 ▶ : $attr_defaults{$tag}{$_[1]}
Branch: 1 branch
BranchTrueFalseTotal
$_[1] eq 'version' ? : 2 196 198
332 };
333 }
334  
335 sub setAttribute {
336 # ~~~ INVALID_CHARACTER_ERR
337 801 ▶ my $self = shift;
Subroutine setAttribute: called CC=7 SCAR=19.5
Pod documented
338  
339 # If the current value is an Attr object, we have to modify that
340 # instead of just assigning to the attribute.
341 801 my $attr = $self->attr($_[0]);
342 801 ▶ if(defined blessed $attr && $attr->isa('HTML::DOM::Attr')){
Branch: 1 branch
BranchTrueFalseTotal
if (defined builtin::blessed($attr) and $attr->isa('HTML::DOM::Attr')) { } 216 585 801
Condition100%3/3
defined builtin::blessed($attr) and $attr->isa("HTML::DOM::Attr")
!ll&&!rl&&r
5832216
MC/DC100%2/2
defined builtin::blessed($attr) and $attr->isa("HTML::DOM::Attr")
defined builtin::blessed($attr) $attr->isa("HTML::DOM::Attr")
Truth table100%3/3
A and B
A= defined builtin::blessed($attr)B= $attr->isa("HTML::DOM::Attr")
ABresult
0X0
100
111
343 216 $attr->value($_[1]);
344 }else{
345 585 my($name,$val) = @_;
346 585 my $str_val = "$val";
347 585 my $old = $self->attr($name,$str_val);
348 25 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
349 $old ne $str_val
350 and $self->trigger_event('DOMAttrModified',
351 auto_viv => sub {
352 249 ▶ require HTML'DOM'Event'Mutation;
Subroutine __ANON__: called CC=2 SCAR=6.9
353 249 ▶ attr_name => $name,
Branch: 1 branch
BranchTrueFalseTotal
defined $old ? : 12 237 249
354 attr_change_type =>
355 defined $old
356 ? &HTML'DOM'Event'Mutation'MODIFICATION
357 : &HTML'DOM'Event'Mutation'ADDITION,
358 prev_value => $old,
359 new_value => $val,
360 rel_node => $self->getAttributeNode($name),
361 }
362 585 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$old ne $str_val and $self->trigger_event("DOMAttrModified", "auto_viv", sub { require HTML::DOM::Event::Mutation; "attr_name", $name, "attr_change_type", defined $old ? &HTML::DOM::Event::Mutation::MODIFICATION : &HTML::DOM::Event::Mutation::ADDITION, "prev_value", $old, "new_value", $val, "rel_node", $self->getAttributeNode($name); } ) 564 21 585
363 }
364  
365 # possible event handler
366 801 ▶ if ($_[0] =~ /^on(.*)/is and my $listener_maker = $self->
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /^on(.*)/is and my $listener_maker = $self->ownerDocument->event_attr_handler) 2 799 801
Condition100%3/3
$_[0] =~ /^on(.*)/is and my $listener_maker = $self->ownerDocument->event_attr_handler
!ll&&!rl&&r
79722
MC/DC0%0/2
$_[0] =~ /^on(.*)/is and my $listener_maker = $self->ownerDocument->event_attr_handler
$_[0] =~ /^on(.*)/is my $listener_maker = $self->ownerDocument->event_attr_handler
Truth table33%1/3
A and B
A= $_[0] =~ /^on(.*)/isB= my $listener_maker = $self->ownerDocument->event_attr_handler
ABresult
0X0
100
111
367 ownerDocument->event_attr_handler) {
368 2 my $eavesdropper = &$listener_maker(
369 $self, my $name = lc $1, $_[1]
370 );
371 2 ▶ defined $eavesdropper and $self-> event_handler(
Branch: 1 branch
BranchTrueFalseTotal
defined $eavesdropper and $self->event_handler($name, $eavesdropper) 2 0 2
372 $name, $eavesdropper
373 );
374 }
375  
376 return # nothing;
377 801 }
378  
379 # This is just like attr, except that it triggers events.
380 sub _attr {
381 5158 ▶ my($self,$name) = (shift,shift);
Subroutine _attr: called CC=4 SCAR=13.9
382 # ~~~ Can we change getAttribute to attr, to make it faster, or will attr reject a reference? (Do we have to stringify it?)
383 5158 ▶ my $old = $self->getAttribute($name) if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 4720 438 5158
384 @_
385 5158 ▶ and defined $_[0]
Branch: 2 branches
BranchTrueFalseTotal
@_ and defined $_[0] ? $self->setAttribute($name, shift()) : $self->removeAttribute($name) 783 4375 5158
defined $_[0] ? : 747 36 783
386 ? $self->setAttribute($name, shift)
387 : $self->removeAttribute($name);
388 5158 $old;
389 }
390  
391  
392 sub removeAttribute {
393 47 ▶ my $old = (my $self = shift)->attr(my $name = shift);
Subroutine removeAttribute: called CC=4 SCAR=13.9
Pod documented
394 47 $self->attr($name => undef);
395 47 ▶ if(defined blessed $old and $old->isa('HTML::DOM::Attr')) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined builtin::blessed($old) and $old->isa('HTML::DOM::Attr')) { } 7 40 47
Condition66%2/3
defined builtin::blessed($old) and $old->isa("HTML::DOM::Attr")
!ll&&!rl&&r
4007
MC/DC50%1/2
defined builtin::blessed($old) and $old->isa("HTML::DOM::Attr")
defined builtin::blessed($old) $old->isa("HTML::DOM::Attr")
Truth table66%2/3
A and B
A= defined builtin::blessed($old)B= $old->isa("HTML::DOM::Attr")
ABresult
0X0
100
111
396 # So the attr node can be reused:
397 7 $old->_element(undef);
398  
399 7 $self->trigger_event('DOMAttrModified',
400 attr_name => $name,
401 attr_change_type => 3,
402 prev_value =>
403 (new_value => ($old->value) x 2)[-1..1],
404 rel_node => $old,
405 );
406 }
407 else {
408 40 ▶ return unless defined $old;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $old 1 39 40
409 $self->trigger_event('DOMAttrModified',
410 auto_viv => sub {
411 2 ▶ (my $attr =
Subroutine __ANON__: called CC=1 SCAR=0.0
412 $self->ownerDocument
413 ->createAttribute($name)
414 )->value($old);
415 2 attr_name => $name,
416 attr_change_type => 3,
417 prev_value => $old,
418 new_value => $old,
419 rel_node => $attr,
420 }
421 39 );
422 }
423  
424 return # nothing;
425 46 }
426  
427 sub getAttributeNode {
428 378 ▶ my $elem = shift;
Subroutine getAttributeNode: called CC=10 SCAR=23.0
Pod documented
429 378 my $name = lc shift;
430  
431 378 my $attr = $elem->attr($name);
432 378 ▶ unless(defined $attr
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $attr) 45 333 378
433 ) { # check to see whether it has a default value
434 45 my $tag = $elem->tag;
435 45 ▶ return $elem->{_HTML_DOM_unspecified}{$name} ||= do{
Condition100%3/3
$elem->{"_HTML_DOM_unspecified"}{$name} ||= do { return unless exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$name} or $tag eq "html" and $name eq "version" and exists $elem->{"_HTML_DOM_version"}; my $attr = "HTML::DOM::Attr"->new($name); $attr->_set_ownerDocument($elem->ownerDocument); $attr->_element($elem); $attr->value($name eq "version" ? $elem->{"_HTML_DOM_version"} : $attr_defaults{$tag}{$name}); $attr }
l!l&&r!l&&!r
12321
MC/DC100%2/2
$elem->{"_HTML_DOM_unspecified"}{$name} ||= do { return unless exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$name} or $tag eq "html" and $name eq "version" and exists $elem->{"_HTML_DOM_version"}; my $attr = "HTML::DOM::Attr"->new($name); $attr->_set_ownerDocument($elem->ownerDocument); $attr->_element($elem); $attr->value($name eq "version" ? $elem->{"_HTML_DOM_version"} : $attr_defaults{$tag}{$name}); $attr }
$elem->{"_HTML_DOM_unspecified"}{$name} do { return unless exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$name} or $tag eq "html" and $name eq "version" and exists $elem->{"_HTML_DOM_version"}; my $attr = "HTML::DOM::Attr"->new($name); $attr->_set_ownerDocument($elem->ownerDocument); $attr->_element($elem); $attr->value($name eq "version" ? $elem->{"_HTML_DOM_version"} : $attr_defaults{$tag}{$name}); $attr }
Truth table100%3/3
A ||= B
A= $elem->{"_HTML_DOM_unspecified"}{$name}B= do { return unless exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$name} or $tag eq "html" and $name eq "version" and exists $elem->{"_HTML_DOM_version"}; my $attr = "HTML::DOM::Attr"->new($name); $attr->_set_ownerDocument($elem->ownerDocument); $attr->_element($elem); $attr->value($name eq "version" ? $elem->{"_HTML_DOM_version"} : $attr_defaults{$tag}{$name}); $attr }
ABresult
1X1
011
000
436 return unless exists $attr_defaults{$tag}
437 and exists $attr_defaults{$tag}{$name}
438 or $tag eq 'html' and $name eq 'version'
439 44 ▶ and exists $elem->{_HTML_DOM_version};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$name} or $tag eq "html" and $name eq "version" and exists $elem->{"_HTML_DOM_version"} 1 21 22
Condition91%11/12
exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$name} or $tag eq "html" and $name eq "version" and exists $elem->{"_HTML_DOM_version"}
l!l&&r!l&&!r
20123
exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$name}
!ll&&!rl&&r
22220
$tag eq "html" and $name eq "version" and exists $elem->{"_HTML_DOM_version"}
!ll&&!rl&&r
2211
$tag eq "html" and $name eq "version"
!ll&&!rl&&r
2202
MC/DC40%2/5
exists $attr_defaults{$tag} and exists $attr_defaults{$tag}{$name} or $tag eq "html" and $name eq "version" and exists $elem->{"_HTML_DOM_version"}
exists $attr_defaults{$tag} exists $attr_defaults{$tag}{$name} $tag eq "html" $name eq "version" exists $elem->{"_HTML_DOM_version"}
Truth table33%3/9
A and B or C and D and E
A= exists $attr_defaults{$tag}B= exists $attr_defaults{$tag}{$name}C= $tag eq "html"D= $name eq "version"E= exists $elem->{"_HTML_DOM_version"}
ABCDEresult
11XXX1
0X1111
101111
0X0XX0
0X10X0
0X1100
100XX0
1010X0
101100
440 21 my $attr = HTML::DOM::Attr->new($name);
441 21 $attr->_set_ownerDocument($elem->ownerDocument);
442 21 $attr->_element($elem);
443 $attr->value($name eq 'version'
444 ? $elem->{_HTML_DOM_version}
445 21 ▶ : $attr_defaults{$tag}{$name});
Branch: 1 branch
BranchTrueFalseTotal
$name eq 'version' ? : 1 20 21
446 21 $attr;
447 };
448 }
449  
450 333 ▶ if(!ref $attr) {
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $attr) 299 34 333
451 299 $elem->attr($name, my $new_attr =
452 HTML::DOM::Attr->new($name, $attr));
453 299 $new_attr->_set_ownerDocument($elem->ownerDocument);
454 299 $new_attr->_element($elem);
455 299 return $new_attr;
456 }
457 34 $attr;
458 }
459  
460 sub setAttributeNode {
461 19 ▶ my $doc = $_[0]->ownerDocument;
Subroutine setAttributeNode: called CC=11 SCAR=24.8
Pod documented
462  
463 # Even if it’s already the same document, it’s actually
464 # quicker just to set it than to check first.
465 19 $_[1]->_set_ownerDocument($doc);
466  
467 19 my $e;
468 19 ▶ die HTML::DOM::Exception->new(INUSE_ATTRIBUTE_ERR,
Branch: 1 branch
BranchTrueFalseTotal
if defined($e = $_[1]->_element) and $e != $_[0] 1 18 19
Condition66%2/3
defined($e = $_[1]->_element) and $e != $_[0]
!ll&&!rl&&r
1801
MC/DC50%1/2
defined($e = $_[1]->_element) and $e != $_[0]
defined($e = $_[1]->_element) $e != $_[0]
Truth table66%2/3
A and B
A= defined($e = $_[1]->_element)B= $e != $_[0]
ABresult
0X0
100
111
469 'The attribute passed to setAttributeNode is in use')
470 if defined($e = $_[1]->_element) && $e != $_[0];
471  
472 18 my $old = $_[0]->attr(my $name = $_[1]->nodeName, $_[1]);
473 18 $_[1]->_element($_[0]);
474  
475 # possible event handler
476 18 ▶ if ($name =~ /^on(.*)/is and my $listener_maker = $_[0]->
Branch: 1 branch
BranchTrueFalseTotal
if ($name =~ /^on(.*)/is and my $listener_maker = $_[0]->ownerDocument->event_attr_handler) 0 18 18
Condition33%1/3
$name =~ /^on(.*)/is and my $listener_maker = $_[0]->ownerDocument->event_attr_handler
!ll&&!rl&&r
1800
MC/DC0%0/2
$name =~ /^on(.*)/is and my $listener_maker = $_[0]->ownerDocument->event_attr_handler
$name =~ /^on(.*)/is my $listener_maker = $_[0]->ownerDocument->event_attr_handler
Truth table33%1/3
A and B
A= $name =~ /^on(.*)/isB= my $listener_maker = $_[0]->ownerDocument->event_attr_handler
ABresult
0X0
100
111
477 ownerDocument->event_attr_handler) {
478 # ~~~ Is there a possibility that the listener-maker
479 # will have a reference to the old attr node, and
480 # that calling it when that attr still has an
481 # 'owner' element when it shouldn't will cause any
482 # problems? Yet I don't want to intertwine this
483 # section of code with the one below.
484 0 my $eavesdropper = &$listener_maker(
485 $_[0], $name = lc $1, $_[1]->nodeValue
486 );
487 0 ▶ defined $eavesdropper and $_[0]-> event_handler(
Branch: 1 branch
BranchTrueFalseTotal
defined $eavesdropper and $_[0]->event_handler($name, $eavesdropper) 0 0 0
488 $name, $eavesdropper
489 );
490 }
491  
492 18 my $ret;
493 18 ▶ if(defined $old) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) 10 8 18
494 10 ▶ if(defined blessed $old and $old->isa("HTML::DOM::Attr")) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined builtin::blessed($old) and $old->isa('HTML::DOM::Attr')) { } 9 1 10
Condition66%2/3
defined builtin::blessed($old) and $old->isa("HTML::DOM::Attr")
!ll&&!rl&&r
109
MC/DC50%1/2
defined builtin::blessed($old) and $old->isa("HTML::DOM::Attr")
defined builtin::blessed($old) $old->isa("HTML::DOM::Attr")
Truth table66%2/3
A and B
A= defined builtin::blessed($old)B= $old->isa("HTML::DOM::Attr")
ABresult
0X0
100
111
495 9 $old->_element(undef);
496 9 $ret = $old;
497 } else {
498 1 $ret =
499 HTML::DOM::Attr->new($name);
500 1 $ret->_set_ownerDocument($doc);
501 1 $ret->_element($_[0]);
502 1 $ret->value($old);
503 }
504 }
505  
506 18 ▶ defined $ret and $_[0]->trigger_event('DOMAttrModified',
Branch: 1 branch
BranchTrueFalseTotal
defined $ret and $_[0]->trigger_event("DOMAttrModified", "attr_name", $name, "attr_change_type", 3, "prev_value", ("new_value", ($ret->value) x 2)[-1..1], "rel_node", $ret) 10 8 18
507 attr_name => $name,
508 attr_change_type => 3,
509 prev_value =>
510 (new_value => ($ret->value) x 2)[-1..1],
511 rel_node => $ret,
512 );
513 18 $_[0]->trigger_event('DOMAttrModified',
514 attr_name => $_[1]->name,
515 attr_change_type => 2,
516 prev_value =>
517 (new_value => ($_[1]->value) x 2)[-1..1],
518 rel_node => $_[1],
519 );
520  
521 18 ▶ return $ret if defined $ret;
Branch: 1 branch
BranchTrueFalseTotal
if defined $ret 10 8 18
522  
523 return # nothing;
524 8 }
525  
526 sub removeAttributeNode {
527 11 ▶ my($elem,$attr) = @_;
Subroutine removeAttributeNode: called CC=4 SCAR=13.9
Pod documented
528  
529 11 my $old_val = $elem->attr(my $name = $attr->nodeName);
530 defined($old_val)
531 ? ref$old_val && refaddr $attr == refaddr $old_val
532 11 ▶ : exists $elem->{_HTML_DOM_unspecified}{$name}
Branch: 2 branches
BranchTrueFalseTotal
defined $old_val ? ref $old_val && builtin::refaddr($attr) == builtin::refaddr($old_val) : exists $elem->{"_HTML_DOM_unspecified"}{$name} or die "HTML::DOM::Exception"->new(8, "The node passed to removeAttributeNode is not an attribute of this element.") 3 8 11
defined $old_val ? : 9 2 11
Condition100%3/3
ref $old_val and builtin::refaddr($attr) == builtin::refaddr($old_val)
!ll&&!rl&&r
117
MC/DC100%2/2
ref $old_val and builtin::refaddr($attr) == builtin::refaddr($old_val)
ref $old_val builtin::refaddr($attr) == builtin::refaddr($old_val)
Truth table100%3/3
A and B
A= ref $old_valB= builtin::refaddr($attr) == builtin::refaddr($old_val)
ABresult
0X0
100
111
533 or die HTML::DOM::Exception->new(NOT_FOUND_ERR,
534 "The node passed to removeAttributeNode is not an " .
535 "attribute of this element.");
536  
537 8 $elem->attr($name, undef);
538 8 delete $elem->{_HTML_DOM_unspecified}{$name};
539 8 $attr->_element(undef);
540  
541 8 $elem->trigger_event('DOMAttrModified',
542 attr_name => $name,
543 attr_change_type => 3,
544 prev_value =>
545 (new_value => ($attr->value) x 2)[-1..1],
546 rel_node => $attr,
547 );
548  
549  
550 8 return $attr
551 }
552  
553  
554 sub getElementsByTagName {
555 10 ▶ my($self,$tagname) = @_;
Subroutine getElementsByTagName: called CC=4 SCAR=13.9
Pod documented
556 10 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 4 6 10
557 4 ▶ return $tagname eq '*'
Branch: 1 branch
BranchTrueFalseTotal
$tagname eq '*' ? : 1 3 4
558 ? grep tag $_ !~ /^~/, $self->descendants
559 : (
560 ($tagname = lc $tagname)[()],
561 grep tag $_ eq $tagname, $self->descendants
562 );
563 }
564 else {
565 my $list = HTML::DOM::NodeList::Magic->new(
566 $tagname eq '*'
567 2 ▶ ? sub { grep tag $_ !~ /^~/, $self->descendants }
Subroutine __ANON__: called CC=1 SCAR=0.0
568 : (
569 $tagname = lc $tagname,
570 sub {
571 9 ▶ grep tag $_ eq $tagname, $self->descendants
Subroutine __ANON__: called CC=1 SCAR=0.0
572 }
573 6 ▶ )[1]
Branch: 1 branch
BranchTrueFalseTotal
$tagname eq '*' ? : 1 5 6
574 );
575 6 $self->ownerDocument-> _register_magic_node_list($list);
576 6 $list;
577 }
578 }
579  
580 sub getElementsByClassName {
581 9 ▶ splice @_, 2; # Remove extra elements
Subroutine getElementsByClassName: called CC=1 SCAR=0.0
Pod documented
582 9 goto &_getElementsByClassName;
583 }
584 sub _getElementsByClassName {
585 18 ▶ my($self,$names,$is_doc) = @_;
Subroutine _getElementsByClassName: called CC=4 SCAR=13.9
586  
587 18 my $cref;
588 18 ▶ if(defined $names) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $names) { } 18 0 18
589 25 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
590 # The DOM spec says to skip *ASCII* whitespace, and defines it as:
591 # U+0009, U+000A, U+000C, U+000D, and U+0020
592 # \t \n \f \r
593 18 $names
594 = join ".*", map " $_ ", sort split /[ \t\n\f\r]+/, $names;
595 $cref = sub {
596 177 ▶ (" ".join(" ", sort split /[ \t\n\f\r]+/, $_[0]->attr('class'))
Subroutine __ANON__: called CC=1 SCAR=0.0
597 ." ")
598 =~ $names
599 18 };
600 }
601 0 ▶ else { $cref = sub {} }
Subroutine __ANON__: not called CC=1 SCAR=6.9
602  
603 18 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 14 4 18
604 14 return $self->look_down($cref);
605 }
606 else {
607 my $list = HTML::DOM::NodeList::Magic->new(
608 4 ▶ sub { $self->look_down($cref); }
Subroutine __ANON__: called CC=1 SCAR=0.0
609 4 );
610 4 ▶ ($is_doc ? $self : $self-> ownerDocument)
Branch: 1 branch
BranchTrueFalseTotal
$is_doc ? : 2 2 4
611 ->_register_magic_node_list($list);
612 4 $list;
613 }
614 }
615  
616 sub hasAttribute {
617 497 ▶ my ($self,$attrname)= (shift, lc shift);
Subroutine hasAttribute: called CC=6 SCAR=18.0
Pod documented
618 497 my $tag;
619 defined $self->attr($attrname)
620 or exists $attr_defaults{$tag = $self->tag}
621 and exists $attr_defaults{$tag}{$attrname}
622 or $tag eq 'html' and $attrname eq 'version'
623 and exists $self->{_HTML_DOM_version}
624 497 ▶}
Branch: 1 branch
BranchTrueFalseTotal
defined $self->attr($attrname) or exists $attr_defaults{$tag = $self->tag} and exists $attr_defaults{$tag}{$attrname} or $tag eq "html" and $attrname eq "version" and exists $self->{"_HTML_DOM_version"} 14 483 497
Condition86%13/15
defined $self->attr($attrname) || exists $attr_defaults{$tag = $self->tag} && exists $attr_defaults{$tag}{$attrname} || $tag eq 'html' && $attrname eq 'version' && exists $self->{'_HTML_DOM_version'}
l!l&&r!l&&!r
483113
defined $self->attr($attrname) or exists $attr_defaults{$tag = $self->tag} and exists $attr_defaults{$tag}{$attrname}
l!l&&r!l&&!r
482114
exists $attr_defaults{$tag = $self->tag} and exists $attr_defaults{$tag}{$attrname}
!ll&&!rl&&r
1311
$tag eq "html" and $attrname eq "version" and exists $self->{"_HTML_DOM_version"}
!ll&&!rl&&r
1301
$tag eq "html" and $attrname eq "version"
!ll&&!rl&&r
1301
MC/DC66%4/6
defined $self->attr($attrname) || exists $attr_defaults{$tag = $self->tag} && exists $attr_defaults{$tag}{$attrname} || $tag eq 'html' && $attrname eq 'version' && exists $self->{'_HTML_DOM_version'}
defined $self->attr($attrname) exists $attr_defaults{$tag = $self->tag} exists $attr_defaults{$tag}{$attrname} $tag eq "html" $attrname eq "version" exists $self->{"_HTML_DOM_version"}
Truth table50%5/10
A or B and C || D and E and F
A= defined $self->attr($attrname)B= exists $attr_defaults{$tag = $self->tag}C= exists $attr_defaults{$tag}{$attrname}D= $tag eq "html"E= $attrname eq "version"F= exists $self->{"_HTML_DOM_version"}
ABCDEFresult
1XXXXX1
011XXX1
00X1111
0101111
00X0XX0
00X10X0
00X1100
0100XX0
01010X0
0101100
625  
626 21 ▶sub _attr_specified { defined shift->attr(shift) }
Subroutine _attr_specified: called CC=1 SCAR=0.0
627  
628 2 ▶sub click { shift->trigger_event('click') }
Subroutine click: called CC=1 SCAR=0.0
Pod documented
629  
630 # used by innerHTML and insertAdjacentHTML
631 sub _html_fragment_parser {
632 30 ▶ require HTML'DOM; # paranoia
Subroutine _html_fragment_parser: called CC=2 SCAR=6.9
633 30 (my $tb = new HTML::DOM::Element::HTML:: no_magic_forms=>1)
634 ->_set_ownerDocument(shift->ownerDocument);
635 30 $tb->parse(shift);
636 30 $tb->eof();
637 30 $_->implicit(1) for $tb, $tb->content_list; # more paranoia
638 30 $tb;
639 }
640  
641 25 use constant _html_element_adds_newline =>
642 25 ▶ new HTML::DOM::_Element 'foo' =>->as_HTML =~ /\n/;
Subroutine BEGIN: called CC=1 SCAR=0.0
643  
644 sub innerHTML {
645 42 ▶ my $self = shift;
Subroutine innerHTML: called CC=6 SCAR=18.0
Pod undocumented
646 42 ▶ my $old = join '', map $_->nodeType==ELEMENT_NODE
Branch: 3 branches
BranchTrueFalseTotal
if defined wantarray 18 24 42
$_->nodeType == 1 ? : 33 9 42
&_html_element_adds_newline() ? : 0 33 33
647 ? _html_element_adds_newline
648 ? substr(
649 $_->as_HTML((undef)x2,{}),0,-1
650 )
651 : $_->as_HTML((undef)x2,{})
652 : encode_entities($_->data),$self->content_list
653 if defined wantarray;
654 42 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 25 17 42
655 25 my $tb = _html_fragment_parser($self,shift);
656 25 $self->delete_content;
657 25 $self->push_content($tb->guts);
658 25 ▶ {($self->ownerDocument||last)->_modified}
Condition50%1/2
$self->ownerDocument || (last)
l!l
250
MC/DC0%0/1
$self->ownerDocument || (last)
$self->ownerDocument
Truth table50%1/2
A
A= $self->ownerDocument
Aresult
11
00
659 }
660 42 $old;
661 }
662  
663 {
664 25 my %mm # method map
665 = qw(
666 beforebegin preinsert
667 afterend postinsert
668 afterbegin unshift_content
669 beforeend push_content
670 );
671  
672 sub insertAdjacentHTML {
673 5 ▶ my $elem = shift;
Subroutine insertAdjacentHTML: called CC=3 SCAR=11.1
Pod undocumented
674
675 die new HTML::DOM::Exception:: SYNTAX_ERR,
676 "$_[0]: invalid first argument to insertAdjacentHTML"
677 5 ▶ unless exists $mm{ my $where = lc $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $mm{my $where = lc $_[0]} 0 5 5
678
679 5 my $tb = _html_fragment_parser($elem,$_[1]);
680 5 $elem->${\$mm{$where}}(guts $tb);
681  
682 5 ▶ {($elem->ownerDocument||last)->_modified}
Condition50%1/2
$elem->ownerDocument || (last)
l!l
50
MC/DC0%0/1
$elem->ownerDocument || (last)
$elem->ownerDocument
Truth table50%1/2
A
A= $elem->ownerDocument
Aresult
11
00
683  
684 ()
685 5 }
686
687 sub insertAdjacentElement {
688 5 ▶ my $elem = shift;
Subroutine insertAdjacentElement: called CC=3 SCAR=11.2
Pod undocumented
689
690 die new HTML::DOM::Exception:: SYNTAX_ERR,
691 "$_[0]: invalid first argument to insertAdjacentElement"
692 5 ▶ unless exists $mm{ my $where = lc $_[0] };
Branch: 1 branch
BranchTrueFalseTotal
unless exists $mm{my $where = lc $_[0]} 0 5 5
693
694 5 $elem->${\$mm{$where}}($_[1]);
695  
696 5 ▶ {($elem->ownerDocument||last)->_modified}
Condition50%1/2
$elem->ownerDocument || (last)
l!l
50
MC/DC0%0/1
$elem->ownerDocument || (last)
$elem->ownerDocument
Truth table50%1/2
A
A= $elem->ownerDocument
Aresult
11
00
697  
698 ()
699 5 }
700 }
701  
702 25 sub innerText {
703 3 ▶ my $self = shift;
Subroutine innerText: called CC=4 SCAR=13.9
Pod undocumented
704 3 ▶ my $old = $self->as_text
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 3 0 3
705 if defined wantarray;
706 3 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 1 2 3
707 # The slow way (with removeChild instead of delete_content)
708 # in order to trigger mutation events. (This may change if
709 # there is a spec one day for innerText.)
710 1 $self->removeChild($_) for $self->childNodes;
711 1 $self->appendChild(
712 $self->ownerDocument->createTextNode(shift)
713 );
714 }
715 3 $old;
716 }
717  
718 sub starttag {
719 121 ▶ my $self = shift;
Subroutine starttag: called CC=1 SCAR=0.0
Pod undocumented
720 121 my $tag = $self->SUPER::starttag(@ _);
721 121 $tag =~ s/ \/>\z/>/;
722 121 $tag
723 }
724  
725 # ------- OVERRIDDEN NODE METHDOS ---------- #
726  
727 25 *nodeName = \&tagName;
728 25 *nodeType = \& ELEMENT_NODE;
729  
730 sub attributes {
731 8 ▶ my $self = shift;
Subroutine attributes: called CC=2 SCAR=7.1
Pod documented
732 $self->{_HTML_DOM_Element_map} ||=
733 8 ▶ HTML::DOM::NamedNodeMap->new($self);
Condition66%2/3
$self->{"_HTML_DOM_Element_map"} ||= "HTML::DOM::NamedNodeMap"->new($self)
l!l&&r!l&&!r
260
MC/DC0%0/2
$self->{"_HTML_DOM_Element_map"} ||= "HTML::DOM::NamedNodeMap"->new($self)
$self->{"_HTML_DOM_Element_map"} "HTML::DOM::NamedNodeMap"->new($self)
Truth table66%2/3
A ||= B
A= $self->{"_HTML_DOM_Element_map"}B= "HTML::DOM::NamedNodeMap"->new($self)
ABresult
1X1
011
000
734 }
735  
736  
737 sub cloneNode { # override of HTML::DOM::Node’s method
738 7 ▶ my $clown = shift->SUPER::cloneNode(@_);
Subroutine cloneNode: called CC=3 SCAR=11.0
Pod documented
739  
740 7 ▶ unless(shift) { # if it’s shallow
Branch: 1 branch
BranchTrueFalseTotal
unless (shift()) 3 4 7
741 # Flatten attr nodes, effectively cloning them:
742 3 $$clown{$_} = "$$clown{$_}" for grep !/^_/, keys %$clown;
743 3 delete $clown->{_HTML_DOM_Element_map};
744 } # otherwise clone takes care of this, so we don’t need to here
745 7 $clown;
746 }
747  
748 sub clone { # override of HTML::Element’s method; this is called
749 # recursively during a deep clone
750 173 ▶ my $clown = shift->SUPER::clone;
Subroutine clone: called CC=2 SCAR=6.9
Pod undocumented
751 173 $$clown{$_} = "$$clown{$_}" for grep !/^_/, keys %$clown;
752 173 delete $clown->{_HTML_DOM_Element_map};
753 173 $clown;
754 }
755  
756 sub trigger_event {
757 1548 ▶ my ($a,$evnt) = (shift,shift);
Subroutine trigger_event: called CC=2 SCAR=6.9
Pod documented
758 $a->SUPER::trigger_event(
759 $evnt,
760 click_default =>sub {
761 $_[0]->target->trigger_event(DOMActivate =>
762 16 ▶ detail => eval{$_[0]->detail}
Subroutine __ANON__: called CC=1 SCAR=0.0
763 );;
764 },
765 # We check magic_forms before adding this for efficiency’s
766 # sake: so as not to burden well-formed documents with
767 # the extra overhead of auto-vivving an event object
768 # unnecessarily.
769 $a->ownerDocument->magic_forms ? (
770 DOMNodeRemoved_default => sub {
771 58 ▶ my $targy = $_[0]->target;
Subroutine __ANON__: called CC=2 SCAR=6.9
772 58 for($targy, $targy->descendants) {
773 271 eval { $_->form(undef) };
774 }
775 58 return; # give the eval void context
776 },
777 1548 ▶ ) : (),
Branch: 1 branch
BranchTrueFalseTotal
$a->ownerDocument->magic_forms ? : 1548 0 1548
778 @_,
779 );
780 }
781  
782  
783 =head1 SEE ALSO
784  
785 L<HTML::DOM>
786  
787 L<HTML::DOM::Node>
788  
789 L<HTML::Element>
790  
791 All the HTML::DOM::Element subclasses listed under
792 L<HTML::DOM/CLASSES AND DOM INTERFACES>
793  
794 =cut
795  
796  
797 # ------- HTMLHtmlElement interface ---------- #
798 # This has been moved to DOM.pm.
799  
800 # ------- HTMLHeadElement interface ---------- #
801  
802 package HTML::DOM::Element::Head;
803 25 our $VERSION = '0.057';
804 25 our @ISA = 'HTML::DOM::Element';
805 5 ▶sub profile { shift->_attr('profile' => @_) }
Subroutine profile: called CC=1 SCAR=0.0
806  
807 # ------- HTMLLinkElement interface ---------- #
808  
809 package HTML::DOM::Element::Link;
810 25 our $VERSION = '0.057';
811 25 our @ISA = 'HTML::DOM::Element';
812 25 ▶use Scalar::Util 'blessed';
Subroutine BEGIN: called CC=1 SCAR=0.0
813 sub disabled {
814 6 ▶ if(@_ > 1) {
Subroutine disabled: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 2 4 6
815 2 my $old = $_[0]->{_HTML_DOM_disabled};
816 2 $_[0]->{_HTML_DOM_disabled} = $_[1];
817 2 return $old;
818 }
819 4 else { $_[0]->{_HTML_DOM_disabled};}
820 }
821 15 ▶sub charset { shift->_attr('charset' => @_) }
Subroutine charset: called CC=1 SCAR=0.0
822 43 ▶sub href { shift->_attr('href' => @_) }
Subroutine href: called CC=1 SCAR=0.0
823 10 ▶sub hreflang { shift->_attr( hreflang => @_) }
Subroutine hreflang: called CC=1 SCAR=0.0
824 10 ▶sub media { shift->_attr('media' => @_) }
Subroutine media: called CC=1 SCAR=0.0
825 10 ▶sub rel { shift->_attr('rel' => @_) }
Subroutine rel: called CC=1 SCAR=0.0
826 10 ▶sub rev { shift->_attr('rev' => @_) }
Subroutine rev: called CC=1 SCAR=0.0
827 20 ▶sub target { shift->_attr('target' => @_) }
Subroutine target: called CC=1 SCAR=0.0
828 40 ▶sub type { shift->_attr('type' => @_) }
Subroutine type: called CC=1 SCAR=0.0
829  
830 sub sheet {
831 40 ▶ my $self = shift;
Subroutine sheet: called CC=4 SCAR=13.9
832 25 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
833 40 ▶ $self->attr('rel') =~
Branch: 1 branch
BranchTrueFalseTotal
$self->attr("rel") =~ /(?:^|\p{IsSpacePerl})stylesheet(?:\z|\p{IsSpacePerl})/i or return 24 16 40
834 /(?:^|\p{IsSpacePerl})stylesheet(?:\z|\p{IsSpacePerl})/i
835 or return;
836  
837 16 my $old = $$self{_HTML_DOM_sheet};
838 16 ▶ @_ and $self->{_HTML_DOM_sheet} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"_HTML_DOM_sheet"} = shift() 4 12 16
839 16 ▶ $old||(); }
Branch: 1 branch
BranchTrueFalseTotal
$old or () 4 12 16
840  
841 # I need to override these four to update the document’s style sheet list.
842 # ~~~ These could be made more efficient if they checked the attribute
843 # name first, to avoid unnecessary method calls.
844 sub setAttribute {
845 29 ▶ for(shift) {
Subroutine setAttribute: called CC=2 SCAR=6.9
846 29 $_->SUPER::setAttribute(@_);
847 29 $_->ownerDocument->_populate_sheet_list;
848 }
849 return # nothing;
850 29 }
851 sub removeAttribute {
852 1 ▶ for(shift) {
Subroutine removeAttribute: called CC=2 SCAR=6.9
853 1 $_->SUPER::removeAttribute(@_);
854 1 $_->ownerDocument->_populate_sheet_list
855 }
856 return # nothing;
857 1 }
858 sub setAttributeNode {
859 3 ▶ (my $self = shift)->SUPER::setAttributeNode(@_);
Subroutine setAttributeNode: called CC=1 SCAR=0.0
860 3 $self->ownerDocument->_populate_sheet_list;
861 return # nothing;
862 3 }
863 sub removeAttributeNode {
864 1 ▶ my $self = shift;
Subroutine removeAttributeNode: called CC=1 SCAR=0.0
865 1 my $attr = $self->SUPER::removeAttributeNode(@_);
866 1 $self->ownerDocument->_populate_sheet_list;
867 1 $attr
868 }
869  
870 sub trigger_event {
871 # ~~~ This defeats the purpose of having an auto-viv sub. I need to do
872 # some rethinking....
873 38 ▶ my $elem = shift;
Subroutine trigger_event: called CC=8 SCAR=27.2
874 38 ▶ if(defined blessed $_[0] and $_[0]->isa("HTML::DOM::Event")) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined builtin::blessed($_[0]) and $_[0]->isa('HTML::DOM::Event')) { } 0 38 38
elsif (not $_[0] =~ /^domattrmodified\z/i) { } 0 38 38
Condition33%1/3
defined builtin::blessed($_[0]) and $_[0]->isa("HTML::DOM::Event")
!ll&&!rl&&r
3800
MC/DC0%0/2
defined builtin::blessed($_[0]) and $_[0]->isa("HTML::DOM::Event")
defined builtin::blessed($_[0]) $_[0]->isa("HTML::DOM::Event")
Truth table33%1/3
A and B
A= defined builtin::blessed($_[0])B= $_[0]->isa("HTML::DOM::Event")
ABresult
0X0
100
111
875 0 ▶ return $elem->SUPER::trigger_event(@_)
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0]->type =~ /^domattrmodified\z/i 0 0 0
876 unless $_[0]->type =~ /^domattrmodified\z/i;
877 0 my $attr_name = $_[0]->attrName;
878 0 ▶ if($attr_name eq 'href') { _reset_style_sheet($elem) }
Branch: 1 branch
BranchTrueFalseTotal
if ($attr_name eq "href") 0 0 0
879 }
880 elsif($_[0] !~ /^domattrmodified\z/i) {
881 0 return $elem->SUPER::trigger_event(@_);
882 }
883 else {
884 38 my($event,%args) = @_;
885 38 ▶ $args{auto_viv} and %args = &{$args{auto_viv}}, @_ = ($event, %args);
Branch: 1 branch
BranchTrueFalseTotal
$args{"auto_viv"} and %args = &{$args{"auto_viv"};}, @_ = ($event, %args) 19 19 38
886 38 ▶ $args{attr_name} eq 'href' and _reset_style_sheet($elem);
Branch: 1 branch
BranchTrueFalseTotal
$args{"attr_name"} eq "href" and _reset_style_sheet($elem) 5 33 38
887 }
888 38 SUPER'trigger_event $elem @_;
889 }
890  
891 sub _reset_style_sheet {
892 21 ▶ my $elem = shift;
Subroutine _reset_style_sheet: called CC=7 SCAR=20.1
893 return
894 21 ▶ unless ($elem->attr('rel')||'')
Branch: 1 branch
BranchTrueFalseTotal
unless ($elem->attr("rel") || "") =~ /(?:^|\p{IsSpacePerl})stylesheet(?:\z|\p{IsSpacePerl})/i 14 7 21
Condition100%2/2
$elem->attr('rel') || ''
l!l
174
MC/DC100%1/1
$elem->attr('rel') || ''
$elem->attr('rel')
Truth table100%2/2
A
A= $elem->attr('rel')
Aresult
11
00
895 =~ /(?:^|\p{IsSpacePerl})stylesheet(?:\z|\p{IsSpacePerl})/i;
896 7 my $doc = $elem->ownerDocument;
897 7 ▶ return unless my $fetcher = $doc->css_url_fetcher;
Branch: 1 branch
BranchTrueFalseTotal
unless my $fetcher = $doc->css_url_fetcher 2 5 7
898 5 my $base = $doc->base;
899 5 ▶ my $url = defined $base
Branch: 1 branch
BranchTrueFalseTotal
defined $base ? : 0 5 5
900 ? new_abs URI
901 $elem->href, $doc->base
902 : $elem->href;
903 5 my ($css_code, %args)
904 = $fetcher->($url);
905 5 ▶ return unless defined $css_code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $css_code 1 4 5
906 4 require CSS'DOM;
907 4 VERSION CSS'DOM 0.03;
908 4 ▶ my $hint
Condition50%1/2
$doc->charset || 'iso-8859-1'
l!l
04
MC/DC0%0/1
$doc->charset || 'iso-8859-1'
$doc->charset
Truth table50%1/2
A
A= $doc->charset
Aresult
11
00
909 = $doc->charset || 'iso-8859-1';
910 # default HTML charset
911 $elem->sheet(
912 # ’Tis true we create a new clo-
913 # sure for each style sheet, but
914 # what if the charset changes?
915 # ~~~ Is that even possible?
916 CSS'DOM'parse(
917 $css_code,
918 url_fetcher => sub {
919 0 ▶ my @ret = $fetcher->(shift);
Subroutine __ANON__: not called CC=2 SCAR=17.9
920 @ret
921 0 ▶ ? (
Branch: 1 branch
BranchTrueFalseTotal
@ret ? : 0 0 0
922 $ret[0],
923 encoding_hint => $hint,
924 @ret[1..$#ret]
925 ) : ()
926 },
927 4 encoding_hint => $hint,
928 %args
929 )
930 );
931 }
932  
933 # ------- HTMLTitleElement interface ---------- #
934  
935 package HTML::DOM::Element::Title;
936 25 our $VERSION = '0.057';
937 25 our @ISA = 'HTML::DOM::Element';
938 # This is what I call FWP (no lexical vars):
939 sub text {
940 17 ▶ ($_[0]->firstChild or
Subroutine text: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
@_ > 1 and $_[0]->appendChild((shift())->ownerDocument->createTextNode(shift())) 3 3 6
Condition66%2/3
$_[0]->firstChild || (@_ > 1 && $_[0]->appendChild((shift())->ownerDocument->createTextNode(shift())), (return ''))
l!l&&r!l&&!r
1160
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
941 @_ > 1 && $_[0]->appendChild(
942 shift->ownerDocument->createTextNode(shift)
943 ),
944 return '',
945 )->data(@_[1..$#_]);
946 }
947  
948 # ------- HTMLMetaElement interface ---------- #
949  
950 package HTML::DOM::Element::Meta;
951 25 our $VERSION = '0.057';
952 25 our @ISA = 'HTML::DOM::Element';
953 5 ▶sub content { shift->_attr('content' => @_) }
Subroutine content: called CC=1 SCAR=0.0
954 5 ▶sub httpEquiv { shift->_attr('http-equiv' => @_) }
Subroutine httpEquiv: called CC=1 SCAR=0.0
955 45 ▶sub name { shift->_attr('name' => @_) }
Subroutine name: called CC=1 SCAR=0.0
956 5 ▶sub scheme { shift->_attr('scheme' => @_) }
Subroutine scheme: called CC=1 SCAR=0.0
957  
958 # ------- HTMLBaseElement interface ---------- #
959  
960 package HTML::DOM::Element::Base;
961 25 our $VERSION = '0.057';
962 25 our @ISA = 'HTML::DOM::Element';
963 25 *href =\& HTML::DOM::Element::Link::href;
964 25 *target =\& HTML::DOM::Element::Link::target;
965  
966 # ------- HTMLIsIndexElement interface ---------- #
967  
968 package HTML::DOM::Element::IsIndex;
969 25 our $VERSION = '0.057';
970 25 our @ISA = 'HTML::DOM::Element';
971 2 ▶sub form { (shift->look_up(_tag => 'form'))[0] || () }
Subroutine form: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
((shift())->look_up("_tag", "form"))[0] or () 1 1 2
972 # ~~~ Should this be the same as Select::form? I.e., should isindex ele-
973 # ments get magic form associations?
974 5 ▶sub prompt { shift->_attr('prompt' => @_) }
Subroutine prompt: called CC=1 SCAR=0.0
975  
976 # ------- HTMLStyleElement interface ---------- #
977  
978 package HTML::DOM::Element::Style;
979 25 our $VERSION = '0.057';
980 25 our @ISA = 'HTML::DOM::Element';
981 25 *disabled = \&HTML::DOM::Element::Link::disabled;
982 25 *media =\& HTML::DOM::Element::Link::media;
983 25 *type =\& HTML::DOM::Element::Link::type;
984  
985 sub sheet {
986 15 ▶ my $self = shift;
Subroutine sheet: called CC=3 SCAR=11.1
987 15 ▶ $self->{_HTML_DOM_sheet} ||= do{
Condition66%2/3
$self->{"_HTML_DOM_sheet"} ||= do { my $first_child = $self->firstChild; local *@; require CSS::DOM; "CSS::DOM"->VERSION("0.03"); CSS::DOM::parse($first_child ? $first_child->data : "") }
l!l&&r!l&&!r
1140
MC/DC0%0/2
$self->{"_HTML_DOM_sheet"} ||= do { my $first_child = $self->firstChild; local *@; require CSS::DOM; "CSS::DOM"->VERSION("0.03"); CSS::DOM::parse($first_child ? $first_child->data : "") }
$self->{"_HTML_DOM_sheet"} do { my $first_child = $self->firstChild; local *@; require CSS::DOM; "CSS::DOM"->VERSION("0.03"); CSS::DOM::parse($first_child ? $first_child->data : "") }
Truth table66%2/3
A ||= B
A= $self->{"_HTML_DOM_sheet"}B= do { my $first_child = $self->firstChild; local *@; require CSS::DOM; "CSS::DOM"->VERSION("0.03"); CSS::DOM::parse($first_child ? $first_child->data : "") }
ABresult
1X1
011
000
988 4 my $first_child = $self->firstChild;
989 4 local *@;
990 4 require CSS::DOM;
991 4 VERSION CSS::DOM .03;
992 4 ▶ CSS::DOM::parse($first_child?$first_child->data:'');
Branch: 1 branch
BranchTrueFalseTotal
$first_child ? : 4 0 4
993 };
994 }
995  
996 # ------- HTMLBodyElement interface ---------- #
997  
998 package HTML::DOM::Element::Body;
999 25 our $VERSION = '0.057';
1000 25 our @ISA = 'HTML::DOM::Element';
1001 7 ▶sub aLink { shift->_attr( aLink => @_) }
Subroutine aLink: called CC=1 SCAR=0.0
1002 7 ▶sub background { shift->_attr( background => @_) }
Subroutine background: called CC=1 SCAR=0.0
1003 7 ▶sub bgColor { shift->_attr('bgcolor' => @_) }
Subroutine bgColor: called CC=1 SCAR=0.0
1004 7 ▶sub link { shift->_attr('link' => @_) }
Subroutine link: called CC=1 SCAR=0.0
1005 7 ▶sub text { shift->_attr('text' => @_) }
Subroutine text: called CC=1 SCAR=0.0
1006 7 ▶sub vLink { shift->_attr('vlink' => @_) }
Subroutine vLink: called CC=1 SCAR=0.0
1007 sub event_handler {
1008 4 ▶ my $self = shift;
Subroutine event_handler: called CC=2 SCAR=6.9
1009 4 my $target = $self->ownerDocument->event_parent;
1010 4 ▶ $target
Branch: 1 branch
BranchTrueFalseTotal
$target ? : 1 3 4
1011 ? $target->event_handler(@_)
1012 : $self->SUPER::event_handler(@_);
1013 }
1014  
1015 # ------- HTMLFormElement interface ---------- #
1016  
1017 # See Element/Form.pm
1018  
1019 # ~~~ list other form things here for reference
1020  
1021 # ------- HTMLUListElement interface ---------- #
1022  
1023 package HTML::DOM::Element::UL;
1024 25 our $VERSION = '0.057';
1025 25 our @ISA = 'HTML::DOM::Element';
1026 30 ▶sub compact { shift->_attr( compact => @_ ? $_[0]?'compact': undef : () ) }
Subroutine compact: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 20 10 30
$_[0] ? : 11 9 20
1027 5 ▶sub type { lc shift->_attr( type => @_) }
Subroutine type: called CC=1 SCAR=0.0
1028  
1029 # ------- HTMLOListElement interface ---------- #
1030  
1031 package HTML::DOM::Element::OL;
1032 25 our $VERSION = '0.057';
1033 25 our @ISA = 'HTML::DOM::Element';
1034 5 ▶sub start { shift->_attr( start => @_) }
Subroutine start: called CC=1 SCAR=0.0
1035 25 *compact=\&HTML::DOM::Element::UL::compact;
1036 25 * type = \ & HTML::DOM::Element::Link::type ;
1037  
1038 # ------- HTMLDListElement interface ---------- #
1039  
1040 package HTML::DOM::Element::DL;
1041 25 our $VERSION = '0.057';
1042 25 our @ISA = 'HTML::DOM::Element';
1043 25 *compact=\&HTML::DOM::Element::UL::compact;
1044  
1045 # ------- HTMLDirectoryElement interface ---------- #
1046  
1047 package HTML::DOM::Element::Dir;
1048 25 our $VERSION = '0.057';
1049 25 our @ISA = 'HTML::DOM::Element';
1050 25 *compact=\&HTML::DOM::Element::UL::compact;
1051  
1052 # ------- HTMLMenuElement interface ---------- #
1053  
1054 package HTML::DOM::Element::Menu;
1055 25 our $VERSION = '0.057';
1056 25 our @ISA = 'HTML::DOM::Element';
1057 25 *compact=\&HTML::DOM::Element::UL::compact;
1058  
1059 # ------- HTMLLIElement interface ---------- #
1060  
1061 package HTML::DOM::Element::LI;
1062 25 our $VERSION = '0.057';
1063 25 our @ISA = 'HTML::DOM::Element';
1064 25 *type =\& HTML::DOM::Element::Link::type;
1065 10 ▶sub value { shift->_attr( value => @_) }
Subroutine value: called CC=1 SCAR=0.0
1066  
1067 # ------- HTMLDivElement interface ---------- #
1068  
1069 package HTML::DOM::Element::Div;
1070 25 our $VERSION = '0.057';
1071 25 our @ISA = 'HTML::DOM::Element';
1072 40 ▶sub align { lc shift->_attr( align => @_) }
Subroutine align: called CC=1 SCAR=0.0
1073  
1074 # ------- HTMLParagraphElement interface ---------- #
1075  
1076 package HTML::DOM::Element::P;
1077 25 our $VERSION = '0.057';
1078 25 our @ISA = 'HTML::DOM::Element';
1079 25 *align =\& HTML::DOM::Element::Div::align;
1080  
1081 # ------- HTMLHeadingElement interface ---------- #
1082  
1083 package HTML::DOM::Element::Heading;
1084 25 our $VERSION = '0.057';
1085 25 our @ISA = 'HTML::DOM::Element';
1086 25 *align =\& HTML::DOM::Element::Div::align;
1087  
1088 # ------- HTMLQuoteElement interface ---------- #
1089  
1090 package HTML::DOM::Element::Quote;
1091 25 our $VERSION = '0.057';
1092 25 our @ISA = 'HTML::DOM::Element';
1093 10 ▶sub cite { shift->_attr( cite => @_) }
Subroutine cite: called CC=1 SCAR=0.0
1094  
1095 # ------- HTMLPreElement interface ---------- #
1096  
1097 package HTML::DOM::Element::Pre;
1098 25 our $VERSION = '0.057';
1099 25 our @ISA = 'HTML::DOM::Element';
1100 30 ▶sub width { shift->_attr( width => @_) }
Subroutine width: called CC=1 SCAR=0.0
1101  
1102 # ------- HTMLBRElement interface ---------- #
1103  
1104 package HTML::DOM::Element::Br;
1105 25 our $VERSION = '0.057';
1106 25 our @ISA = 'HTML::DOM::Element';
1107 5 ▶sub clear { lc shift->_attr( clear => @_) }
Subroutine clear: called CC=1 SCAR=0.0
1108  
1109 # ------- HTMLBaseFontElement interface ---------- #
1110  
1111 package HTML::DOM::Element::BaseFont;
1112 25 our $VERSION = '0.057';
1113 25 our @ISA = 'HTML::DOM::Element';
1114 10 ▶sub color { shift->_attr( color => @_) }
Subroutine color: called CC=1 SCAR=0.0
1115 10 ▶sub face { shift->_attr( face => @_) }
Subroutine face: called CC=1 SCAR=0.0
1116 15 ▶sub size { shift->_attr( size => @_) }
Subroutine size: called CC=1 SCAR=0.0
1117  
1118 # ------- HTMLBaseFontElement interface ---------- #
1119  
1120 package HTML::DOM::Element::Font;
1121 25 our $VERSION = '0.057';
1122 25 our @ISA = 'HTML::DOM::Element';
1123 25 *color =\& HTML::DOM::Element::BaseFont::color;
1124 25 *face =\& HTML::DOM::Element::BaseFont::face;
1125 25 *size =\& HTML::DOM::Element::BaseFont::size;
1126  
1127 # ------- HTMLHRElement interface ---------- #
1128  
1129 package HTML::DOM::Element::HR;
1130 25 our $VERSION = '0.057';
1131 25 our @ISA = 'HTML::DOM::Element';
1132 25 *align =\& HTML::DOM::Element::Div::align;
1133 6 ▶sub noShade { shift->_attr( noshade => @_ ? $_[0]?'noshade':undef : () ) }
Subroutine noShade: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 4 2 6
$_[0] ? : 2 2 4
1134  
1135 25 *size =\& HTML::DOM::Element::BaseFont::size;
1136 25 *width =\& HTML::DOM::Element::Pre::width;
1137  
1138 # ------- HTMLModElement interface ---------- #
1139  
1140 package HTML::DOM::Element::Mod;
1141 25 our $VERSION = '0.057';
1142 25 our @ISA = 'HTML::DOM::Element';
1143 25 *cite =\& HTML::DOM::Element::Quote::cite;
1144 5 ▶sub dateTime { shift->_attr( datetime => @_) }
Subroutine dateTime: called CC=1 SCAR=0.0
1145  
1146 # ------- HTMLAnchorElement interface ---------- #
1147  
1148 package HTML::DOM::Element::A;
1149 25 our $VERSION = '0.057';
1150 25 our @ISA = 'HTML::DOM::Element';
1151 10 ▶sub accessKey { shift->_attr( accesskey => @_) }
Subroutine accessKey: called CC=1 SCAR=0.0
1152 25 * charset =\&HTML::DOM::Element::Link::charset ;
1153 25 * coords =\&HTML::DOM::Element::Area::coords ;
1154 25 * href =\&HTML::DOM::Element::Link::href ;
1155 25 * hreflang =\&HTML::DOM::Element::Link::hreflang ;
1156 25 * name =\&HTML::DOM::Element::Meta::name ;
1157 25 * rel =\&HTML::DOM::Element::Link::rel ;
1158 25 * rev =\&HTML::DOM::Element::Link::rev ;
1159 10 ▶sub shape { shift->_attr( shape => @_) }
Subroutine shape: called CC=1 SCAR=0.0
1160 25 * tabIndex =\&HTML::DOM::Element::Object::tabIndex ;
1161 25 * target =\&HTML::DOM::Element::Link::target ;
1162 25 * type =\&HTML::DOM::Element::Link::type ;
1163  
1164 1 ▶sub blur { shift->trigger_event('blur') }
Subroutine blur: called CC=1 SCAR=0.0
1165 1 ▶sub focus { shift->trigger_event('focus') }
Subroutine focus: called CC=1 SCAR=0.0
1166  
1167 sub trigger_event {
1168 119 ▶ my ($a,$evnt) = (shift,shift);
Subroutine trigger_event: called CC=1 SCAR=0.0
1169 119 $a->SUPER::trigger_event(
1170 $evnt,
1171 DOMActivate_default =>
1172 $a->ownerDocument->
1173 default_event_handler_for('link')
1174 ,
1175 @_,
1176 );
1177 }
1178  
1179 sub _get_abs_href {
1180 128 ▶ my $elem = shift;
Subroutine _get_abs_href: called CC=4 SCAR=13.9
1181 128 my $uri = new URI $elem->attr('href');
1182 128 ▶ if(!$uri->scheme) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($uri->scheme) 90 38 128
1183 90 my $base = $elem->ownerDocument->base;
1184 90 ▶ return unless $base;
Branch: 1 branch
BranchTrueFalseTotal
unless $base 84 6 90
1185 6 $uri = $uri->abs($base);
1186 6 ▶ return unless $uri->scheme;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri->scheme 0 6 6
1187 }
1188 $uri
1189 44 }
1190  
1191 sub hash {
1192 18 ▶ my $elem = shift;
Subroutine hash: called CC=6 SCAR=17.9
1193 18 ▶ defined(my $uri = _get_abs_href $elem) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined(my $uri = _get_abs_href($elem)) or return "" 12 6 18
1194 6 my $old;
1195 6 ▶ if(defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 6 0 6
1196 6 $old = $uri->fragment;
1197 6 ▶ $old = "#$old" if defined $old;
Branch: 1 branch
BranchTrueFalseTotal
if defined $old 2 4 6
1198 }
1199 6 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 4 6
1200 2 shift() =~ /#?(.*)/s;
1201 2 $uri->fragment($1);
1202 2 $elem->_attr(href => $uri);
1203 }
1204 6 ▶ $old||''
Branch: 1 branch
BranchTrueFalseTotal
$old or "" 4 2 6
1205 }
1206  
1207 sub host {
1208 18 ▶ my $elem = shift;
Subroutine host: called CC=4 SCAR=13.9
1209 18 ▶ defined(my $uri = _get_abs_href $elem) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined(my $uri = _get_abs_href($elem)) or return "" 12 6 18
1210 6 ▶ my $old = $uri->host_port if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 6 0 6
1211 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 4 6
1212 2 $uri->port("");
1213 2 $uri->host_port(shift);
1214 2 $elem->attr(href => $uri);
1215 }
1216 $old
1217 6 }
1218  
1219 sub hostname {
1220 18 ▶ my $elem = shift;
Subroutine hostname: called CC=4 SCAR=13.9
1221 18 ▶ defined(my $uri = _get_abs_href $elem) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined(my $uri = _get_abs_href($elem)) or return "" 12 6 18
1222 6 ▶ my $old = $uri->host if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 6 0 6
1223 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 4 6
1224 2 $uri->host(shift);
1225 2 $elem->attr(href => $uri);
1226 }
1227 $old
1228 6 }
1229  
1230 sub pathname {
1231 18 ▶ my $elem = shift;
Subroutine pathname: called CC=4 SCAR=13.9
1232 18 ▶ defined(my $uri = _get_abs_href $elem) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined(my $uri = _get_abs_href($elem)) or return "" 12 6 18
1233 6 ▶ my $old = $uri->path if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 6 0 6
1234 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 4 6
1235 2 $uri->path(shift);
1236 2 $elem->attr(href => $uri);
1237 }
1238 $old
1239 6 }
1240  
1241 sub port {
1242 18 ▶ my $elem = shift;
Subroutine port: called CC=4 SCAR=13.9
1243 18 ▶ defined(my $uri = _get_abs_href $elem) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined(my $uri = _get_abs_href($elem)) or return "" 12 6 18
1244 6 ▶ my $old = $uri->port if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 6 0 6
1245 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 4 6
1246 2 $uri->port(shift);
1247 2 $elem->attr(href => $uri);
1248 }
1249 $old
1250 6 }
1251  
1252 sub protocol {
1253 18 ▶ my $elem = shift;
Subroutine protocol: called CC=4 SCAR=13.9
1254 18 ▶ defined(my $uri = _get_abs_href $elem) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined(my $uri = _get_abs_href($elem)) or return "" 12 6 18
1255 6 ▶ my $old = $uri->scheme . ':' if defined wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if defined wantarray 6 0 6
1256 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 2 4 6
1257 2 shift() =~ /(.*):?/s;
1258 2 $uri->scheme("$1");
1259 2 $elem->attr(href => $uri);
1260 }
1261 $old
1262  
1263 6 }
1264  
1265 sub search {
1266 20 ▶ my $elem = shift;
Subroutine search: called CC=7 SCAR=19.6
1267 20 ▶ defined(my $uri = _get_abs_href $elem) or return '';
Branch: 1 branch
BranchTrueFalseTotal
defined(my $uri = _get_abs_href($elem)) or return "" 12 8 20
1268 8 my $old;
1269 8 ▶ if(defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 6 2 8
1270 6 my $q = $uri->query;
1271 6 ▶ $old = defined $q ? "?$q" : "";
Branch: 1 branch
BranchTrueFalseTotal
defined $q ? : 2 4 6
1272 }
1273 8 ▶ if (@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 4 8
1274 4 shift() =~ /(\??)(.*)/s;
1275 4 ▶ $uri->query(
Branch: 1 branch
BranchTrueFalseTotal
$1 || length $2 ? : 4 0 4
Condition33%1/3
$1 or length $2
l!l&&r!l&&!r
400
MC/DC0%0/2
$1 or length $2
$1 length $2
Truth table33%1/3
A or B
A= $1B= length $2
ABresult
1X1
011
000
1276 $1||length$2 ? "$2" : undef
1277 );
1278 4 $elem->attr(href => $uri);
1279 }
1280 $old
1281 8 }
1282  
1283  
1284 # ------- HTMLImageElement interface ---------- #
1285  
1286 package HTML::DOM::Element::Img;
1287 25 our $VERSION = '0.057';
1288 25 our @ISA = 'HTML::DOM::Element';
1289 0 ▶sub lowSrc { shift->attr( lowsrc => @_) }
Subroutine lowSrc: not called CC=1 SCAR=6.9
1290 25 * name = \&HTML::DOM::Element::Meta::name ;
1291 25 * align = \&HTML::DOM::Element::Div::align ;
1292 15 ▶sub alt { shift->_attr( alt => @_) }
Subroutine alt: called CC=1 SCAR=0.0
1293 5 ▶sub border { shift->_attr( border => @_) }
Subroutine border: called CC=1 SCAR=0.0
1294 20 ▶sub height { shift->_attr( height => @_) }
Subroutine height: called CC=1 SCAR=0.0
1295 15 ▶sub hspace { shift->_attr( hspace => @_) }
Subroutine hspace: called CC=1 SCAR=0.0
1296 6 ▶sub isMap { shift->_attr( ismap => @_ ? $_[0] ? 'ismap' : undef : () ) }
Subroutine isMap: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 4 2 6
$_[0] ? : 2 2 4
1297 5 ▶sub longDesc { shift->_attr( longdesc => @_) }
Subroutine longDesc: called CC=1 SCAR=0.0
1298 20 ▶sub src { shift->_attr( src => @_) }
Subroutine src: called CC=1 SCAR=0.0
1299 10 ▶sub useMap { shift->_attr( usemap => @_) }
Subroutine useMap: called CC=1 SCAR=0.0
1300 15 ▶sub vspace { shift->_attr( vspace => @_) }
Subroutine vspace: called CC=1 SCAR=0.0
1301 25 * width = \&HTML::DOM::Element::Pre::width ;
1302  
1303 # ------- HTMLObjectElement interface ---------- #
1304  
1305 package HTML::DOM::Element::Object;
1306 25 our $VERSION = '0.057';
1307 25 our @ISA = 'HTML::DOM::Element';
1308 25 *form=\&HTML::DOM::Element::Select::form;
1309 10 ▶sub code { shift->_attr( code => @_) }
Subroutine code: called CC=1 SCAR=0.0
1310 25 * align = \&HTML::DOM::Element::Div::align ;
1311 10 ▶sub archive { shift->_attr( archive => @_) }
Subroutine archive: called CC=1 SCAR=0.0
1312 5 ▶sub border { shift->_attr( border => @_) }
Subroutine border: called CC=1 SCAR=0.0
1313 10 ▶sub codeBase { shift->_attr( codebase => @_) }
Subroutine codeBase: called CC=1 SCAR=0.0
1314 5 ▶sub codeType { shift->_attr( codetype => @_) }
Subroutine codeType: called CC=1 SCAR=0.0
1315 5 ▶sub data { shift->_attr( data => @_) }
Subroutine data: called CC=1 SCAR=0.0
1316 6 ▶sub declare { shift->_attr( declare => @_ ? $_[0]?'declare':undef : () ) }
Subroutine declare: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 4 2 6
$_[0] ? : 2 2 4
1317 25 * height = \&HTML::DOM::Element::Img::height ;
1318 25 * hspace = \&HTML::DOM::Element::Img::hspace ;
1319 25 * name = \&HTML::DOM::Element::Meta::name ;
1320 5 ▶sub standby { shift->_attr( standby => @_) }
Subroutine standby: called CC=1 SCAR=0.0
1321 15 ▶sub tabIndex { shift->_attr( tabindex => @_) }
Subroutine tabIndex: called CC=1 SCAR=0.0
1322 25 *type =\& HTML::DOM::Element::Link::type;
1323 25 *useMap =\& HTML::DOM::Element::Img::useMap;
1324 25 *vspace =\& HTML::DOM::Element::Img::vspace;
1325 25 * width = \&HTML::DOM::Element::Pre::width ;
1326 ▶sub contentDocument{}
Subroutine contentDocument: called CC=1 SCAR=0.0
1327  
1328 # ------- HTMLParamElement interface ---------- #
1329  
1330 package HTML::DOM::Element::Param;
1331 25 our $VERSION = '0.057';
1332 25 our @ISA = 'HTML::DOM::Element';
1333 25 *name=\&HTML::DOM::Element::Meta::name;
1334 25 *type=\&HTML::DOM::Element::Link::type;
1335 25 *value=\&HTML::DOM::Element::LI::value;
1336 5 ▶sub valueType{lc shift->_attr(valuetype=>@_)}
Subroutine valueType: called CC=1 SCAR=0.0
1337  
1338 # ------- HTMLAppletElement interface ---------- #
1339  
1340 package HTML::DOM::Element::Applet;
1341 25 our $VERSION = '0.057';
1342 25 our @ISA = 'HTML::DOM::Element';
1343 25 * align = \ & HTML::DOM::Element::Div::align ;
1344 25 * alt = \ & HTML::DOM::Element::Img::alt ;
1345 25 * archive = \ & HTML::DOM::Element::Object::archive ;
1346 25 * code = \ & HTML::DOM::Element::Object::code ;
1347 25 * codeBase = \ & HTML::DOM::Element::Object::codeBase ;
1348 25 * height = \ & HTML::DOM::Element::Img::height ;
1349 25 * hspace = \ & HTML::DOM::Element::Img::hspace ;
1350 25 * name = \ & HTML::DOM::Element::Meta::name ;
1351 5 ▶sub object { shift -> _attr ( object => @_ ) }
Subroutine object: called CC=1 SCAR=0.0
1352 25 * vspace = \ & HTML::DOM::Element::Img::vspace ;
1353 25 * width = \ & HTML::DOM::Element::Pre::width ;
1354  
1355 # ------- HTMLMapElement interface ---------- #
1356  
1357 package HTML::DOM::Element::Map;
1358 25 our $VERSION = '0.057';
1359 25 our @ISA = 'HTML::DOM::Element';
1360 sub areas { # ~~~ I need to make this cache the resulting collection obj
1361 1 ▶ my $self = shift;
Subroutine areas: called CC=2 SCAR=7.1
1362 1 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 0 1 1
1363 0 return grep tag $_ eq 'area', $self->descendants;
1364 }
1365 else {
1366 my $collection = HTML::DOM::Collection->new(
1367 my $list = HTML::DOM::NodeList::Magic->new(
1368 1 ▶ sub { grep tag $_ eq 'area', $self->descendants }
Subroutine __ANON__: called CC=1 SCAR=0.0
1369 1 ));
1370 1 $self->ownerDocument-> _register_magic_node_list($list);
1371 1 $collection;
1372 }
1373 }
1374 25 * name = \ & HTML::DOM::Element::Meta::name ;
1375  
1376 # ------- HTMLAreaElement interface ---------- #
1377  
1378 package HTML::DOM::Element::Area;
1379 25 our $VERSION = '0.057';
1380 25 our @ISA = 'HTML::DOM::Element';
1381 25 * alt = \ & HTML::DOM::Element::Img::alt ;
1382 10 ▶sub coords { shift -> _attr ( coords => @_ ) }
Subroutine coords: called CC=1 SCAR=0.0
1383 25 * href = \ & HTML::DOM::Element::Link::href ;
1384 5 ▶sub noHref { shift->attr ( nohref => @_ ? $_[0] ? 'nohref' : undef : () ) }
Subroutine noHref: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 3 2 5
$_[0] ? : 1 2 3
1385 25 * tabIndex = \ & HTML::DOM::Element::Object::tabIndex ;
1386 25 * target = \ & HTML::DOM::Element::Link::target ;
1387 {
1388 25 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1389 250 *$_ = \&{"HTML::DOM::Element::A::$_"}
1390 25 for qw(accessKey shape hash host hostname pathname port protocol search
1391 trigger_event);
1392 }
1393  
1394 # ------- HTMLScriptElement interface ---------- #
1395  
1396 package HTML::DOM::Element::Script;
1397 25 our $VERSION = '0.057';
1398 25 our @ISA = 'HTML::DOM::Element';
1399 25 * text = \ &HTML::DOM::Element::Title::text ;
1400 5 ▶sub htmlFor { shift -> _attr ( for => @_ ) }
Subroutine htmlFor: called CC=1 SCAR=0.0
1401 5 ▶sub event { shift -> _attr ( event => @_ ) }
Subroutine event: called CC=1 SCAR=0.0
1402 25 * charset = \ &HTML::DOM::Element::Link::charset ;
1403 6 ▶sub defer { shift -> _attr ( defer => @_ ? $_[0] ? 'defer' : undef : () ) }
Subroutine defer: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 4 2 6
$_[0] ? : 2 2 4
1404 25 * src = \ &HTML::DOM::Element::Img::src ;
1405 25 * type = \ &HTML::DOM::Element::Link::type ;
1406  
1407 # ------- HTMLFrameSetElement interface ---------- #
1408  
1409 package HTML::DOM::Element::FrameSet;
1410 25 our $VERSION = '0.057';
1411 25 our @ISA = 'HTML::DOM::Element';
1412 5 ▶sub rows { shift -> _attr ( rows => @_ ) }
Subroutine rows: called CC=1 SCAR=0.0
1413 5 ▶sub cols { shift -> _attr ( cols => @_ ) }
Subroutine cols: called CC=1 SCAR=0.0
1414  
1415 # ------- HTMLFrameElement interface ---------- #
1416  
1417 package HTML::DOM::Element::Frame;
1418 25 our $VERSION = '0.057';
1419 25 our @ISA = 'HTML::DOM::Element';
1420 12 ▶sub frameBorder { lc shift -> _attr ( frameBorder => @_ ) }
Subroutine frameBorder: called CC=1 SCAR=0.0
1421 10 ▶sub longDesc { shift -> _attr ( longdesc => @_ ) }
Subroutine longDesc: called CC=1 SCAR=0.0
1422 10 ▶sub marginHeight{ shift -> _attr ( marginheight => @_ ) }
Subroutine marginHeight: called CC=1 SCAR=0.0
1423 10 ▶sub marginWidth { shift -> _attr ( marginwidth => @_ ) }
Subroutine marginWidth: called CC=1 SCAR=0.0
1424 25 * name = \ &HTML::DOM::Element::Meta::name ;
1425 6 ▶sub noResize { shift->_attr(noresize => @_ ? $_[0]?'noresize':undef : ()) }
Subroutine noResize: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 4 2 6
$_[0] ? : 2 2 4
1426 10 ▶sub scrolling { lc shift -> _attr ( scrolling => @_ ) }
Subroutine scrolling: called CC=1 SCAR=0.0
1427 25 * src = \ &HTML::DOM::Element::Img::src ;
1428 6 ▶sub contentDocument{ (shift->{_HTML_DOM_view} || return)->document }
Subroutine contentDocument: called CC=2 SCAR=6.9
Condition100%2/2
+(shift())->{'_HTML_DOM_view'} || (return)
l!l
42
MC/DC100%1/1
+(shift())->{'_HTML_DOM_view'} || (return)
+(shift())->{'_HTML_DOM_view'}
Truth table100%2/2
A
A= +(shift())->{'_HTML_DOM_view'}
Aresult
11
00
1429 sub contentWindow {
1430 8 ▶ my $old = (my $self = shift)->{_HTML_DOM_view};
Subroutine contentWindow: called CC=3 SCAR=11.0
1431 8 ▶ @_ and $self->{_HTML_DOM_view} = shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->{"_HTML_DOM_view"} = shift() 4 4 8
1432 8 ▶ defined $old ? $old : ()
Branch: 1 branch
BranchTrueFalseTotal
defined $old ? : 4 4 8
1433 };
1434  
1435 # ------- HTMLIFrameElement interface ---------- #
1436  
1437 package HTML::DOM::Element::IFrame;
1438 25 our $VERSION = '0.057';
1439 25 our @ISA = 'HTML::DOM::Element';
1440 25 *align = \&HTML::DOM::Element::Div::align;
1441 25 *frameBorder = \&HTML::DOM::Element::Frame::frameBorder;
1442 25 *height = \&HTML::DOM::Element::Img::height;
1443 25 *longDesc = \&HTML::DOM::Element::Frame::longDesc;
1444 25 * marginHeight = \&HTML::DOM::Element::Frame::marginHeight;
1445 25 *marginWidth = \&HTML::DOM::Element::Frame::marginWidth;
1446 25 *name = \&HTML::DOM::Element::Meta::name;
1447 25 *scrolling = \&HTML::DOM::Element::Frame::scrolling;
1448 25 *src = \&HTML::DOM::Element::Img::src;
1449 25 *width = \&HTML::DOM::Element::Pre::width;
1450 25 *contentDocument = \&HTML::DOM::Element::Frame::contentDocument;
1451 25 *contentWindow = \&HTML::DOM::Element::Frame::contentWindow;
1452  
1453 25 1
« DOM.pm ↑ Summary DOM/EventTarget.pm »