DOM.pm

filter: Statementstmt 92.7% 424 / 457 Branchbran 82.6% 162 / 196 Conditioncond 73.7% 87 / 118 MC/DCmcdc 56.0% 37 / 66 Subroutinesub 98.1% 104 / 106 Podpod 93.2% 55 / 59 totaltotal 86.7% 869 / 1002 CC 158 SCAR 23.8
CC
158
Cov
87%
parse_file
106.8
base
62.0
cookie
12.6
CRAP 10.9
« DOM/EventTarget.pm ↑ Summary DOM/Element/Form.pm »
1 package HTML::DOM;
2  
3 # If you are looking at the source code (which you are obviously doing
4 # if you are reading this), note that '# ~~~' is my way of marking
5 # something to be done still (except in this sentence).
6  
7  
8 24 ▶use 5.008003;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 24 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
14 24 ▶use HTML::DOM::Element;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 24 ▶use HTML::DOM::Exception 'NOT_SUPPORTED_ERR';
Subroutine BEGIN: called CC=1 SCAR=0.0
16 24 ▶use HTML::DOM::Node 'DOCUMENT_NODE';
Subroutine BEGIN: called CC=1 SCAR=0.0
17 24 ▶use Scalar::Util 'weaken';
Subroutine BEGIN: called CC=1 SCAR=0.0
18 24 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 24 our $VERSION = '0.058';
21 24 our @ISA = 'HTML::DOM::Node';
22  
23 24 require HTML::DOM::Collection;
24 24 require HTML::DOM::Comment;
25 24 require HTML::DOM::DocumentFragment;
26 24 require HTML::DOM::Implementation;
27 24 require HTML::DOM::NodeList::Magic;
28 24 require HTML::DOM::Text;
29 24 require HTML::Tagset;
30 24 require HTML::DOM::_TreeBuilder;
31  
32 24 ▶use overload fallback => 1,
Subroutine BEGIN: called CC=1 SCAR=0.0
33 19421 ▶'%{}' => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
34 19421 my $self = shift;
35 #return $self; # for debugging
36 19421 ▶ $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 19418 3 19421
Condition100%3/3
$self->isa(scalar caller) or (caller)->isa("HTML::DOM::_TreeBuilder")
l!l&&r!l&&!r
192032153
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
37 and return $self;
38 3 $self->forms;
39 24 };
40  
41  
42 =head1 NAME
43  
44 HTML::DOM - A Perl implementation of the HTML Document Object Model
45  
46 =head1 VERSION
47  
48 Version 0.058 (alpha)
49  
50 B<WARNING:> This module is still at an experimental stage. The API is
51 subject to change without
52 notice.
53  
54 =head1 SYNOPSIS
55  
56 use HTML::DOM;
57
58 my $dom_tree = new HTML::DOM; # empty tree
59 $dom_tree->write($source_code);
60 $dom_tree->close;
61
62 my $other_dom_tree = new HTML::DOM;
63 $other_dom_tree->parse_file($filename);
64
65 $dom_tree->getElementsByTagName('body')->[0]->appendChild(
66 $dom_tree->createElement('input')
67 );
68
69 print $dom_tree->innerHTML, "\n";
70  
71 my $text = $dom_tree->createTextNode('text');
72 $text->data; # get attribute
73 $text->data('new value'); # set attribute
74
75 =head1 DESCRIPTION
76  
77 This module implements the HTML Document Object Model by extending the
78 HTML::Tree modules. The HTML::DOM class serves both as an HTML parser and
79 as the document class.
80  
81 The following DOM modules are currently supported:
82  
83 Feature Version (aka level)
84 ------- -------------------
85 HTML 2.0
86 Core 2.0
87 Events 2.0
88 UIEvents 2.0
89 MouseEvents 2.0
90 MutationEvents 2.0
91 HTMLEvents 2.0
92 StyleSheets 2.0
93 CSS 2.0 (partially)
94 CSS2 2.0
95 Views 2.0
96  
97 StyleSheets, CSS and CSS2 are actually provided by L<CSS::DOM>. This list
98 corresponds to CSS::DOM versions 0.02 to 0.14.
99  
100 =for comment
101 Level 2 interfaces not yet included: Range, Traversal
102  
103 =head1 METHODS
104  
105 =head2 Construction and Parsing
106  
107 =over 4
108  
109 =item $tree = new HTML::DOM %options;
110  
111 This class method constructs and returns a new HTML::DOM object. The
112 C<%options>, which are all optional, are as follows:
113  
114 =over 4
115  
116 =item url
117  
118 The value that the C<URL> method will return. This value is also used by
119 the C<domain> method.
120  
121 =item referrer
122  
123 The value that the C<referrer> method will return
124  
125 =item response
126  
127 An HTTP::Response object. This will be used for information needed for
128 writing cookies. It is expected to have a reference to a request object
129 (accessible via its C<request> method--see L<HTTP::Response>). Passing a
130 parameter to the 'cookie' method will be a no-op
131 without this.
132  
133 =item weaken_response
134  
135 If this is passed a true value, then the HTML::DOM object will hold a weak
136 reference to the response.
137  
138 =item cookie_jar
139  
140 An HTTP::Cookies object. As with C<response>, if you omit this, arguments
141 passed to the
142 C<cookie> method will be ignored.
143  
144 =item charset
145  
146 The original character set of the document. This does not affect parsing
147 via the C<write> method (which always assumes Unicode). C<parse_file> will
148 use this, if specified, or L<HTML::Encoding> otherwise.
149 L<HTML::DOM::Form>'s C<make_request> method uses this to encode form data
150 unless the form has a valid 'accept-charset' attribute.
151  
152 =back
153  
154 If C<referrer> and C<url> are omitted, they can be inferred from
155 C<response>.
156  
157 =cut
158  
159 {
160 # This HTML::DOM::Element::HTML package represents the
161 # documentElement. It inherits from
162 # HTML::DOM::_TreeBuilder and acts
163 # as the parser. It is also used as a parser for innerHTML.
164  
165 # Note for potential developers: You can’t refer to ->parent in
166 # this package and expect it to provide the document, because
167 # that’s not the case with innerHTML. Use ->ownerDocument.
168 # Use ->parent only to distinguish between innerHTML and
169 # the regular parser.
170  
171 # Concerning magic associations between forms and fields: To cope
172 # with bad markup, an implicitly closed form (with no end tag) is
173 # associated with any form fields that occur after that are not
174 # inside any form. So when a start tag for a form is encountered,
175 # we make that the ‘current form’, by pushing it on to
176 # @{ $$self{_HTML_DOM_cf} }. When the element is closed, if it
177 # is closed by an end tag, we simply pop it off the cf array. If
178 # it is implicitly closed we pop it off and also make it the
179 # ‘magic form’ (_HTML_DOM_mg_f). When we encounter a form field,
180 # we give it a magic association with the form if the cf
181 # stack is empty.
182  
183  
184 package HTML::DOM::Element::HTML;
185 24 our @ISA = qw' HTML::DOM::Element HTML::DOM::_TreeBuilder';
186  
187 24 ▶ use Scalar::Util qw 'weaken isweak';
Subroutine BEGIN: called CC=1 SCAR=0.0
188  
189 # I have to override this so it doesn't delete _HTML_DOM_* attri-
190 # butes and so that it doesn’t rebless the object.
191 83 ▶ sub elementify {
Subroutine elementify: called CC=3 SCAR=11.0
192 83 my $self = shift;
193 83 ▶ my %attrs = map /^[a-z_]*\z/ ? () : ($_ => $self->{$_}),
Branch: 1 branch
BranchTrueFalseTotal
/^[a-z_]*\z/ ? : 1911 484 2395
194 keys %$self;
195 83 my @weak = grep isweak $self->{$_}, keys %$self;
196 83 $self->SUPER::elementify;
197 83 %$self = (%$self, %attrs); # this invigorates feeble refs
198 83 weaken $self->{$_} for @weak;
199 }
200  
201 132 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
202 132 my $tb; # hafta declare it separately so the closures can
203 # c it
204 ($tb = shift->HTML::DOM::_TreeBuilder::new(
205 element_class => 'HTML::DOM::Element',
206 501 ▶ 'tweak_~text' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
207 501 my ($text, $parent) = @_;
208 # $parent->ownerDocument will be undef if
209 # $parent is the doc.
210 501 ▶ $parent->splice_content( -1,1,
Condition33%1/3
$parent->ownerDocument || $parent
l!l&&r!l&&!r
50100
MC/DC0%0/2
$parent->ownerDocument || $parent
$parent->ownerDocument $parent
Truth table33%1/3
A || B
A= $parent->ownerDocumentB= $parent
ABresult
1X1
011
000
211 ($parent->ownerDocument || $parent)
212 ->createTextNode($text) );
213 $parent->content_offset(
214 $$tb{_HTML_DOM_tb_c_offset}
215 501 );
216 },
217 731 ▶ 'tweak_*' => sub {
Subroutine __ANON__: called CC=12 SCAR=24.9
218 731 my($elem, $tag, $doc_elem) = @_;
219 731 ▶ $tag =~ /^~/ and return;
Branch: 1 branch
BranchTrueFalseTotal
$tag =~ /^~/ and return 7 724 731
220  
221 724 ▶ if(
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "link") 16 708 724
222 $tag eq 'link'
223 ) {
224 16 HTML'DOM'Element'Link'_reset_style_sheet(
225 $elem
226 );
227 }
228  
229 # If a form is being closed, determine
230 # whether it is closed implicitly and set
231 # the current form and magic form
232 # accordingly.
233 724 ▶ if($tag eq 'form') {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq "form") 40 684 724
234 pop
235 40 ▶ @{$$doc_elem{_HTML_DOM_cf}||[]};
Condition50%1/2
$doc_elem->{'_HTML_DOM_cf'} || []
l!l
400
MC/DC0%0/1
$doc_elem->{'_HTML_DOM_cf'} || []
$doc_elem->{'_HTML_DOM_cf'}
Truth table50%1/2
A
A= $doc_elem->{'_HTML_DOM_cf'}
Aresult
11
00
236 delete $$doc_elem{_HTML_DOM_etif}
237 or $$doc_elem{_HTML_DOM_mg_f}
238 40 ▶ = $elem
Branch: 1 branch
BranchTrueFalseTotal
delete $doc_elem->{"_HTML_DOM_etif"} or $doc_elem->{"_HTML_DOM_mg_f"} = $elem 27 13 40
239 }
240  
241 # If a formie is being closed, create a
242 # magic association where appropriate.
243 724 ▶ if(!$$doc_elem{_HTML_DOM_no_mg}
Branch: 1 branch
BranchTrueFalseTotal
if (not $doc_elem->{"_HTML_DOM_no_mg"} and $tag =~ /^(?: button|(?: fieldse|inpu|(?:obj|sel)ec )t|label|textarea )\z/x and $doc_elem->{"_HTML_DOM_mg_f"} and not $doc_elem->{"_HTML_DOM_cf"} && @{$doc_elem->{"_HTML_DOM_cf"};}) 9 715 724
Condition91%11/12
not $doc_elem->{"_HTML_DOM_no_mg"} and $tag =~ /^(?: button|(?: fieldse|inpu|(?:obj|sel)ec )t|label|textarea )\z/x and $doc_elem->{"_HTML_DOM_mg_f"} and not $doc_elem->{"_HTML_DOM_cf"} && @{$doc_elem->{"_HTML_DOM_cf"};}
!ll&&!rl&&r
71419
not $doc_elem->{"_HTML_DOM_no_mg"} and $tag =~ /^(?: button|(?: fieldse|inpu|(?:obj|sel)ec )t|label|textarea )\z/x and $doc_elem->{"_HTML_DOM_mg_f"}
!ll&&!rl&&r
6318310
not $doc_elem->{"_HTML_DOM_no_mg"} and $tag =~ /^(?: button|(?: fieldse|inpu|(?:obj|sel)ec )t|label|textarea )\z/x
!ll&&!rl&&r
10053193
$doc_elem->{'_HTML_DOM_cf'} && @{$doc_elem->{'_HTML_DOM_cf'};}
!ll&&!rl&&r
091
MC/DC80%4/5
not $doc_elem->{"_HTML_DOM_no_mg"} and $tag =~ /^(?: button|(?: fieldse|inpu|(?:obj|sel)ec )t|label|textarea )\z/x and $doc_elem->{"_HTML_DOM_mg_f"} and not $doc_elem->{"_HTML_DOM_cf"} && @{$doc_elem->{"_HTML_DOM_cf"};}
not $doc_elem->{"_HTML_DOM_no_mg"} $tag =~ /^(?: button|(?: fieldse|inpu|(?:obj|sel)ec )t|label|textarea )\z/x $doc_elem->{"_HTML_DOM_mg_f"} $doc_elem->{'_HTML_DOM_cf'} @{$doc_elem->{'_HTML_DOM_cf'};}
Truth table83%5/6
not(A) and B and C and not(D && E)
A= not $doc_elem->{"_HTML_DOM_no_mg"}B= $tag =~ /^(?: button|(?: fieldse|inpu|(?:obj|sel)ec )t|label|textarea )\z/xC= $doc_elem->{"_HTML_DOM_mg_f"}D= $doc_elem->{'_HTML_DOM_cf'}E= @{$doc_elem->{'_HTML_DOM_cf'};}
ABCDEresult
0XXXX0
10XXX0
110XX0
111110
1110X1
111101
244 and $tag =~ /^(?:
245 button|(?:
246 fieldse|inpu|(?:obj|sel)ec
247 )t|label|textarea
248 )\z/x
249 and $$doc_elem{_HTML_DOM_mg_f}
250 and !$$doc_elem{_HTML_DOM_cf}
251 10 ||!@{$$doc_elem{_HTML_DOM_cf}}) {
252 $elem->form(
253 $$doc_elem{_HTML_DOM_mg_f}
254 9 );
255 9 $doc_elem->ownerDocument->
256 magic_forms(1);
257 }
258  
259 my $event_offsets = delete
260 $elem->{_HTML_DOM_tb_event_offsets}
261 724 ▶ or return;
Branch: 1 branch
BranchTrueFalseTotal
my $event_offsets = delete $elem->{"_HTML_DOM_tb_event_offsets"} or return 4 720 724
262 4 _create_events(
263 $doc_elem, $elem, $event_offsets
264 );
265 },
266 132 ))
267 ->ignore_ignorable_whitespace(0); # stop eof()'s cleanup
268 132 $tb->store_comments(1); # from changing an
269 132 $tb->unbroken_text(1); # necessary, con- # elem_han-
270 # sidering what # dler's view
271 # _tweak_~text does # of the tree
272  
273 # Web browsers preserve whitespace, at least from the point
274 # of view of the DOM; but the main reason we are using this
275 # option is that a parser for innerHTML doesn’t know
276 # whether the nodes will be inserted in a <pre>.
277 132 no_space_compacting $tb 1;
278  
279 132 $tb->handler(text => "text", # so we can get line
280 "self, text, is_cdata, offset"); # numbers for scripts
281 132 $tb->handler(start => "start",
282 "self, tagname, attr, attrseq, offset, tokenpos");
283 132 $tb->handler((declaration=>)x2,'self,tagname,tokens,text');
284  
285 132 $tb->{_HTML_DOM_tweakall} = $tb->{'_tweak_*'};
286  
287 132 my %opts = @_;
288 132 $tb->{_HTML_DOM_no_mg} = delete $opts{no_magic_forms};
289 # used by an element’s innerHTML
290  
291 # We have to copy it like this, because our circular ref-
292 # erence is thus: $tb -> object -> closure -> $tb
293 # We can’t weaken $tb without a copy of it, because it is
294 # the only reference to the object.
295 132 my $life_raft = $tb; weaken $tb; $tb;
296 }
297  
298 550 ▶ sub start {
Subroutine start: called CC=8 SCAR=20.8
299 550 ▶ return shift->SUPER::start(@_) if @_ < 6; # shirt-çorcuit
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 6 3 547 550
300
301 547 my $tokenpos = pop;
302 547 my $offset = pop;
303 547 my %event_offsets;
304 547 my $attr_names = pop;
305 547 for(0..$#$attr_names) {
306 $$attr_names[$_] =~ /^on(.*)/is
307 517 ▶ and $event_offsets{$1} =
Branch: 1 branch
BranchTrueFalseTotal
$attr_names->[$_] =~ /^on(.*)/is and $event_offsets{$1} = $$tokenpos[$_ * 4 + 4] + $offset 5 512 517
308 $$tokenpos[$_*4 + 4] + $offset;
309 }
310  
311 547 my $elem = (my $self = shift)->SUPER::start(@_);
312
313 547 ▶ $_[0] eq 'form' and push @{ $$self{_HTML_DOM_cf} ||= [] },
Branch: 1 branch
BranchTrueFalseTotal
$_[0] eq "form" and push @{$self->{"_HTML_DOM_cf"} ||= [];}, $elem 40 507 547
Condition100%2/2
$self->{"_HTML_DOM_cf"} ||= []
l!l
733
MC/DC100%1/1
$self->{"_HTML_DOM_cf"} ||= []
$self->{"_HTML_DOM_cf"}
Truth table100%2/2
A
A= $self->{"_HTML_DOM_cf"}
Aresult
11
00
314 $elem;
315  
316 547 ▶ return $elem unless %event_offsets;
Branch: 1 branch
BranchTrueFalseTotal
unless %event_offsets 542 5 547
317  
318 5 ▶ if(!$HTML::Tagset::emptyElement{$_[0]}) { # container
Branch: 1 branch
BranchTrueFalseTotal
if (not $HTML::Tagset::emptyElement{$_[0]}) { } 4 1 5
319 $$elem{_HTML_DOM_tb_event_offsets} =
320 4 \%event_offsets;
321 } else {
322 1 _create_events(
323 $self,
324 $elem,
325 \%event_offsets,
326 );
327 }
328  
329 5 return $elem;
330 }
331  
332 5 ▶ sub _create_events {
Subroutine _create_events: called CC=4 SCAR=13.9
333 5 my ($doc_elem,$elem,$event_offsets) = @_;
334 5 ▶ defined(my $event_attr_handler =
Branch: 1 branch
BranchTrueFalseTotal
defined(my $event_attr_handler = $doc_elem->ownerDocument->event_attr_handler) or return 3 2 5
335 $doc_elem->ownerDocument->event_attr_handler)
336 or return;
337 3 for(keys %$event_offsets) {
338 my $l =
339 &$event_attr_handler(
340 $elem,
341 $_,
342 $elem->attr("on$_"),
343 3 $$event_offsets{$_}
344 );
345 3 ▶ defined $l and
Branch: 1 branch
BranchTrueFalseTotal
defined $l and $elem->event_handler($_, $l) 3 0 3
346 $elem->event_handler (
347 $_, $l
348 );
349 }
350 }
351  
352 501 ▶ sub text {
Subroutine text: called CC=1 SCAR=0.0
353 501 $_[0]{_HTML_DOM_tb_c_offset} = pop;
354 501 shift->SUPER::text(@_)
355 }
356  
357 786 ▶ sub insert_element {
Subroutine insert_element: called CC=4 SCAR=13.9
358 786 my ($self, $tag) = (shift, @_);
359 786 ▶ if((ref $tag ? $tag->tag : $tag) eq 'tr'
Branch: 2 branches
BranchTrueFalseTotal
if ((ref $tag ? $tag->tag : $tag) eq "tr" and $self->pos->tag eq "table") 12 774 786
ref $tag ? : 510 276 786
Condition100%3/3
(ref $tag ? $tag->tag : $tag) eq "tr" and $self->pos->tag eq "table"
!ll&&!rl&&r
768612
MC/DC100%2/2
(ref $tag ? $tag->tag : $tag) eq "tr" and $self->pos->tag eq "table"
(ref $tag ? $tag->tag : $tag) eq "tr" $self->pos->tag eq "table"
Truth table100%3/3
A and B
A= (ref $tag ? $tag->tag : $tag) eq "tr"B= $self->pos->tag eq "table"
ABresult
0X0
100
111
360 and $self->pos->tag eq 'table') {
361 12 $self->insert_element('tbody', 1);
362 }
363 786 $self->SUPER::insert_element(@_);
364 }
365  
366 549 ▶ sub end {
Subroutine end: called CC=5 SCAR=16.1
367 549 my $self = shift;
368  
369 # If this is a form, record that we’ve seen an end tag, so
370 # that this does not become a ‘magic form’.
371 ++$$self{_HTML_DOM_etif} # end tag is 'form'
372 549 ▶ if $_[0] eq 'form';
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "form" 27 522 549
373  
374 # Make sure </t[hd]> cannot close a cell outside the cur-
375 # rent table.
376 549 ▶ $_[0] =~ /^t[hd]\z/ and @_ = (\$_[0], 'table');
Branch: 1 branch
BranchTrueFalseTotal
$_[0] =~ /^t[hd]\z/ and @_ = (\$_[0], "table") 4 545 549
377  
378 # HTML::TreeBuilder expects the <html> element to be the
379 # topmost element, and gets confused when it’s inside the
380 # ~doc. It sets _pos to the doc when it encounters </html>.
381 # This works around that.
382 549 my $pos = $self->{_pos};
383 549 my @ret = $self->SUPER::end(@_);
384 $self->{_pos} = $pos
385 548 ▶ if ($self->{_pos}||return @ret)->{_tag} eq '~doc';
Branch: 1 branch
BranchTrueFalseTotal
if +($self->{"_pos"} || (return @ret))->{"_tag"} eq "~doc" 73 440 513
Condition100%2/2
$self->{'_pos'} || (return @ret)
l!l
51335
MC/DC100%1/1
$self->{'_pos'} || (return @ret)
$self->{'_pos'}
Truth table100%2/2
A
A= $self->{'_pos'}
Aresult
11
00
386 513 @ret; # TB relies on this retval
387 }
388  
389 9 ▶ sub declaration {
Subroutine declaration: called CC=7 SCAR=19.8
390 9 my($self,$tagname,$tokens,$source) = @_;
391 return
392 9 ▶ unless $tagname eq 'doctype'
Branch: 1 branch
BranchTrueFalseTotal
unless $tagname eq "doctype" and my $parent = $self->parent 1 8 9
Condition66%2/3
$tagname eq "doctype" and my $parent = $self->parent
!ll&&!rl&&r
018
MC/DC50%1/2
$tagname eq "doctype" and my $parent = $self->parent
$tagname eq "doctype" my $parent = $self->parent
Truth table66%2/3
A and B
A= $tagname eq "doctype"B= my $parent = $self->parent
ABresult
0X0
100
111
393 and my $parent = $self->parent;
394 package HTML::DOM; # bypass overloading
395 $parent->{_HTML_DOM_doctype} = $source
396 8 ▶ unless defined $parent->{_HTML_DOM_doctype};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $parent->{"_HTML_DOM_doctype"} 8 0 8
397 8 ▶ return unless @$tokens > 3;
Branch: 1 branch
BranchTrueFalseTotal
unless @$tokens > 3 1 7 8
398 7 for ($self->{_HTML_DOM_version} = $tokens->[3]){
399 7 ▶ s/^['"]// and s/['"]\z//;
Branch: 1 branch
BranchTrueFalseTotal
s/^['"]// and s/['"]\z// 7 0 7
400 }
401 }
402  
403 1048 ▶ sub element_class { 'HTML::DOM::Element' }
Subroutine element_class: called CC=1 SCAR=0.0
404  
405 # HTMLHtmlElement interface
406 5 ▶ sub version { shift->_attr('version' => @_) }
Subroutine version: called CC=1 SCAR=0.0
407  
408 } # end of special TreeBuilder package
409  
410 24 ▶sub new {
Subroutine new: called CC=7 SCAR=19.5
Pod documented
411 81 my $self = shift->SUPER::new('~doc');
412  
413 81 my %opts = @_;
414 81 $self->{_HTML_DOM_url} = $opts{url}; # might be undef
415 81 $self->{_HTML_DOM_referrer} = $opts{referrer}; # might be undef
416 81 ▶ if($opts{response}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"response"}) 8 73 81
417 8 $self->{_HTML_DOM_response} = $opts{response};
418 8 ▶ if(!defined $self->{_HTML_DOM_url}) {{
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_HTML_DOM_url"}) 6 2 8
419 6 $self->{_HTML_DOM_url} =
420 ($opts{response}->request || last)
421 6 ▶ ->url;
Condition100%2/2
$opts{'response'}->request || (last)
l!l
33
MC/DC100%1/1
$opts{'response'}->request || (last)
$opts{'response'}->request
Truth table100%2/2
A
A= $opts{'response'}->request
Aresult
11
00
422 }}
423 8 ▶ if(!defined $self->{_HTML_DOM_referrer}) {{
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"_HTML_DOM_referrer"}) 6 2 8
424 6 $self->{_HTML_DOM_referrer} =
425 ($opts{response}->request || last)
426 6 ▶ ->header('Referer')
Condition100%2/2
$opts{'response'}->request || (last)
l!l
33
MC/DC100%1/1
$opts{'response'}->request || (last)
$opts{'response'}->request
Truth table100%2/2
A
A= $opts{'response'}->request
Aresult
11
00
427 }}
428 8 ▶ if($opts{weaken_response}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"weaken_response"}) 1 7 8
429 weaken $self->{_HTML_DOM_response}
430 1 }
431 }
432 81 $self->{_HTML_DOM_jar} = $opts{cookie_jar}; # might be undef
433 81 $self->{_HTML_DOM_cs} = $opts{charset};
434  
435 81 $self;
436 }
437  
438 =item $tree->elem_handler($elem_name => sub { ... })
439  
440 If you call this method first, then, when the DOM tree is in the
441 process of
442 being built (as a result of a call to C<write> or C<parse_file>), the
443 subroutine will be called after each C<$elem_name> element
444 is
445 added to the tree. If you give '*' as the element name, the subroutine
446 will be called for each element that does not have a handler. The
447 subroutine's
448 two arguments will be the tree itself
449 and the element in question. The subroutine can call the DOM object's
450 C<write>
451 method to insert HTML code into the source after the element.
452  
453 Here is a lame example (which does not take Content-Script-Type headers
454 or security into account):
455  
456 $tree->elem_handler(script => sub {
457 my($document,$elem) = @_;
458 return unless $elem->attr('type') eq 'application/x-perl';
459 eval($elem->firstChild->data);
460 });
461  
462 $tree->write(
463 '<p>The time is
464 <script type="application/x-perl">
465 $document->write(scalar localtime)
466 </script>
467 precisely.
468 </p>'
469 );
470 $tree->close;
471  
472 print $tree->documentElement->as_text, "\n";
473  
474 (Note: L<HTML::DOM::Element>'s
475 L<C<content_offset>|HTML::DOM::Element/content_offset> method might come in
476 handy for reporting line numbers for script errors.)
477  
478 =cut
479  
480 125 ▶sub elem_handler {
Subroutine elem_handler: called CC=3 SCAR=11.0
Pod documented
481 125 my ($self,$elem_name,$sub) = @_;
482  
483 # ~~~ temporary; for internal use only:
484 125 ▶ @_ < 3 and return $$self{_HTML_DOM_nih}{$elem_name};
Branch: 1 branch
BranchTrueFalseTotal
@_ < 3 and return $self->{"_HTML_DOM_nih"}{$elem_name} 120 5 125
485  
486 5 $$self{_HTML_DOM_nih}{$elem_name} = $sub; # nih = node inser-
487 # tion handler
488 7 ▶ my $h = $self->{_HTML_DOM_elem_handlers}{$elem_name} = sub {
Subroutine __ANON__: called CC=6 SCAR=18.3
489 # I can’t put $doc_elem outside the closure, because
490 # ->open replaces it with another object, and we’d be
491 # referring to the wrong one.
492 7 my $doc_elem = $_[2];
493 7 $doc_elem->{_HTML_DOM_tweakall}->(@_);
494 7 $self->_modified; # in case there are node lists hanging
495 # around that the handler references
496 7 &$sub($self, $_[0]);
497  
498 # See the comment in sub write.
499 6 (my $level = $$self{_HTML_DOM_buffered});
500 6 ▶ if( $level
Branch: 1 branch
BranchTrueFalseTotal
if ($level and $level -= 1, 1 and $self->{"_HTML_DOM_p"} and $self->{"_HTML_DOM_p"}[$level]) 3 3 6
Condition77%7/9
$level and $level -= 1, 1 and $self->{"_HTML_DOM_p"} and $self->{"_HTML_DOM_p"}[$level]
!ll&&!rl&&r
303
$level and $level -= 1, 1 and $self->{"_HTML_DOM_p"}
!ll&&!rl&&r
123
$level and $level -= 1, 1
!ll&&!rl&&r
105
MC/DC50%2/4
$level and $level -= 1, 1 and $self->{"_HTML_DOM_p"} and $self->{"_HTML_DOM_p"}[$level]
$level $level -= 1, 1 $self->{"_HTML_DOM_p"} $self->{"_HTML_DOM_p"}[$level]
Truth table60%3/5
A and B and C and D
A= $levelB= $level -= 1, 1C= $self->{"_HTML_DOM_p"}D= $self->{"_HTML_DOM_p"}[$level]
ABCDresult
0XXX0
10XX0
110X0
11100
11111
501 and ($level -= 1, 1)
502 and $$self{_HTML_DOM_p}
503 and $$self{_HTML_DOM_p}[$level]
504 ) {
505 3 $$self{_HTML_DOM_p}[$level]->eof;
506 $level
507 0 ? --$#{$$self{_HTML_DOM_p}}
508 3 ▶ : delete $$self{_HTML_DOM_p};
Branch: 1 branch
BranchTrueFalseTotal
$level ? : 0 3 3
509 }
510 5 };
511 5 ▶ if(my $p = $$self{_HTML_DOM_parser}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $p = $self->{"_HTML_DOM_parser"}) 1 4 5
512 1 $$p{"_tweak_$elem_name"} = $h
513 }
514 5 weaken $self;
515 5 return;
516 }
517  
518  
519 =item css_url_fetcher( \&sub )
520  
521 With this method you can provide a subroutine that fetches URLs referenced
522 by 'link' tags. Its sole argument is the URL, which is made absolute based
523 on the HTML page's own base URL (it is assumed that this is absolute). It
524 should return C<undef> or an empty list on failure. Upon
525 success, it should return just the CSS code, if it has been decoded (and is
526 in Unicode), or, if it has not been decoded, the CSS code followed by
527 C<< decode => 1 >>. See L<CSS::DOM/STYLE SHEET ENCODING> for details on
528 when you should or should not decode it. (Note that HTML::DOM
529 automatically
530 provides an encoding hint based on the HTML document.)
531  
532 HTML::DOM passes the result of the url fetcher to L<CSS::DOM> and
533 turns
534 it into a style sheet object accessible via the link element's
535 L<C<sheet>|HTML::DOM::Element::Link/sheet> method.
536  
537 =cut
538  
539 11 ▶sub css_url_fetcher {
Subroutine css_url_fetcher: called CC=3 SCAR=11.0
Pod documented
540 11 my $old = (my $self = shift)->{_HTML_DOM_cuf};
541 11 ▶ $self->{_HTML_DOM_cuf} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 3 8 11
542 11 ▶ $old||();
Branch: 1 branch
BranchTrueFalseTotal
$old or () 7 4 11
543 }
544  
545 =item $tree->write(...) (DOM method)
546  
547 This parses the HTML code passed to it, adding it to the end of
548 the
549 document. It assumes that its input is a normal Perl Unicode string. Like
550 L<HTML::TreeBuilder>'s
551 C<parse> method, it can take a coderef.
552  
553 When it is called from an an element handler (see
554 C<elem_handler>, above), the value passed to it
555 will be inserted into the HTML code after the current element when the
556 element handler returns. (In this case a coderef won't do--maybe that will
557 be added later.)
558  
559 If the C<close> method has been called, C<write> will call C<open> before
560 parsing the HTML code passed to it.
561  
562 =item $tree->writeln(...) (DOM method)
563  
564 Just like C<write> except that it appends "\n" to its argument and does
565 not work with code refs. (Rather
566 pointless, if you ask me. :-)
567  
568 =item $tree->close() (DOM method)
569  
570 Call this method to signal to the parser that the end of the HTML code has
571 been reached. It will then parse any residual HTML that happens to be
572 buffered. It also makes the next C<write> call C<open>.
573  
574 =item $tree->open (DOM method)
575  
576 Deletes the HTML tree, resetting it so that it has just an <html> element,
577 and a parser hungry for HTML code.
578  
579 =item $tree->parse_file($file)
580  
581 This method takes a file name or handle and parses the content,
582 (effectively) calling C<close> afterwards. In the former case (a file
583 name), L<HTML::Encoding> will be used to detect the encoding. In the
584 latter (a file handle), you'll have to C<binmode> it yourself. This could
585 be considered a bug. If you have a solution to this (how to make
586 HTML::Encoding detect an encoding from a file handle), please let me know.
587  
588 As of version 0.12, this method returns true upon success, or undef/empty
589 list on failure.
590  
591 =item $tree->charset
592  
593 This method returns the name of the character
594 set that was passed to C<new>, or, if that was not given, that which
595 C<parse_file> used.
596  
597 It returns undef if C<new> was not given a charset and if C<parse_file> was
598 not
599 used or was
600 passed a file handle.
601  
602 You can also set the charset by passing an argument, in which case the old
603 value is returned.
604  
605  
606 =cut
607  
608 0 ▶sub parse_file {
Subroutine parse_file: not called CC=11 SCAR=46.7
Pod documented
609 0 my $file = $_[1];
610  
611 0 $_[0]->open;
612  
613 # This ‘if’ statement uses the same check that HTML::Parser uses.
614 # We are not strictly checking to see whether it’s a handle,
615 # but whether HTML::Parser would consider it one.
616 0 ▶ if (ref($file) || ref(\$file) eq "GLOB") {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $file or ref \$file eq "GLOB") 0 0 0
Condition0%0/3
ref $file or ref \$file eq "GLOB"
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $file or ref \$file eq "GLOB"
ref $file ref \$file eq "GLOB"
Truth table0%0/3
A or B
A= ref $fileB= ref \$file eq "GLOB"
ABresult
1X1
011
000
617 (my $a = shift->{_HTML_DOM_parser})
618 0 ▶ ->parse_file($file) || return;
Branch: 1 branch
BranchTrueFalseTotal
(my $a = +(shift())->{"_HTML_DOM_parser"})->parse_file($file) or return 0 0 0
619 0 $a ->elementify;
620 0 return 1;
621 }
622  
623 24 ▶ no warnings 'parenthesis'; # 5.8.3 Grrr!!
Subroutine BEGIN: called CC=1 SCAR=0.0
624 0 ▶ if(my $charset = $_[0]{_HTML_DOM_cs}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $charset = $_[0]{"_HTML_DOM_cs"}) 0 0 0
625 0 ▶ open my $fh, $file or return;
Branch: 1 branch
BranchTrueFalseTotal
CORE::open my $fh, $file or return 0 0 0
626 0 $charset =~ s/^(?:x-?)?mac-?/mac/i;
627 0 binmode $fh, ":encoding($charset)";
628 $$_{_HTML_DOM_parser}->parse_file($fh) || return,
629 $_->close
630 0 ▶ for shift;
Branch: 1 branch
BranchTrueFalseTotal
$_->{"_HTML_DOM_parser"}->parse_file($fh) or return 0 0 0
631 0 return 1;
632 }
633  
634 0 ▶ open my $fh, $file or return;
Branch: 1 branch
BranchTrueFalseTotal
CORE::open my $fh, $file or return 0 0 0
635 0 local $/;
636 0 my $contents = <$fh>;
637 0 require HTML::Encoding;
638 0 ▶ my $encoding = HTML::Encoding::encoding_from_html_document(
Condition0%0/2
HTML::Encoding::encoding_from_html_document($contents) || 'iso-8859-1'
l!l
00
MC/DC0%0/1
HTML::Encoding::encoding_from_html_document($contents) || 'iso-8859-1'
HTML::Encoding::encoding_from_html_document($contents)
Truth table0%0/2
A
A= HTML::Encoding::encoding_from_html_document($contents)
Aresult
11
00
639 $contents
640 ) || 'iso-8859-1';
641 # Since we’ve already slurped the file, we might as well
642 # avoid having HTML::Parser read it again, even if we could
643 # use binmode.
644 0 require Encode;
645 $_->write(Encode::decode($encoding, $contents)), $_->close,
646 $_->{_HTML_DOM_cs} = $encoding
647 0 for shift;
648 0 return 1;
649 }
650  
651 34 ▶sub charset {
Subroutine charset: called CC=2 SCAR=6.9
Pod documented
652 34 my $old = (my$ self = shift)->{_HTML_DOM_cs};
653 34 ▶ $self->{_HTML_DOM_cs} = shift if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 4 30 34
654 34 $old;
655 }
656  
657 99 ▶sub write {
Subroutine write: called CC=5 SCAR=16.3
Pod documented
658 99 my $self = shift;
659 99 ▶ if($$self{_HTML_DOM_buffered}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_HTML_DOM_buffered'}) { } 3 96 99
660 # Although we call this buffered, it’s actually not. Before
661 # version 0.040, a recursive call to ->write on the same
662 # doc object would simply record the HTML code in a buffer
663 # that was processed when the elem handler that made the
664 # inner call to ->write finished. Every elem handler would
665 # have a wrapper (created in the elem_handler sub above)
666 # that took care of this after calling the handler, by cre-
667 # ating a new, temporary, parser object that would call the
668 # start/end, etc., methods of our tree builder.
669 #
670 # This approach stops JS code like this from working (yes,
671 # there *are* websites with code like this!):
672 # document.write("<img id=img1>")
673 # document.getElementById("img1").src="..."
674 #
675 # So, now we take care of creating a new parser immedi-
676 # ately. This does mean, however that we end up with mul-
677 # tiple parser objects floating around in the case of
678 # nested <scripts>. So we have to be careful to create and
679 # delete them at the right time.
680  
681 # $$self{_HTML_DOM_buffered} actually contains a number
682 # indicating the number of nested calls to ->write.
683 3 my $level = $$self{_HTML_DOM_buffered};
684 3 local $$self{_HTML_DOM_buffered} = $level + 1;
685  
686 3 my($doc_elem) = $$self{_HTML_DOM_parser};
687  
688 # These handlers delegate the handling to methods of
689 # *another* HTML::Parser object.
690 my $p = $$self{_HTML_DOM_p}[$level-1] ||=
691 HTML::Parser->new(
692 start_h => [
693 3 ▶ sub { $doc_elem->start(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
694 'tagname, attr, attrseq'
695 ],
696 end_h => [
697 0 ▶ sub { $doc_elem->end(@_) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
698 'tagname, text'
699 ],
700 text_h => [
701 2 ▶ sub { $doc_elem->text(@_) },
Subroutine __ANON__: called CC=1 SCAR=0.0
702 3 ▶ 'text, is_cdata'
Condition33%1/3
$self->{"_HTML_DOM_p"}[$level - 1] ||= "HTML::Parser"->new("start_h", [sub { $doc_elem->start(@_); } , "tagname, attr, attrseq"], "end_h", [sub { $doc_elem->end(@_); } , "tagname, text"], "text_h", [sub { $doc_elem->text(@_); } , "text, is_cdata"])
l!l&&r!l&&!r
030
MC/DC0%0/2
$self->{"_HTML_DOM_p"}[$level - 1] ||= "HTML::Parser"->new("start_h", [sub { $doc_elem->start(@_); } , "tagname, attr, attrseq"], "end_h", [sub { $doc_elem->end(@_); } , "tagname, text"], "text_h", [sub { $doc_elem->text(@_); } , "text, is_cdata"])
$self->{"_HTML_DOM_p"}[$level - 1] "HTML::Parser"->new("start_h", [sub { $doc_elem->start(@_); } , "tagname, attr, attrseq"], "end_h", [sub { $doc_elem->end(@_); } , "tagname, text"], "text_h", [sub { $doc_elem->text(@_); } , "text, is_cdata"])
Truth table33%1/3
A ||= B
A= $self->{"_HTML_DOM_p"}[$level - 1]B= "HTML::Parser"->new("start_h", [sub { $doc_elem->start(@_); } , "tagname, attr, attrseq"], "end_h", [sub { $doc_elem->end(@_); } , "tagname, text"], "text_h", [sub { $doc_elem->text(@_); } , "text, is_cdata"])
ABresult
1X1
011
000
703 ],
704 );
705  
706 3 $p->unbroken_text(1); # push_content, which is called by
707 # H:TB:text, won't concatenate two
708 # text portions if the first one
709 # is a node.
710  
711 3 $p->parse(shift);
712  
713 # We can’t get rid of our parser at this point, as a subse-
714 # quent ->write call from the same nested level (e.g., from
715 # the same <script> block) will need the same one, in case
716 # what we are parsing ends with a partial token. But if the
717 # calling elem handler finishes (e.g., if we reach a
718 # </script>), then we need to remove it, so we have
719 # elem_handler do that for us.
720 }
721 else {
722 my $parser
723 = $$self{_HTML_DOM_parser}
724 96 ▶ || ($self->open, $$self{_HTML_DOM_parser});
Condition66%2/3
$self->{'_HTML_DOM_parser'} || ($self->open, $self->{'_HTML_DOM_parser'})
l!l&&r!l&&!r
27690
MC/DC0%0/2
$self->{'_HTML_DOM_parser'} || ($self->open, $self->{'_HTML_DOM_parser'})
$self->{'_HTML_DOM_parser'} ($self->open, $self->{'_HTML_DOM_parser'})
Truth table66%2/3
A || B
A= $self->{'_HTML_DOM_parser'}B= ($self->open, $self->{'_HTML_DOM_parser'})
ABresult
1X1
011
000
725 96 local $$self{_HTML_DOM_buffered} = 1;
726 96 $parser->parse($_) for @_;
727 }
728 99 $self->_modified;
729 return # nothing;
730 99 }
731  
732 4 ▶sub writeln { shift->write(@_,"\n") }
Subroutine writeln: called CC=1 SCAR=0.0
Pod documented
733  
734 87 ▶sub close {
Subroutine close: called CC=2 SCAR=6.9
Pod documented
735 87 my $a = (my $self = shift)->{_HTML_DOM_parser};
736 87 ▶ return unless $a;
Branch: 1 branch
BranchTrueFalseTotal
unless $a 3 84 87
737  
738 # We can’t use eval { $a->eof } because that would catch errors
739 # that are meant to propagate (a nasty bug [the so-called
740 # ‘content—offset’ bug] was hidden because of an eval in ver-
741 # sion 0.010).
742 # return unless $a->can('eof');
743
744 84 $a->eof(@_);
745 83 delete $$self{_HTML_DOM_parser};
746 83 $a->elementify;
747 return # nothing;
748 83 }
749  
750 102 ▶sub open {
Subroutine open: called CC=3 SCAR=11.0
Pod documented
751 102 (my $self = shift)->detach_content;
752  
753 # We have to use push_content instead of simply putting it there
754 # ourselves, because push_content takes care of weakening the
755 # parent (and that code doesn’t belong in this package).
756 $self->push_content(
757 102 my $tb = $$self{_HTML_DOM_parser} = new HTML::DOM::Element::HTML
758 );
759  
760 24 ▶ delete @$self{<_HTML_DOM_sheets _HTML_DOM_doctype>};
Subroutine BEGIN: called CC=1 SCAR=0.0
761  
762 102 ▶ return unless $self->{_HTML_DOM_elem_handlers};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_HTML_DOM_elem_handlers"} 93 9 102
763 9 for(keys %{$self->{_HTML_DOM_elem_handlers}}) {
764 $$tb{"_tweak_$_"} =
765 9 $self->{_HTML_DOM_elem_handlers}{$_}
766 }
767  
768 return # nothing;
769 9 }
770  
771 =back
772  
773 =head2 Other DOM Methods
774  
775 =over 4
776  
777 =cut
778  
779  
780 #-------------- DOM STUFF (CORE) ---------------- #
781  
782 =item doctype
783  
784 Returns nothing
785  
786 =item implementation
787  
788 Returns the L<HTML::DOM::Implementation> object.
789  
790 =item documentElement
791  
792 Returns the <html> element.
793  
794 =item createElement ( $tag )
795  
796 =item createDocumentFragment
797  
798 =item createTextNode ( $text )
799  
800 =item createComment ( $text )
801  
802 =item createAttribute ( $name )
803  
804 Each of these creates a node of the appropriate type.
805  
806 =item createProcessingInstruction
807  
808 =item createEntityReference
809  
810 These two throw an exception.
811  
812 =for comment
813 =item createCSSStyleSheet
814 This creates a style sheet (L<CSS::DOM> object).
815  
816 =item getElementsByTagName ( $name )
817  
818 C<$name> can be the name of the tag, or '*', to match all tag names. This
819 returns a node list object in scalar context, or a list in list context.
820  
821 =item importNode ( $node, $deep )
822  
823 Clones the C<$node>, setting its C<ownerDocument> attribute to the document
824 with which this method is called. If C<$deep> is true, the C<$node> will
825 be
826 cloned recursively.
827  
828 =cut
829  
830 2 ▶sub doctype {} # always null
Subroutine doctype: called CC=1 SCAR=0.0
Pod documented
831  
832 2 ▶sub implementation {
Subroutine implementation: called CC=1 SCAR=0.0
Pod documented
833 24 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
834 2 return $HTML::DOM::Implementation::it;
835 }
836  
837 98 ▶sub documentElement {
Subroutine documentElement: called CC=1 SCAR=0.0
Pod documented
838 98 ($_[0]->content_list)[0]
839 }
840  
841 352 ▶sub createElement {
Subroutine createElement: called CC=1 SCAR=0.0
Pod documented
842 352 my $elem = HTML::DOM::Element->new($_[1]);
843 352 $elem->_set_ownerDocument(shift);
844 352 $elem;
845 }
846  
847 9 ▶sub createDocumentFragment {
Subroutine createDocumentFragment: called CC=1 SCAR=0.0
Pod documented
848 9 my $thing = HTML::DOM::DocumentFragment->new;
849 9 $thing->_set_ownerDocument(shift);
850 9 $thing;
851 }
852  
853 558 ▶sub createTextNode {
Subroutine createTextNode: called CC=1 SCAR=0.0
Pod documented
854 558 my $thing = HTML::DOM::Text->new(@_[1..$#_]);
855 558 $thing->_set_ownerDocument(shift);
856 558 $thing;
857 }
858  
859 7 ▶sub createComment {
Subroutine createComment: called CC=1 SCAR=0.0
Pod documented
860 7 my $thing = HTML::DOM::Comment->new(@_[1..$#_]);
861 7 $thing->_set_ownerDocument(shift);
862 7 $thing;
863 }
864  
865 1 ▶sub createCDATASection {
Subroutine createCDATASection: called CC=1 SCAR=0.0
Pod undocumented
866 1 die HTML::DOM::Exception->new( NOT_SUPPORTED_ERR,
867 'The HTML DOM does not support CDATA sections' );
868 }
869  
870 1 ▶sub createProcessingInstruction {
Subroutine createProcessingInstruction: called CC=1 SCAR=0.0
Pod documented
871 1 die HTML::DOM::Exception->new( NOT_SUPPORTED_ERR,
872 'The HTML DOM does not support processing instructions' );
873 }
874  
875 22 ▶sub createAttribute {
Subroutine createAttribute: called CC=1 SCAR=0.0
Pod documented
876 22 my $thing = HTML::DOM::Attr->new(@_[1..$#_]);
877 22 $thing->_set_ownerDocument(shift);
878 22 $thing;
879 }
880  
881 1 ▶sub createEntityReference {
Subroutine createEntityReference: called CC=1 SCAR=0.0
Pod documented
882 1 die HTML::DOM::Exception->new( NOT_SUPPORTED_ERR,
883 'The HTML DOM does not support entity references' );
884 }
885  
886 #sub createCSSStyleSheet {
887 # shift;
888 # require CSS'DOM;
889 # ~~~
890 #}
891  
892 17 ▶sub getElementsByTagName {
Subroutine getElementsByTagName: called CC=4 SCAR=13.9
Pod documented
893 17 my($self,$tagname) = @_;
894 #warn "You didn't give me a tag name." if !defined $tagname;
895 17 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 4 13 17
896 4 ▶ return $tagname eq '*'
Branch: 1 branch
BranchTrueFalseTotal
$tagname eq '*' ? : 1 3 4
897 ? grep tag $_ !~ /^~/, $self->descendants
898 : $self->find($tagname);
899 }
900 else {
901 my $list = HTML::DOM::NodeList::Magic->new(
902 $tagname eq '*'
903 2 ▶ ? sub { grep tag $_ !~ /^~/, $self->descendants }
Subroutine __ANON__: called CC=1 SCAR=0.0
904 17 ▶ : sub { $self->find($tagname) }
Subroutine __ANON__: called CC=1 SCAR=0.0
905 13 ▶ );
Branch: 1 branch
BranchTrueFalseTotal
$tagname eq '*' ? : 1 12 13
906 13 $self-> _register_magic_node_list($list);
907 13 $list;
908 }
909 }
910  
911 12 ▶sub importNode {
Subroutine importNode: called CC=4 SCAR=13.9
Pod documented
912 12 my ($self, $node, $deep) = @_;
913 12 ▶ die HTML::DOM::Exception->new( NOT_SUPPORTED_ERR,
Branch: 1 branch
BranchTrueFalseTotal
if $node->nodeType == 9 2 10 12
914 'Documents cannot be imported.' )
915 if $node->nodeType ==DOCUMENT_NODE;
916 10 (my $clown = $node->cloneNode($deep))
917 ->_set_ownerDocument($self);
918 10 ▶ if($clown->can('descendants')) { # otherwise it’s an Attr, so this
Branch: 1 branch
BranchTrueFalseTotal
if ($clown->can("descendants")) 8 2 10
919 8 for($clown->descendants) { # isn’t necessary
920 4 delete $_->{_HTML_DOM_owner};
921 }}
922 10 $clown;
923 }
924  
925 #-------------- DOM STUFF (HTML) ---------------- #
926  
927 =item alinkColor
928  
929 =item background
930  
931 =item bgColor
932  
933 =item fgColor
934  
935 =item linkColor
936  
937 =item vlinkColor
938  
939 These six methods return (optionally set) the corresponding attributes of
940 the body element. Note that most of the names do not map directly to the
941 names of
942 the attributes. C<fgColor> refers to the C<text> attribute. Those that
943 end
944 with 'linkColor' refer to the attributes of the same name but without the
945 'Color' on the end.
946  
947 =cut
948  
949 6 ▶sub alinkColor { (shift->body||return "")->aLink (@_) }
Subroutine alinkColor: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
(shift())->body || (return '')
l!l
24
MC/DC100%1/1
(shift())->body || (return '')
(shift())->body
Truth table100%2/2
A
A= (shift())->body
Aresult
11
00
950 6 ▶sub background { (shift->body||return "")->background(@_) }
Subroutine background: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
(shift())->body || (return '')
l!l
24
MC/DC100%1/1
(shift())->body || (return '')
(shift())->body
Truth table100%2/2
A
A= (shift())->body
Aresult
11
00
951 6 ▶sub bgColor { (shift->body||return "")->bgColor (@_) }
Subroutine bgColor: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
(shift())->body || (return '')
l!l
24
MC/DC100%1/1
(shift())->body || (return '')
(shift())->body
Truth table100%2/2
A
A= (shift())->body
Aresult
11
00
952 6 ▶sub fgColor { (shift->body||return "")->text (@_) }
Subroutine fgColor: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
(shift())->body || (return '')
l!l
24
MC/DC100%1/1
(shift())->body || (return '')
(shift())->body
Truth table100%2/2
A
A= (shift())->body
Aresult
11
00
953 6 ▶sub linkColor { (shift->body||return "")->link (@_) }
Subroutine linkColor: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
(shift())->body || (return '')
l!l
24
MC/DC100%1/1
(shift())->body || (return '')
(shift())->body
Truth table100%2/2
A
A= (shift())->body
Aresult
11
00
954 6 ▶sub vlinkColor { (shift->body||return "")->vLink (@_) }
Subroutine vlinkColor: called CC=2 SCAR=6.9
Pod documented
Condition100%2/2
(shift())->body || (return '')
l!l
24
MC/DC100%1/1
(shift())->body || (return '')
(shift())->body
Truth table100%2/2
A
A= (shift())->body
Aresult
11
00
955  
956 =item title
957  
958 Returns (or optionally sets) the title of the page.
959  
960 =item referrer
961  
962 Returns the page's referrer.
963  
964 =item domain
965  
966 Returns the domain name portion of the document's URL.
967  
968 =item URL
969  
970 Returns the document's URL.
971  
972 =item body
973  
974 Returns the body element, or the outermost frame set if the document has
975 frames. You can set the body by passing an element as an argument, in
976 which
977 case the old body element is returned.
978  
979 =item images
980  
981 =item applets
982  
983 =item links
984  
985 =item forms
986  
987 =item anchors
988  
989 These five methods each return a list of the appropriate elements in list
990 context, or an L<HTML::DOM::Collection> object in scalar context. In this
991 latter case, the object will update automatically when the document is
992 modified.
993  
994 In the case of C<forms> you can access those by using the HTML::DOM object
995 itself as a hash. I.e., you can write C<< $doc->{f} >> instead of
996 S<< C<< $doc->forms->{f} >> >>.
997  
998 =for comment
999 # ~~~ Why on earth did I ever put this in the docs?!
1000 B<TO DO:> I need to make these methods cache the HTML collection objects
1001 that they create. Once I've done this, I can make list context use those
1002 objects, as well as scalar context.
1003  
1004 =item cookie
1005  
1006 This returns a string containing the document's cookies (the format may
1007 still change). If you pass an
1008 argument, it
1009 will set a cookie as well. Both Netscape-style and RFC2965-style cookie
1010 headers are supported.
1011  
1012 =cut
1013  
1014 10 ▶sub title {
Subroutine title: called CC=5 SCAR=16.4
Pod documented
1015 10 my $doc = shift;
1016 10 ▶ if(my $title_elem = $doc->find('title')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $title_elem = $doc->find('title')) { } 7 3 10
1017 7 $title_elem->text(@_);
1018 }
1019 else {
1020 3 ▶ return "" unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 2 3
1021 2 ▶ ( $doc->find('head')
Condition50%3/6
$doc->find('head') || ($doc->find('html') || $doc->appendChild($doc->createElement('html')))->appendChild($doc->createElement('head'))
l!l&&r!l&&!r
110
$doc->find('html') || $doc->appendChild($doc->createElement('html'))
l!l&&r!l&&!r
010
MC/DC0%0/2
$doc->find('head') || ($doc->find('html') || $doc->appendChild($doc->createElement('html')))->appendChild($doc->createElement('head'))
$doc->find('head') ($doc->find('html') || $doc->appendChild($doc->createElement('html')))->appendChild($doc->createElement('head'))
MC/DC0%0/2
$doc->find('html') || $doc->appendChild($doc->createElement('html'))
$doc->find('html') $doc->appendChild($doc->createElement('html'))
Truth table66%2/3
A || B
A= $doc->find('head')B= ($doc->find('html') || $doc->appendChild($doc->createElement('html')))->appendChild($doc->createElement('head'))
ABresult
1X1
011
000
Truth table33%1/3
A || B
A= $doc->find('html')B= $doc->appendChild($doc->createElement('html'))
ABresult
1X1
011
000
1022 || ( $doc->find('html')
1023 || $doc->appendChild($doc->createElement('html'))
1024 )->appendChild($doc->createElement('head'))
1025 )->appendChild(
1026 my $t = $doc->createElement('title')
1027 );
1028 2 $t->text(@_);
1029 2 return "";
1030 }
1031 }
1032  
1033 5 ▶sub referrer {
Subroutine referrer: called CC=2 SCAR=7.2
Pod documented
1034 5 my $referrer = shift->{_HTML_DOM_referrer};
1035 5 ▶ defined $referrer ? $referrer : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $referrer ? : 5 0 5
1036 }
1037  
1038 24 ▶sub domain { no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine domain: called CC=2 SCAR=6.9
Pod documented
1039 2 my $doc = shift;
1040 2 host {ref $doc->{_HTML_DOM_url} ? $doc->{_HTML_DOM_url}
1041 2 ▶ : ($doc->{_HTML_DOM_url} = URI->new($doc->{_HTML_DOM_url}))};
Branch: 1 branch
BranchTrueFalseTotal
ref $doc->{'_HTML_DOM_url'} ? : 1 1 2
1042 }
1043  
1044 152 ▶sub URL {
Subroutine URL: called CC=2 SCAR=6.9
Pod documented
1045 152 my $url = shift->{_HTML_DOM_url};
1046 152 ▶ defined $url ? "$url" : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $url ? : 41 111 152
1047 }
1048  
1049 76 ▶sub body { # ~~~ this needs to return the outermost frameset element if
Subroutine body: called CC=4 SCAR=13.9
Pod documented
1050 # there is one (if the frameset is always the second child
1051 # of <html>, then it already does).
1052 76 my $body = ($_[0]->documentElement->content_list)[1];
1053 76 ▶ if (!$body || $body->tag !~ /^(?:body|frameset)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($body and $body->tag =~ /^(?:body|frameset)\z/) 24 52 76
Condition100%3/3
$body and $body->tag =~ /^(?:body|frameset)\z/
!ll&&!rl&&r
121252
MC/DC100%2/2
$body and $body->tag =~ /^(?:body|frameset)\z/
$body $body->tag =~ /^(?:body|frameset)\z/
Truth table100%3/3
A and B
A= $bodyB= $body->tag =~ /^(?:body|frameset)\z/
ABresult
0X0
100
111
1054 24 $body = $_[0]->find('body','frameset');
1055 }
1056 76 ▶ if(@_>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ > 1) { } 2 74 76
1057 2 my $doc_elem = $_[0]->documentElement;
1058 # I'm using the replaceChild rather than replace_with,
1059 # despite the former's convoluted syntax, since the former
1060 # has the appropriate error-checking code (or will), and
1061 # also because it triggers mutation events.
1062 2 $doc_elem->replaceChild($_[1],$body)
1063 }
1064 else {
1065 74 $body
1066 }
1067 }
1068  
1069 2 ▶sub images {
Subroutine images: called CC=2 SCAR=6.9
Pod documented
1070 2 my $self = shift;
1071 2 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 1 2
1072 1 return grep tag $_ eq 'img', $self->descendants;
1073 }
1074 else {
1075 my $collection = HTML::DOM::Collection->new(
1076 my $list = HTML::DOM::NodeList::Magic->new(
1077 1 ▶ sub { grep tag $_ eq 'img', $self->descendants }
Subroutine __ANON__: called CC=1 SCAR=0.0
1078 1 ));
1079 1 $self-> _register_magic_node_list($list);
1080 1 $collection;
1081 }
1082 }
1083  
1084 2 ▶sub applets {
Subroutine applets: called CC=2 SCAR=6.9
Pod documented
1085 2 my $self = shift;
1086 2 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 1 2
1087 1 return grep $_->tag =~ /^(?:objec|apple)t\z/,
1088 $self->descendants;
1089 }
1090 else {
1091 my $collection = HTML::DOM::Collection->new(
1092 my $list = HTML::DOM::NodeList::Magic->new(
1093 1 ▶ sub { grep $_->tag =~ /^(?:objec|apple)t\z/,
Subroutine __ANON__: called CC=1 SCAR=0.0
1094 $self->descendants }
1095 1 ));
1096 1 $self-> _register_magic_node_list($list);
1097 1 $collection;
1098 }
1099 }
1100  
1101 4 ▶sub links {
Subroutine links: called CC=4 SCAR=13.9
Pod documented
1102 4 my $self = shift;
1103 4 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 3 4
1104 return grep {
1105 1 my $tag = tag $_;
1106 38 ▶ $tag eq 'area' || $tag eq 'a'
Condition100%6/6
$tag eq 'area' || $tag eq 'a' && defined $_->attr('href')
l!l&&r!l&&!r
1235
$tag eq "a" and defined $_->attr("href")
!ll&&!rl&&r
3412
MC/DC100%3/3
$tag eq 'area' || $tag eq 'a' && defined $_->attr('href')
$tag eq 'area' $tag eq "a" defined $_->attr("href")
Truth table100%4/4
A || B and C
A= $tag eq 'area'B= $tag eq "a"C= defined $_->attr("href")
ABCresult
1XX1
0111
00X0
0100
1107 && defined $_->attr('href')
1108 } $self->descendants;
1109 }
1110 else {
1111 my $collection = HTML::DOM::Collection->new(
1112 my $list = HTML::DOM::NodeList::Magic->new(
1113 3 ▶ sub { grep {
Subroutine __ANON__: called CC=3 SCAR=11.0
1114 3 my $tag = tag $_;
1115 90 ▶ $tag eq 'area' || $tag eq 'a'
Condition100%6/6
$tag eq 'area' || $tag eq 'a' && defined $_->attr('href')
l!l&&r!l&&!r
1584
$tag eq "a" and defined $_->attr("href")
!ll&&!rl&&r
8315
MC/DC100%3/3
$tag eq 'area' || $tag eq 'a' && defined $_->attr('href')
$tag eq 'area' $tag eq "a" defined $_->attr("href")
Truth table100%4/4
A || B and C
A= $tag eq 'area'B= $tag eq "a"C= defined $_->attr("href")
ABCresult
1XX1
0111
00X0
0100
1116 && defined $_->attr('href')
1117 } $self->descendants }
1118 3 ));
1119 3 $self-> _register_magic_node_list($list);
1120 3 $collection;
1121 }
1122 }
1123  
1124 39 ▶sub forms {
Subroutine forms: called CC=2 SCAR=6.9
Pod documented
1125 39 my $self = shift;
1126 39 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 17 22 39
1127 17 return grep tag $_ eq 'form', $self->descendants;
1128 }
1129 else {
1130 my $collection = HTML::DOM::Collection->new(
1131 my $list = HTML::DOM::NodeList::Magic->new(
1132 22 ▶ sub { grep tag $_ eq 'form', $self->descendants }
Subroutine __ANON__: called CC=1 SCAR=0.0
1133 22 ));
1134 22 $self-> _register_magic_node_list($list);
1135 22 $collection;
1136 }
1137 }
1138  
1139 2 ▶sub anchors {
Subroutine anchors: called CC=3 SCAR=11.0
Pod documented
1140 2 my $self = shift;
1141 2 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 1 1 2
1142 1 ▶ return grep tag $_ eq 'a' && defined $_->attr('name'),
Condition100%3/3
$_->tag eq 'a' && defined $_->attr('name')
!ll&&!rl&&r
3512
MC/DC100%2/2
$_->tag eq 'a' && defined $_->attr('name')
$_->tag eq 'a' defined $_->attr('name')
Truth table100%3/3
A && B
A= $_->tag eq 'a'B= defined $_->attr('name')
ABresult
0X0
100
111
1143 $self->descendants;
1144 }
1145 else {
1146 my $collection = HTML::DOM::Collection->new(
1147 my $list = HTML::DOM::NodeList::Magic->new(
1148 1 ▶ sub { grep tag $_ eq 'a' && defined $_->attr('name'),
Subroutine __ANON__: called CC=2 SCAR=6.9
Condition100%3/3
$_->tag eq 'a' && defined $_->attr('name')
!ll&&!rl&&r
3512
MC/DC100%2/2
$_->tag eq 'a' && defined $_->attr('name')
$_->tag eq 'a' defined $_->attr('name')
Truth table100%3/3
A && B
A= $_->tag eq 'a'B= defined $_->attr('name')
ABresult
0X0
100
111
1149 $self->descendants }
1150 1 ));
1151 1 $self-> _register_magic_node_list($list);
1152 1 $collection;
1153 }
1154 }
1155  
1156  
1157 8 ▶sub cookie {
Subroutine cookie: called CC=12 SCAR=25.3
Pod documented
1158 8 my $self = shift;
1159 8 ▶ return '' unless defined (my $jar = $self->{_HTML_DOM_jar});
Branch: 1 branch
BranchTrueFalseTotal
unless defined(my $jar = $self->{"_HTML_DOM_jar"}) 2 6 8
1160 6 my $return;
1161 6 ▶ if (defined wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined wantarray) 6 0 6
1162 # Yes, this is nuts (getting HTTP::Cookies to join the cookies, and
1163 # splitting them, filtering them, and joining them again[!]), but
1164 # &HTTP::Cookies::add_cookie_header is long and complicated, and I
1165 # don't want to replicate it here.
1166 24 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1167 6 my $reqclone = $self->{_HTML_DOM_response}->request->clone;
1168 # Yes this is a bit strange, but we don’t want to put
1169 # ‘use HTTP::Header 1.59’ in this file, as it would mean loading the
1170 # module even for people who are not using this feature or who are
1171 # duck-typing.
1172 6 ▶ if (!$reqclone->can('header_field_names')
Branch: 1 branch
BranchTrueFalseTotal
if (not $reqclone->can("header_field_names") and $reqclone->isa("HTTP::Headers")) 0 6 6
Condition33%1/3
not $reqclone->can("header_field_names") and $reqclone->isa("HTTP::Headers")
!ll&&!rl&&r
600
MC/DC0%0/2
not $reqclone->can("header_field_names") and $reqclone->isa("HTTP::Headers")
not $reqclone->can("header_field_names") $reqclone->isa("HTTP::Headers")
Truth table33%1/3
not(A) and B
A= not $reqclone->can("header_field_names")B= $reqclone->isa("HTTP::Headers")
ABresult
0X0
100
111
1173 0 && $reqclone->isa("HTTP::Headers")) { VERSION HTTP::Headers:: 1.59 }
1174 6 for($reqclone->header_field_names) {
1175 1 ▶ /cookie/i and remove_header $reqclone $_;
Branch: 1 branch
BranchTrueFalseTotal
/cookie/i and $reqclone->remove_header($_) 1 0 1
1176 }
1177 6 $return = join ';', grep !/\$/,
1178 $jar->add_cookie_header(
1179 $reqclone
1180 )-> header ('Cookie')
1181 # Pieces of this regexp were stolen from HTTP::Headers::Util:
1182 =~ /\G\s* # initial whitespace
1183 (
1184 [^\s=;,]+ # name
1185 \s*=\s* # =
1186 (?:
1187 \"(?:[^\"\\]*(?:\\.[^\"\\]*)*)\" # quoted value
1188 |
1189 [^;,\s]* # unquoted value
1190 )
1191 )
1192 \s*;?
1193 /xg;
1194 }
1195 6 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 3 6
1196 3 ▶ return unless defined $self->{_HTML_DOM_response};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_HTML_DOM_response"} 0 3 3
1197 3 require HTTP::Headers::Util;
1198 (undef,undef, my%split) =
1199 3 @{(HTTP::Headers::Util::split_header_words($_[0]))[0]};
1200 3 my $rfc;
1201 3 for(keys %split){
1202 # I *hope* this always works! (NS cookies should have no version.)
1203 7 ▶ ++ $rfc, last if lc $_ eq 'version';
Branch: 1 branch
BranchTrueFalseTotal
if lc $_ eq "version" 1 6 7
1204 }
1205 (my $clone = $self->{_HTML_DOM_response}->clone)
1206 3 ->remove_header(qw/ Set-Cookie Set-Cookie2 /);
1207 3 $clone->header('Set-Cookie' . 2 x!! $rfc => $_[0]);
1208 3 $jar->extract_cookies($clone);
1209 }
1210 6 ▶ $return||'';
Branch: 1 branch
BranchTrueFalseTotal
$return or "" 5 1 6
1211 }
1212  
1213 =item getElementById
1214  
1215 =item getElementsByName
1216  
1217 =item getElementsByClassName
1218  
1219 These three do what their names imply. The last two
1220 will return a list in list context, or a node list
1221 object in scalar context. Calling them in list
1222 context is probably more efficient.
1223  
1224 =cut
1225  
1226 162 ▶sub getElementById {
Subroutine getElementById: called CC=3 SCAR=11.0
Pod documented
1227 162 my(@pile) = grep ref($_), @{shift->{'_content'}};
1228 162 my $id = shift;
1229 162 my $this;
1230 162 ▶ while(@pile) {
Branch: 1 branch
BranchTrueFalseTotal
if (@pile) 2495 1 2496
1231 24 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1232 2495 $this = shift @pile;
1233 2495 ▶ $this->id eq $id and return $this;
Branch: 1 branch
BranchTrueFalseTotal
$this->id eq $id and return $this 161 2334 2495
1234 2334 unshift @pile, grep ref($_), $this->content_list;
1235 }
1236 1 return;
1237 }
1238  
1239 3 ▶sub getElementsByName {
Subroutine getElementsByName: called CC=2 SCAR=6.9
Pod documented
1240 3 my($self,$name) = @_;
1241 3 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 2 1 3
1242 2 return $self->look_down(name => "$name");
1243 }
1244 else {
1245 my $list = HTML::DOM::NodeList::Magic->new(
1246 1 ▶ sub { $self->look_down(name => "$name"); }
Subroutine __ANON__: called CC=1 SCAR=0.0
1247 1 );
1248 1 $self-> _register_magic_node_list($list);
1249 1 $list;
1250 }
1251 }
1252  
1253 9 ▶sub getElementsByClassName {
Subroutine getElementsByClassName: called CC=1 SCAR=0.0
Pod documented
1254 9 splice @_, 2, @_, 1; # Remove extra elements; add a true third elem
1255 9 goto &HTML'DOM'Element'_getElementsByClassName;
1256 }
1257  
1258 # ---------- DocumentEvent interface -------------- #
1259  
1260 =item createEvent ( $category )
1261  
1262 Creates a new event object, believe it or not.
1263  
1264 The C<$category> is the DOM event category, which determines what type of
1265 event object will be returned. The currently supported event categories
1266 are MouseEvents, UIEvents, HTMLEvents and MutationEvents.
1267  
1268 You can omit the C<$category> to create an instance of the event base class
1269 (not officially part of the DOM).
1270  
1271 =cut
1272  
1273 267 ▶sub createEvent {
Subroutine createEvent: called CC=2 SCAR=6.9
Pod documented
1274 267 require HTML'DOM'Event;
1275 267 ▶ HTML'DOM'Event'create_event($_[1]||'');
Condition100%2/2
$_[1] || ''
l!l
23730
MC/DC100%1/1
$_[1] || ''
$_[1]
Truth table100%2/2
A
A= $_[1]
Aresult
11
00
1276 }
1277  
1278 # ---------- DocumentView interface -------------- #
1279  
1280 =item defaultView
1281  
1282 Returns the L<HTML::DOM::View> object associated with the document.
1283  
1284 There is no such object by default; you have to put one there yourself:
1285  
1286 Although it is supposed to be read-only according to the DOM, you can set
1287 this attribute by passing an argument to it. It I<is> still marked as
1288 read-only in
1289 L<C<%HTML::DOM::Interface>|HTML::DOM::Interface>.
1290  
1291 If you do set it, it is recommended that the object be a subclass of
1292 L<HTML::DOM::View>.
1293  
1294 This attribute holds a weak reference to the object.
1295  
1296 =cut
1297  
1298 1859 ▶sub defaultView {
Subroutine defaultView: called CC=3 SCAR=11.0
Pod documented
1299 1859 my $self = shift;
1300 1859 my $old = $self->{_HTML_DOM_view};
1301 1859 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 1855 1859
1302 4 weaken($self->{_HTML_DOM_view} = shift);
1303 }
1304 1859 ▶ return defined $old ? $old : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $old ? : 20 1839 1859
1305 }
1306  
1307 # ---------- DocumentStyle interface -------------- #
1308  
1309 =item styleSheets
1310  
1311 Returns a L<CSS::DOM::StyleSheetList> of the document's style sheets, or a
1312 simple list in list context.
1313  
1314 =cut
1315  
1316 25 ▶sub styleSheets {
Subroutine styleSheets: called CC=3 SCAR=11.0
Pod documented
1317 25 my $doc = shift;
1318 my $ret = (
1319 $doc->{_HTML_DOM_sheets} or
1320 $doc->{_HTML_DOM_sheets} = (
1321 require CSS::DOM::StyleSheetList,
1322 new CSS::DOM::StyleSheetList
1323 ),
1324 $doc->_populate_sheet_list,
1325 $doc->{_HTML_DOM_sheets}
1326 25 ▶ );
Condition66%2/3
$doc->{'_HTML_DOM_sheets'} || ($doc->{'_HTML_DOM_sheets'} = (require CSS::DOM::StyleSheetList, 'CSS::DOM::StyleSheetList'->new), $doc->_populate_sheet_list, $doc->{'_HTML_DOM_sheets'})
l!l&&r!l&&!r
2230
MC/DC0%0/2
$doc->{'_HTML_DOM_sheets'} || ($doc->{'_HTML_DOM_sheets'} = (require CSS::DOM::StyleSheetList, 'CSS::DOM::StyleSheetList'->new), $doc->_populate_sheet_list, $doc->{'_HTML_DOM_sheets'})
$doc->{'_HTML_DOM_sheets'} ($doc->{'_HTML_DOM_sheets'} = (require CSS::DOM::StyleSheetList, 'CSS::DOM::StyleSheetList'->new), $doc->_populate_sheet_list, $doc->{'_HTML_DOM_sheets'})
Truth table66%2/3
A || B
A= $doc->{'_HTML_DOM_sheets'}B= ($doc->{'_HTML_DOM_sheets'} = (require CSS::DOM::StyleSheetList, 'CSS::DOM::StyleSheetList'->new), $doc->_populate_sheet_list, $doc->{'_HTML_DOM_sheets'})
ABresult
1X1
011
000
1327 25 ▶ wantarray ? @$ret : $ret;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 24 25
1328 }
1329  
1330 =item innerHTML
1331  
1332 Serialises and returns the HTML document. If you pass an argument, it will
1333 set the contents of the document via C<open>, C<write> and C<close>,
1334 returning a serialisation of the old contents.
1335  
1336 =cut
1337  
1338 22 ▶sub innerHTML {
Subroutine innerHTML: called CC=5 SCAR=16.1
Pod documented
1339 22 my $self = shift;
1340 22 my $old;
1341 22 ▶ $old = join '' , $self->{_HTML_DOM_doctype}||'',
Branch: 2 branches
BranchTrueFalseTotal
if defined wantarray 11 11 22
&HTML::DOM::Element::_html_element_adds_newline() ? : 0 9 9
Condition100%2/2
$self->{'_HTML_DOM_doctype'} || ''
l!l
47
MC/DC100%1/1
$self->{'_HTML_DOM_doctype'} || ''
$self->{'_HTML_DOM_doctype'}
Truth table100%2/2
A
A= $self->{'_HTML_DOM_doctype'}
Aresult
11
00
1342 map
1343 HTML'DOM'Element'_html_element_adds_newline
1344 ? substr((
1345 as_HTML $_ (undef)x2,{}
1346 ), 0, -1)
1347 : $_->as_HTML((undef)x2,{}),
1348 $self->content_list
1349 if defined wantarray;
1350 22 ▶ if(@_){
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 12 10 22
1351 12 $self->open();
1352 12 $self->write(shift);
1353 12 $self->close();
1354 }
1355 $old
1356 22 }
1357  
1358  
1359 =item location
1360  
1361 =item set_location_object (non-DOM)
1362  
1363 C<location> returns the location object, if you've put one there with
1364 C<set_location_object>. HTML::DOM doesn't actually implement such an object
1365 itself, but provides the appropriate magic to make
1366 C<< $doc->location($foo) >> translate into
1367 C<< $doc->location->href($foo) >>.
1368  
1369 BTW, the location object had better be true when used as a boolean, or
1370 HTML::DOM will think it doesn't exist.
1371  
1372 =cut
1373  
1374 3 ▶sub location {
Subroutine location: called CC=4 SCAR=13.9
Pod documented
1375 3 my $self = shift;
1376 3 ▶ @_ and ($$self{_HTML_DOM_loc}||die "Can't assign to location"
Branch: 1 branch
BranchTrueFalseTotal
@_ and ($self->{"_HTML_DOM_loc"} || die("Can't assign to location without a location object"))->href(@_) 1 2 3
Condition50%1/2
$self->{'_HTML_DOM_loc'} || die(q[Can't assign to location without a location object])
l!l
10
MC/DC0%0/1
$self->{'_HTML_DOM_loc'} || die(q[Can't assign to location without a location object])
$self->{'_HTML_DOM_loc'}
Truth table50%1/2
A
A= $self->{'_HTML_DOM_loc'}
Aresult
11
00
1377 ." without a location object")->href(@_);
1378 $$self{_HTML_DOM_loc}||()
1379 3 ▶}
Branch: 1 branch
BranchTrueFalseTotal
$self->{"_HTML_DOM_loc"} or () 2 1 3
1380  
1381 1 ▶sub set_location_object {
Subroutine set_location_object: called CC=1 SCAR=0.0
Pod documented
1382 1 $_[0]{_HTML_DOM_loc} = $_[1];
1383 }
1384  
1385  
1386 =item lastModified
1387  
1388 This method returns the document's modification date as gleaned from the
1389 response object passed to the constructor, in MM/DD/YYYY HH:MM:SS format.
1390  
1391 If there is no modification date, an empty string is returned, but this
1392 may change in the future.
1393  
1394 =begin comment
1395  
1396 When there is no modification date, the return value is different in every
1397 browser.
1398 NS 2-4 and Opera 9 have the epoch (in GMT format).
1399 Firefox 3 has the time the page was loaded.
1400 Safari 4 has an empty string (it uses GMT format when there is a mod time).
1401 IE, 6-8 the only one to comply with HTML 5, has the current time; but HTML
1402 5 is illogical, since it makes no sense for the modification time to keep
1403 ticking away.
1404  
1405 I’ve opted to use the empty string for now, since we can’t *really* find
1406 out the modification time--only what the server *says* it is. And if the
1407 server doesn’t say, it’s no use pretending that it did say it.
1408  
1409 =end comment
1410  
1411 =cut
1412  
1413 4 ▶sub lastModified {
Subroutine lastModified: called CC=3 SCAR=11.0
Pod documented
1414 4 ▶ my $time = ($_[0]{_HTML_DOM_response} || return '')->last_modified
Branch: 1 branch
BranchTrueFalseTotal
my $time = ($_[0]{"_HTML_DOM_response"} || (return ""))->last_modified or return "" 2 1 3
Condition100%2/2
$_[0]{'_HTML_DOM_response'} || (return '')
l!l
31
MC/DC100%1/1
$_[0]{'_HTML_DOM_response'} || (return '')
$_[0]{'_HTML_DOM_response'}
Truth table100%2/2
A
A= $_[0]{'_HTML_DOM_response'}
Aresult
11
00
1415 or return '';
1416 2 require Date'Format;
1417 2 Date'Format'time2str("%d/%m/%Y %X", $time);
1418 }
1419  
1420  
1421 =back
1422  
1423 =cut
1424  
1425  
1426 # ---------- OVERRIDDEN NODE & EVENT TARGET METHODS -------------- #
1427  
1428 35 ▶sub ownerDocument {} # empty list
Subroutine ownerDocument: called CC=1 SCAR=0.0
Pod documented
1429 1 ▶sub nodeName { '#document' }
Subroutine nodeName: called CC=1 SCAR=0.0
Pod documented
1430 24 ▶{ no warnings 'once'; *nodeType = \& DOCUMENT_NODE; }
Subroutine BEGIN: called CC=1 SCAR=0.0
1431  
1432 =head2 Other (Non-DOM) Methods
1433  
1434 (See also L</EVENT HANDLING>, below.)
1435  
1436 =over 4
1437  
1438 =item $tree->base
1439  
1440 Returns the base URL of the page; either from a <base href=...> tag, from
1441 the response object passed to C<new>, or the
1442 URL passed to C<new>.
1443  
1444 =cut
1445  
1446 153 ▶sub base {
Subroutine base: called CC=11 SCAR=41.3
Pod documented
1447 153 my $doc = shift;
1448 153 ▶ if(
Branch: 2 branches
BranchTrueFalseTotal
if (my $base_elem = $doc->look_down('_tag', 'base', 'href', qr/(?:)/)) { } 6 147 153
elsif (my $r = $doc->{'_HTML_DOM_response'}) { } 0 147 147
1449 my $base_elem = $doc->look_down(_tag => 'base', href => qr)(?:\)))
1450 ){
1451 6 return ''.$base_elem->attr('href');
1452 }
1453 elsif (my $r = $$doc{_HTML_DOM_response}) {
1454 0 my $base;
1455 0 ▶ ($base) = $r->header('Content-Base')
Branch: 1 branch
BranchTrueFalseTotal
($base) = $r->header("Content-Base") or ($base) = $r->header("Content-Location") or $base = $r->header("Base") 0 0 0
Condition0%0/3
($base) = $r->header("Content-Base") or ($base) = $r->header("Content-Location")
l!l&&r!l&&!r
000
MC/DC0%0/2
($base) = $r->header("Content-Base") or ($base) = $r->header("Content-Location")
($base) = $r->header("Content-Base") ($base) = $r->header("Content-Location")
Truth table0%0/3
A or B
A= ($base) = $r->header("Content-Base")B= ($base) = $r->header("Content-Location")
ABresult
1X1
011
000
1456 or ($base) = $r->header('Content-Location')
1457 or $base = $r->header('Base');
1458 # URI does not document $URI::scheme_re, but HTTP::Response
1459 # (which is in a separate distribution) uses it. It seems
1460 # unlikely that it will go away in future URI versions, as
1461 # that would break existing versions of HTTP::Response.
1462 0 ▶ if ($base && $base =~ /^$URI::scheme_re:/o) {
Branch: 1 branch
BranchTrueFalseTotal
if ($base and $base =~ /^$URI::scheme_re:/o) 0 0 0
Condition0%0/3
$base and $base =~ /^$URI::scheme_re:/o
!ll&&!rl&&r
000
MC/DC0%0/2
$base and $base =~ /^$URI::scheme_re:/o
$base $base =~ /^$URI::scheme_re:/o
Truth table0%0/3
A and B
A= $baseB= $base =~ /^$URI::scheme_re:/o
ABresult
0X0
100
111
1463 # already absolute
1464 0 return $base;
1465 }
1466 0 my $req = request $r;
1467 0 ▶ my $uri = $req ? uri $req : $doc->URL;
Branch: 1 branch
BranchTrueFalseTotal
$req ? : 0 0 0
1468 0 ▶ return undef unless $uri;
Branch: 1 branch
BranchTrueFalseTotal
unless $uri 0 0 0
1469 # Work around URI bug.
1470 0 ▶ if (!defined $base && $uri =~ /^[Dd][Aa][Tt][Aa]:/) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $base and $uri =~ /^[Dd][Aa][Tt][Aa]:/) 0 0 0
Condition0%0/3
not defined $base and $uri =~ /^[Dd][Aa][Tt][Aa]:/
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $base and $uri =~ /^[Dd][Aa][Tt][Aa]:/
not defined $base $uri =~ /^[Dd][Aa][Tt][Aa]:/
Truth table0%0/3
not(A) and B
A= not defined $baseB= $uri =~ /^[Dd][Aa][Tt][Aa]:/
ABresult
0X0
100
111
1471 0 return $uri;
1472 }
1473 24 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
1474 0 ''.new_abs URI $base,$uri;
1475 }
1476 else {
1477 147 $doc->URL
1478 }
1479 }
1480  
1481 =item $tree->magic_forms
1482  
1483 This is mainly for internal use. It returns a boolean indicating whether
1484 the parser needed to associate formies with a form that did not contain
1485 them. This happens when a closing </form> tag is missing and the form is
1486 closed implicitly, but a formie is encountered later.
1487  
1488 =cut
1489  
1490 1560 ▶sub magic_forms { @_ and ++$_[0]{_HTML_DOM_mg_f}; $_[0]{_HTML_DOM_mg_f} }
Subroutine magic_forms: called CC=2 SCAR=7.2
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ and ++$_[0]{"_HTML_DOM_mg_f"} 1560 0 1560
1491  
1492 =back
1493  
1494 =head1 HASH ACCESS
1495  
1496 You can use an HTML::DOM object as a hash ref to access it's form elements
1497 by name. So C<< $doc->{yayaya} >> is short for
1498 S<< C<< $doc->forms->{yayaya} >> >>.
1499  
1500 =head1 EVENT HANDLING
1501  
1502 HTML::DOM supports both the DOM Level 2 event model and the HTML 4 event
1503 model.
1504  
1505 Throughout this documentation, we make use of HTML 5's distinction between
1506 handlers and listeners: An event handler is the result of an HTML element
1507 beginning with 'on', e.g. onsubmit. These are also accessible via the DOM.
1508 (We also use the word 'handler' in other contexts, such as the 'default
1509 event handler'.)
1510 Event listeners are registered solely with the C<addEventListener> method
1511 and can be removed with C<removeEventListener>.
1512  
1513 HTML::DOM accepts as an event handler a coderef, an object with a
1514 C<call_with> method, or an object with C<&{}> overloading. If the
1515 C<call_with> method is present, it is called with the current event
1516 target as the first argument and the event object as the second.
1517 This is to allow for objects that wrap JavaScript functions (which must be called with the event target as the B<this> value).
1518  
1519 An event listener is a coderef, an object with a C<handleEvent>
1520 method or an object with C<&{}> overloading. HTML::DOM does not implement
1521 any classes that provide a C<handleEvent> method, but will support any
1522 object that has one.
1523  
1524 Listeners and handlers differ in one important aspect. A listener has to
1525 call C<preventDefault> on the event object to cancel the default action. A
1526 handler simply returns a defined false value (except for mouseover events,
1527 which must return a true value to cancel the default).
1528  
1529 =head2 Default Actions
1530  
1531 Default actions that HTML::DOM is capable of handling internally (such as
1532 triggering a DOMActivate event when an element is clicked, and triggering a
1533 form's submit event when the submit button is activated) are dealt with
1534 automatically. You don't have to worry about those. For others, read
1535 on....
1536  
1537 To specify the default actions associated with an event, provide a
1538 subroutine (in this case, it not being part of the DOM, you can't use an
1539 object with a C<handleEvent> method) via the C<default_event_handler_for>
1540 and
1541 C<default_event_handler> methods.
1542  
1543 With the former, you can specify the
1544 default action to be taken when a particular type of event occurs. The
1545 currently supported types are:
1546  
1547 submit when a form is submitted
1548 link called when a link is activated (DOMActivate event)
1549  
1550 Pass the type of event as the first argument and a code ref as the second
1551 argument. When the code ref is called, its sole argument will
1552 be the event object. For instance:
1553  
1554 $dom_tree->default_event_handler_for( link => sub {
1555 my $event = shift;
1556 go_to( $event->target->href );
1557 });
1558 sub go_to { ... }
1559  
1560 C<default_event_handler_for> with just one argument returns the
1561 currently
1562 assigned coderef. With two arguments it returns the old one after
1563 assigning the new one.
1564  
1565 Use C<default_event_handler> (without the C<_for>) to specify a fallback
1566 subroutine that will be used for events not in the list above, and for
1567 events in the list above that do not have subroutines assigned to them.
1568 Without any arguments it will return the currently
1569 assigned coderef. With an argument it will return the old one after
1570 assigning the new one.
1571  
1572 =head2 Dispatching Events
1573  
1574 HTML::DOM::Node's C<dispatchEvent> method triggers the appropriate event
1575 listeners, but does B<not> call any default actions associated with it.
1576 The return value is a boolean that indicates whether the default action
1577 should be taken.
1578  
1579 H:D:Node's C<trigger_event> method will trigger the event for real. It will
1580 call C<dispatchEvent> and, provided it returns true, will call the default
1581 event handler.
1582  
1583 =head2 HTML Event Attributes
1584  
1585 The C<event_attr_handler> can be used to assign a coderef that will turn
1586 text assigned to an event attribute (e.g., C<onclick>) into an event
1587 handler. The
1588 arguments to the routine will be (0) the element, (1) the name (aka
1589 type) of
1590 the event (without the initial 'on'), (2) the value of the attribute and
1591 (3) the offset within the source of the attribute's value. (Actually, if
1592 the value is within quotes, it is the offset of the first quotation mark.
1593 Also, it will be C<undef> for generated HTML [source code passed to the
1594 C<write> method by an element handler].)
1595 As
1596 with C<default_event_handler>, you
1597 can replace an existing handler with a new one, in which case the old
1598 handler is returned. If you call this method without arguments, it returns
1599 the current handler. Here is an example of its use, that assumes that
1600 handlers are Perl code:
1601  
1602 $dom_tree->event_attr_handler(sub {
1603 my($elem, $name, $code, $offset) = @_;
1604 my $sub = eval "sub { $code }";
1605 return sub {
1606 local *_ = \$elem;
1607 &$sub;
1608 };
1609 });
1610  
1611 The event attribute handler will be called whenever an element attribute
1612 whose name
1613 begins with 'on' (case-tolerant) is modified. (For efficiency's sake, I may
1614 change it to call the event attribute handler only when the event is
1615 triggered, so it is not called unnecessarily.)
1616  
1617 =head2 When an Event Handler Dies
1618  
1619 Use C<error_handler> to assign a coderef that will be called whenever an
1620 event listener (or handler) raises an error. The error will be contained in
1621 C<$@>.
1622  
1623 =head2 Other Event-Related Methods
1624  
1625 =over
1626  
1627 =item $tree->event_parent
1628  
1629 =item $tree->event_parent( $new_val )
1630  
1631 This method lets you provide an object that is added to the top of the
1632 event dispatch chain. E.g., if you want the view object (the value of
1633 C<defaultView>, aka the window) to have event handlers called before the
1634 document in the capture phase, and after it in the bubbling phase, you can
1635 set it like this (see also L</defaultView>, above):
1636  
1637 $tree->event_parent( $tree->defaultView );
1638  
1639 This holds a weak reference.
1640  
1641 =item $tree->event_listeners_enabled
1642  
1643 =item $tree->event_listeners_enabled( $new_val )
1644  
1645 This attribute, which is true by default, can be used to disable event
1646 handlers and listeners. (Default event handlers [see above] still run,
1647 though.)
1648  
1649 =back
1650  
1651 =cut
1652  
1653  
1654 # ---------- NON-DOM EVENT METHODS -------------- #
1655  
1656 21 ▶sub event_attr_handler {
Subroutine event_attr_handler: called CC=2 SCAR=6.9
Pod undocumented
1657 21 my $old = $_[0]->{_HTML_DOM_event_attr_handler};
1658 21 ▶ $_[0]->{_HTML_DOM_event_attr_handler} = $_[1] if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 6 15 21
1659 21 $old;
1660 }
1661 1859 ▶sub default_event_handler {
Subroutine default_event_handler: called CC=2 SCAR=6.9
Pod undocumented
1662 1859 my $old = $_[0]->{_HTML_DOM_default_event_handler};
1663 1859 ▶ $_[0]->{_HTML_DOM_default_event_handler} = $_[1] if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 11 1848 1859
1664 1859 $old;
1665 }
1666 223 ▶sub default_event_handler_for {
Subroutine default_event_handler_for: called CC=2 SCAR=6.9
Pod undocumented
1667 223 my $old = $_[0]->{_HTML_DOM_dehf}{$_[1]};
1668 223 ▶ $_[0]->{_HTML_DOM_dehf}{$_[1]} = $_[2] if @_ > 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 2 12 211 223
1669 223 $old;
1670 }
1671 1868 ▶sub error_handler {
Subroutine error_handler: called CC=2 SCAR=6.9
Pod documented
1672 1868 my $old = $_[0]->{_HTML_DOM_error_handler};
1673 1868 ▶ $_[0]->{_HTML_DOM_error_handler} = $_[1] if @_ > 1;
Branch: 1 branch
BranchTrueFalseTotal
if @_ > 1 4 1864 1868
1674 1868 $old;
1675 }
1676  
1677 649 ▶sub event_parent {
Subroutine event_parent: called CC=2 SCAR=6.9
Pod documented
1678 649 my $old = (my $self = shift) ->{_HTML_DOM_event_parent};
1679 649 ▶ weaken($self->{_HTML_DOM_event_parent} = shift) if @_;
Branch: 1 branch
BranchTrueFalseTotal
if @_ 1 648 649
1680 649 $old
1681 }
1682  
1683 1864 ▶sub event_listeners_enabled {
Subroutine event_listeners_enabled: called CC=3 SCAR=11.0
Pod documented
1684 1864 my $old = (my $Self = shift)->{_HTML_DOM_doevents};
1685 1864 ▶ @_ and $$Self{_HTML_DOM_doevents} = !!shift;
Branch: 1 branch
BranchTrueFalseTotal
@_ and $Self->{"_HTML_DOM_doevents"} = !!(shift()) 1 1863 1864
1686 1864 ▶ defined $old ? $old : 1; # true by default
Branch: 1 branch
BranchTrueFalseTotal
defined $old ? : 1 1863 1864
1687 }
1688  
1689  
1690 # ---------- NODE AND SHEET LIST HELPER METHODS -------------- #
1691  
1692 351 ▶sub _modified { # tells all it's magic nodelists that they're stale
Subroutine _modified: called CC=5 SCAR=16.1
1693 # and also rewrites the style sheet list if present
1694 351 my $list = $_[0]{_HTML_DOM_node_lists};
1695 351 my $list_is_stale;
1696 351 for (@$list) {
1697 276 ▶ defined() ? $_->_you_are_stale : ++$list_is_stale
Branch: 1 branch
BranchTrueFalseTotal
defined $_ ? : 189 87 276
1698 }
1699 351 ▶ if($list_is_stale) {
Branch: 1 branch
BranchTrueFalseTotal
if ($list_is_stale) 48 303 351
1700 48 @$list = grep defined, @$list;
1701 48 weaken $_ for @$list;
1702 }
1703
1704 351 $_[0]->_populate_sheet_list
1705 }
1706  
1707 388 ▶sub _populate_sheet_list { # called both by styleSheets and _modified
Subroutine _populate_sheet_list: called CC=3 SCAR=11.0
1708 388 ▶ for($_[0]->{_HTML_DOM_sheets}||return) {
Condition100%2/2
$_[0]{'_HTML_DOM_sheets'} || (return)
l!l
12376
MC/DC100%1/1
$_[0]{'_HTML_DOM_sheets'} || (return)
$_[0]{'_HTML_DOM_sheets'}
Truth table100%2/2
A
A= $_[0]{'_HTML_DOM_sheets'}
Aresult
11
00
1709 12 @$_ = map sheet $_,
1710 $_[0]->look_down(_tag => qr/^(?:link|style)\z/);
1711 }
1712 }
1713  
1714 204 ▶sub _register_magic_node_list { # adds the node list to the list of magic
Subroutine _register_magic_node_list: called CC=1 SCAR=0.0
1715 # node lists that get notified automatic-
1716 # ally whenever the doc structure changes
1717 204 push @{$_[0]{_HTML_DOM_node_lists}}, $_[1];
1718 204 weaken $_[0]{_HTML_DOM_node_lists}[-1];
1719 }
1720  
1721  
1722  
1723 24 1;
1724 __END__
« DOM/EventTarget.pm ↑ Summary DOM/Element/Form.pm »