DOM/Element/Table.pm

filter: Statementstmt 96.6% 227 / 235 Branchbran 85.2% 75 / 88 Conditioncond 81.8% 36 / 44 MC/DCmcdc 65.3% 17 / 26 Subroutinesub 100% 50 / 50 Podpod 100% 22 / 22 totaltotal 91.8% 427 / 465 CC 70 SCAR 15.5
CC
70
Cov
92%
tHead
9.1
tFoot
9.1
caption
9.0
CRAP 4.7
« DOM/Attr.pm ↑ Summary DOM/CharacterData.pm »
1 package HTML::DOM::Element::Table;
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 'HIERARCHY_REQUEST_ERR INDEX_SIZE_ERR';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 25 require HTML::DOM::Collection;
9 25 require HTML::DOM::Element;
10 #require HTML::DOM::NodeList::Magic;
11  
12 25 our @ISA = qw'HTML::DOM::Element';
13 25 our $VERSION = '0.058';
14  
15 13 ▶sub caption {
Subroutine caption: called CC=9 SCAR=22.0
Pod documented
16 13 my $old = ((my $self = shift)->content_list)[0];
17 13 ▶ undef $old unless $old and $old->tag eq 'caption';
Branch: 1 branch
BranchTrueFalseTotal
unless $old and $old->tag eq "caption" 7 6 13
Condition100%3/3
$old and $old->tag eq "caption"
!ll&&!rl&&r
256
MC/DC100%2/2
$old and $old->tag eq "caption"
$old $old->tag eq "caption"
Truth table100%3/3
A and B
A= $oldB= $old->tag eq "caption"
ABresult
0X0
100
111
18 13 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 4 9 13
19 4 my $new = shift;
20 4 ▶ my $tag = (eval{$new->tag}||'');
Condition50%1/2
eval { do { $new->tag } } || ''
l!l
40
MC/DC0%0/1
eval { do { $new->tag } } || ''
eval { do { $new->tag } }
Truth table50%1/2
A
A= eval { do { $new->tag } }
Aresult
11
00
21 4 ▶ $tag eq 'caption' or die new HTML'DOM'Exception
Branch: 2 branches
BranchTrueFalseTotal
$tag eq "caption" or die "HTML::DOM::Exception"->new(3, $tag ? "A $tag element cannot be a table caption" : "Not a valid table caption") 3 1 4
$tag ? : 1 0 1
22 HIERARCHY_REQUEST_ERR,
23 $tag ? "A $tag element cannot be a table caption"
24 : "Not a valid table caption";
25 3 ▶ if ($old) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old) { } 1 2 3
26 1 $self->replaceChild($new, $old);
27 } else {
28 2 $self->unshift_content($new)
29 }
30 }
31 12 ▶ return $old || ();
Condition100%3/3
$old || ()
l!l&&r!l&&!r
624
MC/DC50%1/2
$old || ()
$old ()
Truth table66%2/3
A || B
A= $oldB= ()
ABresult
1X1
011
000
32 }
33 32 ▶sub tHead {
Subroutine tHead: called CC=9 SCAR=22.1
Pod documented
34 32 my $self = shift;
35 32 for($self->content_list) {
36 42 (my $tag = tag $_);
37 42 ▶ if($tag =~ /^t(?:head|body|foot)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^t(?:head|body|foot)\z/) 28 14 42
38 28 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 25 28
39 3 my $new = shift;
40 3 ▶ my $new_tag = (eval{$new->tag}||'');
Condition50%1/2
eval { do { $new->tag } } || ''
l!l
30
MC/DC0%0/1
eval { do { $new->tag } } || ''
eval { do { $new->tag } }
Truth table50%1/2
A
A= eval { do { $new->tag } }
Aresult
11
00
41 3 ▶ $new_tag eq 'thead' or die
Branch: 2 branches
BranchTrueFalseTotal
$new_tag eq "thead" or die "HTML::DOM::Exception"->new(3, $tag ? "A $new_tag element cannot be a table header" : "Not a valid table header") 2 1 3
$tag ? : 1 0 1
42 new HTML'DOM'Exception
43 HIERARCHY_REQUEST_ERR,
44 $tag
45 ? "A $new_tag element cannot be a table header"
46 : "Not a valid table header";
47 2 $_->${\qw[preinsert replace_with][$tag eq 'thead']}(
48 $new
49 );
50 2 $self->ownerDocument->_modified;
51 }
52 27 ▶ return $tag eq 'thead' ? $_:();
Branch: 1 branch
BranchTrueFalseTotal
$tag eq 'thead' ? : 12 15 27
53 }
54 }
55 4 ▶ @_ and $self->appendChild(shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->appendChild(shift()) 0 4 4
56 4 return;
57 }
58 32 ▶sub tFoot {
Subroutine tFoot: called CC=9 SCAR=22.1
Pod documented
59 32 my $self = shift;
60 32 for($self->content_list) {
61 56 (my $tag = tag $_);
62 56 ▶ if($tag =~ /^t(?:body|foot)\z/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($tag =~ /^t(?:body|foot)\z/) 28 28 56
63 28 ▶ if(@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 3 25 28
64 3 my $new = shift;
65 3 ▶ my $new_tag = (eval{$new->tag}||'');
Condition50%1/2
eval { do { $new->tag } } || ''
l!l
30
MC/DC0%0/1
eval { do { $new->tag } } || ''
eval { do { $new->tag } }
Truth table50%1/2
A
A= eval { do { $new->tag } }
Aresult
11
00
66 3 ▶ $new_tag eq 'tfoot' or die
Branch: 2 branches
BranchTrueFalseTotal
$new_tag eq "tfoot" or die "HTML::DOM::Exception"->new(3, $tag ? "A $new_tag element cannot be a table footer" : "Not a valid table footer") 2 1 3
$tag ? : 1 0 1
67 new HTML'DOM'Exception
68 HIERARCHY_REQUEST_ERR,
69 $tag
70 ? "A $new_tag element cannot be a table footer"
71 : "Not a valid table footer";
72 2 $_->${\qw[preinsert replace_with][$tag eq 'tfoot']}(
73 $new
74 );
75 2 $self->ownerDocument->_modified;
76 }
77 27 ▶ return $tag eq 'tfoot' ? $_ : ();
Branch: 1 branch
BranchTrueFalseTotal
$tag eq 'tfoot' ? : 12 15 27
78 }
79 }
80 4 ▶ @_ and $self->appendChild(shift);
Branch: 1 branch
BranchTrueFalseTotal
@_ and $self->appendChild(shift()) 0 4 4
81 4 return;
82 }
83 16 ▶sub rows { # ~~~ I need to make this cache the resulting collection obj
Subroutine rows: called CC=2 SCAR=6.9
Pod documented
84 16 my $self = shift;
85 16 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 2 14 16
86 # I need a grep in order to exclude text nodes.
87 2 return grep tag $_ eq 'tr', map $_->content_list,
88 map $self->$_, qw/ tHead tBodies tFoot /;
89 }
90 else {
91 my $collection = HTML::DOM::Collection->new(
92 my $list = HTML::DOM::NodeList::Magic->new(
93 18 ▶ sub { grep tag $_ eq 'tr', map $_->content_list,
Subroutine __ANON__: called CC=1 SCAR=0.0
94 map $self->$_, qw/ tHead tBodies tFoot /; }
95 14 ));
96 14 $self->ownerDocument-> _register_magic_node_list($list);
97 14 $collection;
98 }
99 }
100 26 ▶sub tBodies { # ~~~ I need to make this cache the resulting collection obj
Subroutine tBodies: called CC=2 SCAR=6.9
Pod documented
101 26 my $self = shift;
102 26 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 21 5 26
103 21 return grep tag $_ eq 'tbody', $self->content_list;
104 }
105 else {
106 my $collection = HTML::DOM::Collection->new(
107 my $list = HTML::DOM::NodeList::Magic->new(
108 5 ▶ sub { grep tag $_ eq 'tbody', $self->content_list }
Subroutine __ANON__: called CC=1 SCAR=0.0
109 5 ));
110 5 $self->ownerDocument-> _register_magic_node_list($list);
111 5 $collection;
112 }
113 }
114 30 ▶sub align { lc shift->_attr('align' => @_) }
Subroutine align: called CC=1 SCAR=0.0
Pod documented
115 15 ▶sub bgColor { shift->_attr('bgcolor' => @_) }
Subroutine bgColor: called CC=1 SCAR=0.0
Pod documented
116 5 ▶sub border { shift->_attr( border => @_) }
Subroutine border: called CC=1 SCAR=0.0
Pod documented
117 5 ▶sub cellPadding { shift->_attr('cellpadding' => @_) }
Subroutine cellPadding: called CC=1 SCAR=0.0
Pod documented
118 5 ▶sub cellSpacing { shift->_attr('cellspacing' => @_) }
Subroutine cellSpacing: called CC=1 SCAR=0.0
Pod documented
119 5 ▶sub frame { shift->_attr('frame' => @_) }
Subroutine frame: called CC=1 SCAR=0.0
Pod documented
120 5 ▶sub rules { lc shift->_attr('rules' => @_) }
Subroutine rules: called CC=1 SCAR=0.0
Pod documented
121 5 ▶sub summary { shift->_attr('summary' => @_) }
Subroutine summary: called CC=1 SCAR=0.0
Pod documented
122 10 ▶sub width { shift->_attr('width' => @_) }
Subroutine width: called CC=1 SCAR=0.0
Pod documented
123  
124 2 ▶sub createTHead {
Subroutine createTHead: called CC=5 SCAR=16.2
Pod documented
125 2 my $self = shift;
126 2 my $th = $self->tHead;
127 2 ▶ $th and return $th;
Branch: 1 branch
BranchTrueFalseTotal
$th and return $th 1 1 2
128  
129 1 my $inserted;
130 1 $th = $self->ownerDocument->createElement('thead');
131 1 for($self->content_list) {
132 1 ▶ next if tag $_ =~ /^c(?:aption|ol(?:group)?)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $_->tag =~ /^c(?:aption|ol(?:group)?)\z/ 0 1 1
133 1 $_->preinsert($th), ++$inserted,
134 $self->ownerDocument->_modified, last
135 }
136 1 ▶ $self->appendChild($th) unless $inserted;
Branch: 1 branch
BranchTrueFalseTotal
unless $inserted 0 1 1
137  
138 1 $th
139 }
140  
141 1 ▶sub deleteTHead {
Subroutine deleteTHead: called CC=2 SCAR=7.0
Pod documented
142 1 my $self = shift;
143 1 ▶ ($self->tHead||return)->delete; # ~~~ once I weaken upward refs, should I make this less destructive?
Condition50%1/2
$self->tHead || (return)
l!l
10
MC/DC0%0/1
$self->tHead || (return)
$self->tHead
Truth table50%1/2
A
A= $self->tHead
Aresult
11
00
144 1 $self->ownerDocument->_modified;
145 1 return;
146 }
147  
148 2 ▶sub createTFoot {
Subroutine createTFoot: called CC=5 SCAR=16.1
Pod documented
149 2 my $self = shift;
150 2 my $tf = $self->tFoot;
151 2 ▶ $tf and return $tf;
Branch: 1 branch
BranchTrueFalseTotal
$tf and return $tf 1 1 2
152  
153 1 my $inserted;
154 1 $tf = $self->ownerDocument->createElement('tfoot');
155 1 for($self->content_list) {
156 2 ▶ next if tag $_ =~ /^(?:c(?:aption|ol(?:group)?)|thead)\z/;
Branch: 1 branch
BranchTrueFalseTotal
if $_->tag =~ /^(?:c(?:aption|ol(?:group)?)|thead)\z/ 1 1 2
157 1 $_->preinsert($tf), ++$inserted,
158 $self->ownerDocument->_modified, last
159 }
160 1 ▶ $self->appendChild($tf) unless $inserted;
Branch: 1 branch
BranchTrueFalseTotal
unless $inserted 0 1 1
161  
162 1 $tf
163 }
164  
165 1 ▶sub deleteTFoot {
Subroutine deleteTFoot: called CC=2 SCAR=7.0
Pod documented
166 1 my $self = shift;
167 1 ▶ ($self->tFoot||return)->delete; # ~~~ once I weaken upward refs, should I make this less destructive?
Condition50%1/2
$self->tFoot || (return)
l!l
10
MC/DC0%0/1
$self->tFoot || (return)
$self->tFoot
Truth table50%1/2
A
A= $self->tFoot
Aresult
11
00
168 1 $self->ownerDocument->_modified;
169 1 return;
170 }
171  
172 2 ▶sub createCaption {
Subroutine createCaption: called CC=2 SCAR=6.9
Pod documented
173 2 my $self = shift; my $th;
174 2 ▶ $self->caption or
Branch: 1 branch
BranchTrueFalseTotal
$self->caption or $self->unshift_content($th = $self->ownerDocument->createElement("caption")), $self->ownerDocument->_modified, $th 1 1 2
175 $self->unshift_content($th =
176 $self->ownerDocument->createElement('caption')),
177 $self->ownerDocument->_modified,
178 $th;
179 }
180  
181 1 ▶sub deleteCaption {
Subroutine deleteCaption: called CC=2 SCAR=7.0
Pod documented
182 1 my $self = shift;
183 1 ▶ ($self->caption||return)->delete; # ~~~ once I weaken upward refs, should I make this less destructive?
Condition50%1/2
$self->caption || (return)
l!l
10
MC/DC0%0/1
$self->caption || (return)
$self->caption
Truth table50%1/2
A
A= $self->caption
Aresult
11
00
184 1 $self->ownerDocument->_modified;
185 1 return;
186 }
187  
188 9 ▶sub insertRow {
Subroutine insertRow: called CC=7 SCAR=19.5
Pod documented
189 9 my $self = shift;
190 9 my $ix = shift;
191 9 my $len = (my $rows = $self->rows)->length;
192 9 my $row = $self->ownerDocument->createElement('tr');
193 9 ▶ if(!$len) { # worst case
Branch: 3 branches
BranchTrueFalseTotal
if (not $len) { } 2 7 9
elsif ($ix == -1 or $ix == $len) { } 2 5 7
elsif ($ix < $len and $ix >= 0) { } 3 2 5
194 2 ▶ if(my $tb = $self->tBodies->item(0)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $tb = $self->tBodies->item(0)) { } 0 2 2
195 0 $tb->appendChild($row);
196 }
197 else {
198 2 (my $tb = $self->ownerDocument
199 ->createElement('tbody'))
200 ->appendChild($row);
201 2 $self->appendChild($tb);
202 }
203 }
204 ▶ elsif($ix == -1 || $ix == $len) {
Condition100%3/3
$ix == -1 or $ix == $len
l!l&&r!l&&!r
115
MC/DC100%2/2
$ix == -1 or $ix == $len
$ix == -1 $ix == $len
Truth table100%3/3
A or B
A= $ix == -1B= $ix == $len
ABresult
1X1
011
000
205 2 $rows->item(-1)->postinsert(
206 $row
207 );
208 2 $self->ownerDocument->_modified;
209 }
210 ▶ elsif($ix < $len && $ix >= 0) {
Condition100%3/3
$ix < $len and $ix >= 0
!ll&&!rl&&r
113
MC/DC100%2/2
$ix < $len and $ix >= 0
$ix < $len $ix >= 0
Truth table100%3/3
A and B
A= $ix < $lenB= $ix >= 0
ABresult
0X0
100
111
211 3 $rows->item($ix)->preinsert($row);
212 3 $self->ownerDocument->_modified
213 }
214 else {
215 2 die new HTML::DOM::Exception INDEX_SIZE_ERR,
216 "Index $ix is out of range"
217 }
218  
219 7 return $row;
220 }
221  
222 2 ▶sub deleteRow {
Subroutine deleteRow: called CC=2 SCAR=7.0
Pod documented
223 2 my $self = shift;
224 2 ▶ ($self->rows->item(shift)||return)->delete; # ~~~ once I weaken upward refs, should I make this less destructive?
Condition50%1/2
$self->rows->item(shift()) || (return)
l!l
20
MC/DC0%0/1
$self->rows->item(shift()) || (return)
$self->rows->item(shift())
Truth table50%1/2
A
A= $self->rows->item(shift())
Aresult
11
00
225 2 $self->ownerDocument->_modified;
226 2 return;
227 }
228  
229  
230 =head1 NAME
231  
232 HTML::DOM::Element::Table - A Perl class for representing 'table' elements in an HTML DOM tree
233  
234 =head1 VERSION
235  
236 Version 0.058
237  
238 =head1 SYNOPSIS
239  
240 use HTML::DOM;
241 $doc = HTML::DOM->new;
242 $elem = $doc->createElement('table');
243  
244 $elem->tHead;
245 $elem->tBodies->[0];
246 $elem->createTFoot;
247 # etc
248  
249 =head1 DESCRIPTION
250  
251 This class represents 'table' elements in an HTML::DOM tree. It implements the HTMLTableElement DOM interface and inherits from L<HTML::DOM::Element>
252 (q.v.).
253  
254 =head1 METHODS
255  
256 In addition to those inherited from HTML::DOM::Element and its
257 superclasses, this class implements the following DOM methods:
258  
259 =over 4
260  
261 =item caption
262  
263 =item tHead
264  
265 =item tFoot
266  
267 Each of these returns the table's corresponding element, if it exists, or
268 an empty list otherwise.
269  
270 =item rows
271  
272 Returns a collection of all table row elements, or a list in list context.
273  
274 =item tBodies
275  
276 Returns a collection of all 'tbody' elements, or a list in list context.
277  
278 =item align
279  
280 =item bgColor
281  
282 =item border
283  
284 =item cellPadding
285  
286 =item cellSpacing
287  
288 =item frame
289  
290 =item rules
291  
292 =item summary
293  
294 =item width
295  
296 These get (optionally set) the corresponding HTML attributes.
297  
298 =item createTHead
299  
300 Returns the table's 'thead' element, creating it if it doesn't exist.
301  
302 =item deleteTHead
303  
304 Deletes the table's 'thead' element.
305  
306 =item createTFoot
307  
308 Returns the table's 'tfoot' element, creating it if it doesn't exist.
309  
310 =item deleteTFoot
311  
312 Does what you would think.
313  
314 =item createCaption
315  
316 Returns the table's 'caption' element, creating it if it doesn't exist.
317  
318 =item deleteCaption
319  
320 Deletes the caption.
321  
322 =item insertRow
323  
324 Insert a new 'tr' element at the index specified by the first argument, and
325 returns that new row.
326  
327 =item deleteRow
328  
329 Deletes the row at the index specified by the first arg.
330  
331 =back
332  
333 =head1 SEE ALSO
334  
335 L<HTML::DOM>
336  
337 L<HTML::DOM::Element>
338  
339 L<HTML::DOM::Element::Caption>
340  
341 L<HTML::DOM::Element::TableColumn>
342  
343 L<HTML::DOM::Element::TableSection>
344  
345 L<HTML::DOM::Element::TR>
346  
347 L<HTML::DOM::Element::TableCell>
348  
349 =cut
350  
351  
352 # ------- HTMLTableCaptionElement interface ---------- #
353  
354 package HTML::DOM::Element::Caption;
355 25 our $VERSION = '0.058';
356 25 our @ISA = 'HTML::DOM::Element';
357 25 *align = \&HTML::DOM::Element::Table::align;
358  
359 # ------- HTMLTableColElement interface ---------- #
360  
361 package HTML::DOM::Element::TableColumn;
362 25 our $VERSION = '0.058';
363 25 our @ISA = 'HTML::DOM::Element';
364 25 *align = \&HTML::DOM::Element::Table::align;
365 20 ▶sub ch { shift->_attr('char' => @_) }
Subroutine ch: called CC=1 SCAR=0.0
366 20 ▶sub chOff { shift->_attr( charoff => @_) }
Subroutine chOff: called CC=1 SCAR=0.0
367 5 ▶sub span { shift->_attr('span' => @_) }
Subroutine span: called CC=1 SCAR=0.0
368 20 ▶sub vAlign { lc shift->_attr('valign' => @_) }
Subroutine vAlign: called CC=1 SCAR=0.0
369 5 ▶sub width { shift->_attr('width' => @_) }
Subroutine width: called CC=1 SCAR=0.0
370  
371 # ------- HTMLTableSectionElement interface ---------- #
372  
373 package HTML::DOM::Element::TableSection;
374 25 our $VERSION = '0.058';
375 25 our @ISA = 'HTML::DOM::Element';
376 25 *align = \&HTML::DOM::Element::Table::align;
377 25 *ch = \&HTML::DOM::Element::TableColumn::ch;
378 25 *chOff = \&HTML::DOM::Element::TableColumn::chOff;
379 25 *vAlign = \&HTML::DOM::Element::TableColumn::vAlign;
380 15 ▶sub rows { # ~~~ I need to make this cache the resulting collection obj
Subroutine rows: called CC=2 SCAR=6.9
381 15 my $self = shift;
382 15 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 3 12 15
383 # I need a grep in order to exclude text nodes.
384 3 return grep tag $_ eq 'tr', $self->content_list,
385 }
386 else {
387 my $collection = HTML::DOM::Collection->new(
388 my $list = HTML::DOM::NodeList::Magic->new(
389 16 ▶ sub { grep tag $_ eq 'tr', $self->content_list; }
Subroutine __ANON__: called CC=1 SCAR=0.0
390 12 ));
391 12 $self->ownerDocument-> _register_magic_node_list($list);
392 12 $collection;
393 }
394 }
395 7 ▶sub insertRow {
Subroutine insertRow: called CC=7 SCAR=19.5
396 7 my $self = shift;
397 7 ▶ my $ix = shift||0;
Condition100%2/2
shift() || 0
l!l
52
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
398 7 my $len = (my $rows = $self->rows)->length;
399 7 my $row = $self->ownerDocument->createElement('tr');
400 7 ▶ if(!$len) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $len) { } 1 6 7
elsif ($ix == -1 or $ix == $len) { } 2 4 6
elsif ($ix < $len and $ix >= 0) { } 2 2 4
401 1 $self->appendChild($row);
402 }
403 ▶ elsif($ix == -1 || $ix == $len) {
Condition100%3/3
$ix == -1 or $ix == $len
l!l&&r!l&&!r
114
MC/DC100%2/2
$ix == -1 or $ix == $len
$ix == -1 $ix == $len
Truth table100%3/3
A or B
A= $ix == -1B= $ix == $len
ABresult
1X1
011
000
404 2 $rows->item(-1)->postinsert(
405 $row
406 );
407 2 $self->ownerDocument->_modified;
408 }
409 ▶ elsif($ix < $len && $ix >= 0) {
Condition100%3/3
$ix < $len and $ix >= 0
!ll&&!rl&&r
112
MC/DC100%2/2
$ix < $len and $ix >= 0
$ix < $len $ix >= 0
Truth table100%3/3
A and B
A= $ix < $lenB= $ix >= 0
ABresult
0X0
100
111
410 2 $rows->item($ix)->preinsert($row);
411 2 $self->ownerDocument->_modified;
412 }
413 else {
414 2 die new HTML::DOM::Exception
415 HTML::DOM::Exception::INDEX_SIZE_ERR,
416 "Index $ix is out of range"
417 }
418  
419 5 return $row;
420 }
421  
422 25 *deleteRow = \&HTML::DOM::Element::Table::deleteRow;
423  
424 # ------- HTMLTableRowElement interface ---------- #
425  
426 package HTML::DOM::Element::TR;
427 25 our $VERSION = '0.058';
428 25 our @ISA = 'HTML::DOM::Element';
429 1 ▶sub rowIndex {
Subroutine rowIndex: called CC=3 SCAR=11.0
430 1 my $self = shift;
431 1 my $ix = 0;
432 1 for($self->look_up(_tag => 'table')->rows){
433 2 ▶ return $ix if $self == $_;
Branch: 1 branch
BranchTrueFalseTotal
if $self == $_ 1 1 2
434 1 $ix++
435 }
436 0 die "Internal error in HTML::DOM::Element::TR::rowIndex: " .
437 "This table row is not inside the table it is inside. " .
438 "Please report this bug."
439 }
440 1 ▶sub sectionRowIndex {
Subroutine sectionRowIndex: called CC=4 SCAR=15.9
441 1 my $self = shift;
442 1 my $parent = $self->parent;
443 1 ▶ while(!$parent->isa('HTML::DOM::Element::TableSection')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($parent->isa("HTML::DOM::Element::TableSection")) 0 1 1
444 # If we get here, there is probably something wrong, should
445 # I just throw an error instead?
446 0 $parent = $parent->parent;
447 }
448 1 my $ix = 0;
449 1 for($parent->rows){
450 1 ▶ return $ix if $self == $_;
Branch: 1 branch
BranchTrueFalseTotal
if $self == $_ 1 0 1
451 0 $ix++
452 }
453 0 die "Internal error in HTML::DOM::Element::TR::sectionRowIndex: " .
454 "This table row is not inside the table section it is " .
455 "inside. Please report this bug."
456 }
457 11 ▶sub cells { # ~~~ I need to make this cache the resulting collection obj
Subroutine cells: called CC=2 SCAR=6.9
458 11 my $self = shift;
459 11 ▶ if (wantarray) {
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 3 8 11
460 # I need a grep in order to exclude text nodes.
461 3 return grep tag $_ =~ /^t[hd]\z/, $self->content_list,
462 }
463 else {
464 my $collection = HTML::DOM::Collection->new(
465 my $list = HTML::DOM::NodeList::Magic->new(
466 14 ▶ sub { grep tag $_ =~ /^t[hd]\z/, $self->content_list; }
Subroutine __ANON__: called CC=1 SCAR=0.0
467 8 ));
468 8 $self->ownerDocument-> _register_magic_node_list($list);
469 8 $collection;
470 }
471 }
472 25 *align = \&HTML::DOM::Element::Table::align;
473 25 *bgColor = \&HTML::DOM::Element::Table::bgColor;
474 25 *ch = \&HTML::DOM::Element::TableColumn::ch;
475 25 *chOff = \&HTML::DOM::Element::TableColumn::chOff;
476 25 *vAlign = \&HTML::DOM::Element::TableColumn::vAlign;
477 6 ▶sub insertCell {
Subroutine insertCell: called CC=7 SCAR=19.5
478 6 my $self = shift;
479 6 ▶ my $ix = shift||0;
Condition100%2/2
shift() || 0
l!l
51
MC/DC100%1/1
shift() || 0
shift()
Truth table100%2/2
A
A= shift()
Aresult
11
00
480 6 my $len = (my $cels = $self->cells)->length;
481 6 my $cel = $self->ownerDocument->createElement('td');
482 6 ▶ if(!$len) {
Branch: 3 branches
BranchTrueFalseTotal
if (not $len) { } 0 6 6
elsif ($ix == -1 or $ix == $len) { } 2 4 6
elsif ($ix < $len and $ix >= 0) { } 2 2 4
483 0 $self->appendChild($cel);
484 }
485 ▶ elsif($ix == -1 || $ix == $len) {
Condition100%3/3
$ix == -1 or $ix == $len
l!l&&r!l&&!r
114
MC/DC100%2/2
$ix == -1 or $ix == $len
$ix == -1 $ix == $len
Truth table100%3/3
A or B
A= $ix == -1B= $ix == $len
ABresult
1X1
011
000
486 2 $cels->item(-1)->postinsert(
487 $cel
488 );
489 2 $self->ownerDocument->_modified;
490 }
491 ▶ elsif($ix < $len && $ix >= 0) {
Condition100%3/3
$ix < $len and $ix >= 0
!ll&&!rl&&r
112
MC/DC100%2/2
$ix < $len and $ix >= 0
$ix < $len $ix >= 0
Truth table100%3/3
A and B
A= $ix < $lenB= $ix >= 0
ABresult
0X0
100
111
492 2 $cels->item($ix)->preinsert($cel);
493 2 $self->ownerDocument->_modified;
494 }
495 else {
496 2 die new HTML::DOM::Exception
497 HTML::DOM::Exception::INDEX_SIZE_ERR,
498 "Index $ix is out of range"
499 }
500  
501 4 return $cel;
502 }
503 1 ▶sub deleteCell {
Subroutine deleteCell: called CC=2 SCAR=7.0
504 1 my $self = shift;
505 1 ▶ ($self->cells->item(shift)||return)->delete; # ~~~ once I weaken upward refs, should I make this less destructive?
Condition50%1/2
$self->cells->item(shift()) || (return)
l!l
10
MC/DC0%0/1
$self->cells->item(shift()) || (return)
$self->cells->item(shift())
Truth table50%1/2
A
A= $self->cells->item(shift())
Aresult
11
00
506 1 $self->ownerDocument->_modified;
507 1 return;
508 }
509  
510 # ------- HTMLTableCellElement interface ---------- #
511  
512 package HTML::DOM::Element::TableCell;
513 25 our $VERSION = '0.058';
514 25 our @ISA = 'HTML::DOM::Element';
515 1 ▶sub cellIndex {
Subroutine cellIndex: called CC=3 SCAR=12.5
516 1 my $self = shift;
517 1 my $ix = 0;
518 1 for($self->parent->cells){
519 1 ▶ return $ix if $self == $_;
Branch: 1 branch
BranchTrueFalseTotal
if $self == $_ 1 0 1
520 0 $ix++
521 }
522 0 die "Internal error in HTML::DOM::Element::TR::rowIndex: " .
523 "This table row is not inside the table it is inside. " .
524 "Please report this bug."
525 }
526 5 ▶sub abbr { shift->_attr('abbr' => @_) }
Subroutine abbr: called CC=1 SCAR=0.0
527 25 *align = \&HTML::DOM::Element::Table::align;
528 5 ▶sub axis { shift->_attr('axis' => @_) }
Subroutine axis: called CC=1 SCAR=0.0
529 25 *bgColor = \&HTML::DOM::Element::Table::bgColor;
530 25 *ch = \&HTML::DOM::Element::TableColumn::ch;
531 25 *chOff = \&HTML::DOM::Element::TableColumn::chOff;
532 5 ▶sub colSpan { shift->_attr('colspan' => @_) }
Subroutine colSpan: called CC=1 SCAR=0.0
533 5 ▶sub headers { shift->_attr('headers' => @_) }
Subroutine headers: called CC=1 SCAR=0.0
534 5 ▶sub height { shift->_attr('height' => @_) }
Subroutine height: called CC=1 SCAR=0.0
535 6 ▶sub noWrap { shift->_attr(nowrap => @_ ? $_[0] ? 'nowrap' : undef : ()) }
Subroutine noWrap: called CC=3 SCAR=11.0
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 4 2 6
$_[0] ? : 2 2 4
536 5 ▶sub rowSpan { shift->_attr('rowspan' => @_) }
Subroutine rowSpan: called CC=1 SCAR=0.0
537 5 ▶sub scope { lc shift->_attr('scope' => @_) }
Subroutine scope: called CC=1 SCAR=0.0
538 25 *vAlign = \&HTML::DOM::Element::TableColumn::vAlign;
539 25 *width = \&HTML::DOM::Element::Table::width;
540  
« DOM/Attr.pm ↑ Summary DOM/CharacterData.pm »