lib/HTML/Object/DOM/Element/Table.pm

filter: Statementstmt 72.7% 211 / 290 Branchbran 49.1% 61 / 124 Conditioncond 40.4% 38 / 94 MC/DCmcdc 19.6% 10 / 51 Subroutinesub 85.4% 41 / 48 Podpod 100% 25 / 25 totaltotal 61.0% 386 / 632 CC 102 SCAR 37.0
CC
102
Cov
61%
insertRow
199.4
_create_tsection
46.7
__ANON__
40.0
CRAP 40.6
« lib/HTML/Object/XPath/Step.pm ↑ Summary lib/HTML/Object/EventTarget.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/Table.pm
3 ## Version v0.3.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/23
7 ## Modified 2025/10/16
8 ## All rights reserved.
9 ##
10 ##
11 ## This program is free software; you can redistribute it and/or modify it
12 ## under the same terms as Perl itself.
13 ##----------------------------------------------------------------------------
14 package HTML::Object::DOM::Element::Table;
15 BEGIN
16 {
17 2 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶ use parent qw( HTML::Object::DOM::Element );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶ use vars qw( $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶ use HTML::Object::DOM::Element::Shared qw( :table );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 our $VERSION = 'v0.3.0';
25 };
26  
27 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 sub init
31 {
32 1 ▶ my $self = shift( @_ );
Subroutine init: called CC=4 SCAR=14.0
Pod documented
33 1 $self->{_init_strict_use_sub} = 1;
34 1 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 1 1
35 1 ▶ $self->{tag} = 'table' if( !defined( $self->{tag} ) || !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"tag"} and length qq[$self->{"tag"}] 0 1 1
Condition33%1/3
defined $self->{"tag"} and length qq[$self->{"tag"}]
!ll&&!rl&&r
001
MC/DC0%0/2
defined $self->{"tag"} and length qq[$self->{"tag"}]
defined $self->{"tag"} length qq[$self->{"tag"}]
Truth table33%1/3
A and B
A= defined $self->{"tag"}B= length qq[$self->{"tag"}]
ABresult
0X0
100
111
36 1 $self->{_table_reset_caption} = 1;
37 1 $self->{_table_reset_tbody} = 1;
38 1 $self->{_table_reset_tfoot} = 1;
39 1 $self->{_table_reset_thead} = 1;
40 1 $self->{_table_reset_rows} = 1;
41 1 $self->{_reset_fields} = [qw( _table_reset_caption _table_reset_tbody _table_reset_tfoot _table_reset_thead _table_reset_rows )];
42 my $callback = sub
43 {
44 16 ▶ my $def = shift( @_ );
Subroutine __ANON__: called CC=2 SCAR=6.9
45 # my $info = [caller(5)];
46 # print( STDERR ref( $self ), "::children->callback(add): called from package ", $info->[0], " at line ", $info->[2], " for '", $def->{added}->[0], "'\n" );
47  
48 # Our children were modified from outside our package.
49 # We need to check if it affects our rows and reset the cache accordingly
50 16 ▶ unless( $def->{caller}->[0] eq ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless ($def->{"caller"}[0] eq ref $self) 12 4 16
51 {
52 # my $has_row = 0;
53 # for( @{$def->{data}} )
54 # {
55 # $has_row++, last if( $self->_is_a( $_ => 'HTML::Object::DOM::Element::TableRow' ) );
56 # }
57 # $self->_reset_table( 'rows' ) if( $has_row );
58 12 $self->_reset_table( 'all' );
59 }
60 16 return(1);
61 1 };
62 1 $self->children->callback( add => $callback );
63 1 $self->children->callback( remove => $callback );
64 1 return( $self );
65 }
66  
67 # Note: deprecated property align is inherited
68  
69 # Note: deprecated property bgColor
70 0 ▶sub bgColor : lvalue { return( shift->_set_get_property( 'bgcolor', @_ ) ); }
Subroutine bgColor: not called CC=1 SCAR=6.9
Pod documented
71  
72 # Note: deprecated property border
73 0 ▶sub border : lvalue { return( shift->_set_get_property( 'border', @_ ) ); }
Subroutine border: not called CC=1 SCAR=6.9
Pod documented
74  
75 # Note: property caption
76 4 ▶sub caption : lvalue { return( shift->_set_get_section( caption => 'HTML::Object::DOM::Element::TableCaption', @_ ) ); }
Subroutine caption: called CC=1 SCAR=0.0
Pod documented
77  
78 # Note: deprecated property cellPadding
79 0 ▶sub cellPadding : lvalue { return( shift->_set_get_property( 'cellpadding', @_ ) ); }
Subroutine cellPadding: not called CC=1 SCAR=6.9
Pod documented
80  
81 # Note: deprecated property cellSpacing
82 0 ▶sub cellSpacing : lvalue { return( shift->_set_get_property( 'cellspacing', @_ ) ); }
Subroutine cellSpacing: not called CC=1 SCAR=6.9
Pod documented
83  
84 sub createCaption
85 {
86 1 ▶ my $self = shift( @_ );
Subroutine createCaption: called CC=8 SCAR=33.3
Pod documented
87 1 ▶ if( $self->{_table_captions} && !$self->_is_table_reset( 'caption' ) && !$self->{_table_captions}->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_table_captions"} and not $self->_is_table_reset("caption") and not $self->{"_table_captions"}->is_empty) 0 1 1
Condition33%2/6
$self->{"_table_captions"} and not $self->_is_table_reset("caption") and not $self->{"_table_captions"}->is_empty
!ll&&!rl&&r
100
$self->{"_table_captions"} and not $self->_is_table_reset("caption")
!ll&&!rl&&r
100
MC/DC0%0/3
$self->{"_table_captions"} and not $self->_is_table_reset("caption") and not $self->{"_table_captions"}->is_empty
$self->{"_table_captions"} not $self->_is_table_reset("caption") not $self->{"_table_captions"}->is_empty
Truth table25%1/4
A and not(B) and not(C)
A= $self->{"_table_captions"}B= not $self->_is_table_reset("caption")C= not $self->{"_table_captions"}->is_empty
ABCresult
0XX0
10X0
1100
1111
88 {
89 0 return( $self->{_table_captions}->first );
90 }
91  
92 1 ▶ my $list = $self->children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Element::TableCaption' ) });
Subroutine __ANON__: called CC=1 SCAR=0.0
93 1 my $capt = $list->first;
94 1 ▶ if( !$capt )
Branch: 1 branch
BranchTrueFalseTotal
unless ($capt) 0 1 1
95 {
96 0 ▶ $self->_load_class( 'HTML::Object::DOM::Element::TableCaption' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Element::TableCaption") or return $self->pass_error 0 0 0
97 return( $self->pass_error );
98 0 ▶ $capt = HTML::Object::DOM::Element::TableCaption->new( @_ ) ||
Condition0%0/2
'HTML::Object::DOM::Element::TableCaption'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableCaption'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Element::TableCaption'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableCaption'->error))
'HTML::Object::DOM::Element::TableCaption'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Element::TableCaption'->new(@_)
Aresult
11
00
99 return( $self->pass_error( HTML::Object::DOM::Element::TableCaption->error ) );
100 0 $capt->close;
101 0 $capt->parent( $self );
102 0 $self->children->unshift( $capt );
103 0 $list->unshift( $capt );
104 0 $self->reset(1);
105 0 ▶ $self->_load_class( 'HTML::Object::DOM::Collection' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Collection") or return $self->pass_error 0 0 0
106 return( $self->pass_error );
107 0 $self->{_table_captions} = HTML::Object::DOM::Collection->new( $list );
108 0 $self->_remove_table_reset( 'caption' );
109 }
110 1 return( $capt );
111 }
112  
113 1 ▶sub createTBody { return( shift->_create_tsection( tbody => @_ ) ); }
Subroutine createTBody: called CC=1 SCAR=0.0
Pod documented
114  
115 1 ▶sub createTFoot { return( shift->_create_tsection( tfoot => @_ ) ); }
Subroutine createTFoot: called CC=1 SCAR=0.0
Pod documented
116  
117 1 ▶sub createTHead { return( shift->_create_tsection( thead => @_ ) ); }
Subroutine createTHead: called CC=1 SCAR=0.0
Pod documented
118  
119 1 ▶sub deleteCaption { return( shift->_delete_first_element( caption => @_ ) ); }
Subroutine deleteCaption: called CC=1 SCAR=0.0
Pod documented
120  
121 sub deleteRow
122 {
123 1 ▶ my $self = shift( @_ );
Subroutine deleteRow: called CC=9 SCAR=24.3
Pod documented
124 1 my $pos = shift( @_ );
125 1 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos and $self->_is_integer($pos) 0 1 1
Condition20%1/5
defined $pos and $self->_is_integer($pos)
!ll&&!rl&&r
001
$pos // ""
l!l
00
MC/DC0%0/2
defined $pos and $self->_is_integer($pos)
defined $pos $self->_is_integer($pos)
MC/DC0%0/1
$pos // ""
$pos
Truth table33%1/3
A and B
A= defined $posB= $self->_is_integer($pos)
ABresult
0X0
100
111
Truth table0%0/2
A
A= $pos
Aresult
11
00
126 message => "Value provided (" . overload::StrVal( $pos // '' ) . ") is not an integer.",
127 class => 'HTML::Object::IndexSizeError',
128 }) ) if( !defined( $pos ) || !$self->_is_integer( $pos ) );
129 1 my $rows = $self->rows;
130 1 my $size = $rows->size;
131 1 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if $pos > $size 0 1 1
132 message => "Value provided ($pos) is greater than the zero-based number of rows available (" . $rows->size . ").",
133 class => 'HTML::Object::IndexSizeError',
134 }) ) if( $pos > $size );
135 1 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 and abs $pos > $size 0 1 1
Condition33%1/3
$pos < 0 and abs $pos > $size
!ll&&!rl&&r
010
MC/DC0%0/2
$pos < 0 and abs $pos > $size
$pos < 0 abs $pos > $size
Truth table33%1/3
A and B
A= $pos < 0B= abs $pos > $size
ABresult
0X0
100
111
136 message => "Value provided ($pos) is lower than the zero-based number of rows available (" . $rows->size . "). If you want to specify a negative index, it must be between -1 and -${size}",
137 class => 'HTML::Object::IndexSizeError',
138 }) ) if( $pos < 0 && abs( $pos ) > $size );
139 1 ▶ $pos = ( $rows->length + $pos ) if( $pos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 1 0 1
140 1 my $elem = $rows->index( $pos );
141 1 my $parent = $elem->parent;
142 1 my $children = $parent->children;
143 1 my $kid_pos = $children->pos( $elem );
144 1 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kid_pos 0 1 1
145 message => "Unable to find the row element for index $pos",
146 class => 'HTML::Object::HierarchyRequestError',
147 }) ) if( !defined( $kid_pos ) );
148 1 my $rv = $children->splice( $kid_pos, 1 );
149 1 $elem->parent( undef );
150 1 $parent->reset(1);
151 1 $self->_reset_table( 'rows' );
152 1 return( $elem );
153 }
154  
155 1 ▶sub deleteTFoot { return( shift->_delete_first_element( tfoot => @_ ) ); }
Subroutine deleteTFoot: called CC=1 SCAR=0.0
Pod documented
156  
157 1 ▶sub deleteTHead { return( shift->_delete_first_element( thead => @_ ) ); }
Subroutine deleteTHead: called CC=1 SCAR=0.0
Pod documented
158  
159 # Note: deprecated property frame
160 0 ▶sub frame : lvalue { return( shift->_set_get_property( 'frame', @_ ) ); }
Subroutine frame: not called CC=1 SCAR=6.9
Pod documented
161  
162 sub insertRow
163 {
164 1 ▶ my $self = shift( @_ );
Subroutine insertRow: called CC=20 SCAR=53.0
Pod documented
165 1 my $pos = shift( @_ );
166 1 my $rows = $self->rows;
167 1 my $size = $rows->size;
168 1 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 0 1 1
169 {
170 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_integer($pos) 0 0 0
Condition0%0/2
$pos // ""
l!l
00
MC/DC0%0/1
$pos // ""
$pos
Truth table0%0/2
A
A= $pos
Aresult
11
00
171 message => "Value provided (" . overload::StrVal( $pos // '' ) . ") is not an integer.",
172 class => 'HTML::Object::IndexSizeError',
173 }) ) if( !$self->_is_integer( $pos ) );
174 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if $pos > $size 0 0 0
175 message => "Value provided ($pos) is greater than the zero-based number of rows available (" . $rows->size . ").",
176 class => 'HTML::Object::IndexSizeError',
177 }) ) if( $pos > $size );
178 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 and abs $pos > $size 0 0 0
Condition0%0/3
$pos < 0 and abs $pos > $size
!ll&&!rl&&r
000
MC/DC0%0/2
$pos < 0 and abs $pos > $size
$pos < 0 abs $pos > $size
Truth table0%0/3
A and B
A= $pos < 0B= abs $pos > $size
ABresult
0X0
100
111
179 message => "Value provided ($pos) is lower than the zero-based number of rows available (" . $rows->size . "). If you want to specify a negative index, it must be between -1 and -${size}",
180 class => 'HTML::Object::IndexSizeError',
181 }) ) if( $pos < 0 && abs( $pos ) > $size );
182 0 ▶ $pos = ( $rows->length + $pos ) if( $pos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 0 0
183 }
184 # "If a table has multiple <tbody> elements, by default, the new row is inserted into the last <tbody>."
185 1 my $body = $self->tbodies->last;
186 # If there is no tbody and no rows yet, we create a tbody
187 1 ▶ if( !$rows->length && !$body )
Branch: 1 branch
BranchTrueFalseTotal
unless ($rows->length or $body) 0 1 1
Condition33%1/3
$rows->length or $body
l!l&&r!l&&!r
100
MC/DC0%0/2
$rows->length or $body
$rows->length $body
Truth table33%1/3
A or B
A= $rows->lengthB= $body
ABresult
1X1
011
000
188 {
189 0 $body = $self->createTBody();
190 }
191 1 ▶ $self->_load_class( 'HTML::Object::DOM::Element::TableRow' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Element::TableRow") or return $self->pass_error 0 1 1
192 1 my $row;
193 # A position was provided
194 1 ▶ if( defined( $pos ) )
Branch: 2 branches
BranchTrueFalseTotal
if (defined $pos) { } 0 1 1
elsif ($body) { } 1 0 1
195 {
196 # ..., but there are no rows yet
197 0 ▶ if( $rows->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($rows->is_empty) { } 0 0 0
198 {
199 # if we have a tbody, we add the new row there
200 0 ▶ if( $body )
Branch: 1 branch
BranchTrueFalseTotal
if ($body) { } 0 0 0
201 {
202 0 $row = $body->insertRow();
203 }
204 # otherwise, we just add as the last child of the table.
205 # However, this should not happen, because if there are no rows and no tbody, oen is created and this condition is never reached
206 else
207 {
208 0 $self->children->push( $row );
209 0 $row->parent( $self );
210 0 $self->reset(1);
211 }
212 }
213 else
214 {
215 0 my $elem = $rows->index( $pos );
216 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
217 message => "No element could be found at row index $pos",
218 class => 'HTML::Object::HierarchyRequestError',
219 }) ) if( !defined( $elem ) );
220 0 my $parent = $elem->parent;
221 0 my $children = $parent->children;
222 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $parent 0 0 0
223 message => "Element at row index $pos has no parent!",
224 class => 'HTML::Object::HierarchyRequestError',
225 }) ) if( !$parent );
226 0 my $real_pos = $children->pos( $elem );
227 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $real_pos 0 0 0
228 message => "Unable to find the row element for index $pos",
229 class => 'HTML::Object::HierarchyRequestError',
230 }) ) if( !defined( $real_pos ) );
231 0 ▶ $row = HTML::Object::DOM::Element::TableRow->new( @_ ) ||
Condition0%0/2
'HTML::Object::DOM::Element::TableRow'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableRow'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Element::TableRow'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableRow'->error))
'HTML::Object::DOM::Element::TableRow'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Element::TableRow'->new(@_)
Aresult
11
00
232 return( $self->pass_error( HTML::Object::DOM::Element::TableRow->error ) );
233 0 $row->close;
234 0 $row->parent( $parent );
235 0 $children->splice( $real_pos, 0, $row );
236 0 $parent->reset(1);
237 }
238 }
239 # If there is already a tbody, the new row will be added there
240 elsif( $body )
241 {
242 1 $row = $body->insertRow();
243 }
244 # otherwise, there are already other rows directly under <table> and the new row is just added at the end of the table, even if there is a <tfoot> element.
245 else
246 {
247 0 ▶ $row = HTML::Object::DOM::Element::TableRow->new( @_ ) ||
Condition0%0/2
'HTML::Object::DOM::Element::TableRow'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableRow'->error))
l!l
00
MC/DC0%0/1
'HTML::Object::DOM::Element::TableRow'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableRow'->error))
'HTML::Object::DOM::Element::TableRow'->new(@_)
Truth table0%0/2
A
A= 'HTML::Object::DOM::Element::TableRow'->new(@_)
Aresult
11
00
248 return( $self->pass_error( HTML::Object::DOM::Element::TableRow->error ) );
249 0 $row->close;
250 0 $self->children->push( $row );
251 0 $row->parent( $self );
252 0 $self->reset(1);
253 }
254 1 $self->_reset_table( 'rows' );
255 1 return( $row );
256 }
257  
258 # Note: property rows read-only
259 sub rows
260 {
261 21 ▶ my $self = shift( @_ );
Subroutine rows: called CC=6 SCAR=18.0
Pod documented
262 21 ▶ return( $self->{_table_rows} ) if( $self->{_table_rows} && !$self->_is_table_reset( qw( rows tbody tfoot thead ) ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_table_rows"} and not $self->_is_table_reset("rows", "tbody", "tfoot", "thead") 2 19 21
Condition100%3/3
$self->{"_table_rows"} and not $self->_is_table_reset("rows", "tbody", "tfoot", "thead")
!ll&&!rl&&r
1182
MC/DC100%2/2
$self->{"_table_rows"} and not $self->_is_table_reset("rows", "tbody", "tfoot", "thead")
$self->{"_table_rows"} not $self->_is_table_reset("rows", "tbody", "tfoot", "thead")
Truth table100%3/3
A and not(B)
A= $self->{"_table_rows"}B= not $self->_is_table_reset("rows", "tbody", "tfoot", "thead")
ABresult
0X0
100
111
263 19 my $results = $self->new_array;
264 19 my $children = $self->children;
265 $children->foreach(sub
266 {
267 140 ▶ my $tag = $_->tag;
Subroutine __ANON__: called CC=6 SCAR=18.0
268 140 ▶ if( $tag eq 'tr' )
Branch: 2 branches
BranchTrueFalseTotal
if ($tag eq 'tr') { } 0 140 140
elsif ($tag eq 'tbody' or $tag eq 'tfoot' or $tag eq 'thead') { } 36 104 140
269 {
270 0 $results->push( $_ );
271 }
272 ▶ elsif( $tag eq 'tbody' || $tag eq 'tfoot' || $tag eq 'thead' )
Condition100%6/6
$tag eq "tbody" or $tag eq "tfoot" or $tag eq "thead"
l!l&&r!l&&!r
2214104
$tag eq "tbody" or $tag eq "tfoot"
l!l&&r!l&&!r
157118
MC/DC100%3/3
$tag eq "tbody" or $tag eq "tfoot" or $tag eq "thead"
$tag eq "tbody" $tag eq "tfoot" $tag eq "thead"
Truth table100%4/4
A or B or C
A= $tag eq "tbody"B= $tag eq "tfoot"C= $tag eq "thead"
ABCresult
1XX1
01X1
0011
0000
273 {
274 36 my $rows = $_->rows;
275 36 ▶ $results->push( $rows->list ) if( !$rows->is_empty );
Branch: 1 branch
BranchTrueFalseTotal
unless $rows->is_empty 32 4 36
276 }
277 140 return(1);
278 19 });
279 19 ▶ unless( $self->{_table_rows} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_table_rows"}) 1 18 19
280 {
281 1 ▶ $self->_load_class( 'HTML::Object::DOM::Collection' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Collection") or return $self->pass_error 0 1 1
282 return( $self->pass_error );
283 1 ▶ $self->{_table_rows} = HTML::Object::DOM::Collection->new ||
Condition50%1/2
'HTML::Object::DOM::Collection'->new || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
l!l
10
MC/DC0%0/1
'HTML::Object::DOM::Collection'->new || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
'HTML::Object::DOM::Collection'->new
Truth table50%1/2
A
A= 'HTML::Object::DOM::Collection'->new
Aresult
11
00
284 return( $self->pass_error( HTML::Object::DOM::Collection->error ) );
285 }
286 # Re-use the same object, so that we can update the object the user may have retrieved
287 # e.g.:
288 # my $rows = $table->rows
289 # then do some row changes, and
290 # say $rows->length; # shows updated number of rows. No need to redo $table->rows
291 19 $self->{_table_rows}->set( $results );
292 19 $self->_remove_table_reset( 'rows' );
293 19 return( $self->{_table_rows} );
294 }
295  
296 # Note: deprecated property rules
297 0 ▶sub rules : lvalue { return( shift->_set_get_property( 'rules', @_ ) ); }
Subroutine rules: not called CC=1 SCAR=6.9
Pod documented
298  
299 # Note: deprecated property summary
300 0 ▶sub summary : lvalue { return( shift->_set_get_property( 'summary', @_ ) ); }
Subroutine summary: not called CC=1 SCAR=6.9
Pod documented
301  
302 # Note: property tBodies read-only
303 5 ▶sub tBodies { return( shift->_get_tsection_collection( 'tbody' ) ); }
Subroutine tBodies: called CC=1 SCAR=0.0
Pod documented
304  
305 5 ▶sub tbodies { return( shift->tBodies( @_ ) ); }
Subroutine tbodies: called CC=1 SCAR=0.0
Pod documented
306  
307 # Note: property tFoot
308 1 ▶sub tFoot : lvalue { return( shift->_set_get_section( tfoot => 'HTML::Object::DOM::Element::TableSection', @_ ) ); }
Subroutine tFoot: called CC=1 SCAR=0.0
Pod documented
309  
310 1 ▶sub tfoot : lvalue { return( shift->tFoot( @_ ) ); }
Subroutine tfoot: called CC=1 SCAR=0.0
Pod documented
311  
312 # Note: property tHead
313 1 ▶sub tHead : lvalue { return( shift->_set_get_section( thead => 'HTML::Object::DOM::Element::TableSection', @_ ) ); }
Subroutine tHead: called CC=1 SCAR=0.0
Pod documented
314  
315 1 ▶sub thead : lvalue { return( shift->tHead( @_ ) ); }
Subroutine thead: called CC=1 SCAR=0.0
Pod documented
316  
317 # Note: deprecated property width is inherited
318  
319 # Common for tbody, thead and tfoot
320 sub _create_tsection
321 {
322 3 ▶ my $self = shift( @_ );
Subroutine _create_tsection: called CC=15 SCAR=38.4
323 3 ▶ my $tag = shift( @_ ) || return( $self->error( "No tag name was provided for this table section." ) );
Condition50%1/2
shift @_ || (return $self->error('No tag name was provided for this table section.'))
l!l
30
MC/DC0%0/1
shift @_ || (return $self->error('No tag name was provided for this table section.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
324 3 my $opts = $self->_get_args_as_hash( @_ );
325 3 ▶ $self->_load_class( 'HTML::Object::DOM::Element::TableSection' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Element::TableSection") or return $self->pass_error 0 3 3
326 return( $self->pass_error );
327 3 $opts->{tag} = $tag;
328 3 my $children = $self->children;
329 3 ▶ my $elem = HTML::Object::DOM::Element::TableSection->new( %$opts ) ||
Condition50%1/2
'HTML::Object::DOM::Element::TableSection'->new(%$opts) || (return $self->pass_error('HTML::Object::DOM::Element::TableSection'->error))
l!l
30
MC/DC0%0/1
'HTML::Object::DOM::Element::TableSection'->new(%$opts) || (return $self->pass_error('HTML::Object::DOM::Element::TableSection'->error))
'HTML::Object::DOM::Element::TableSection'->new(%$opts)
Truth table50%1/2
A
A= 'HTML::Object::DOM::Element::TableSection'->new(%$opts)
Aresult
11
00
330 return( $self->pass_error( HTML::Object::DOM::Element::TableSection->error ) );
331 3 $elem->close;
332 3 $elem->parent( $self );
333 3 ▶ my $list = $children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Element::TableSection' ) && $_->tag eq $tag });
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($_, "HTML::Object::DOM::Element::TableSection") and $_->tag eq $tag 11 24 35
334 3 ▶ if( $tag eq 'tbody' )
Branch: 3 branches
BranchTrueFalseTotal
if ($tag eq 'tbody') { } 1 2 3
elsif ($tag eq 'tfoot') { } 1 1 2
elsif ($tag eq 'thead') { } 1 0 1
335 {
336 1 my $last_elem = $list->last;
337 1 ▶ if( $last_elem )
Branch: 1 branch
BranchTrueFalseTotal
if ($last_elem) { } 1 0 1
338 {
339 1 $last_elem->after( $elem );
340 }
341 else
342 {
343 0 $children->push( $elem );
344 }
345 1 $self->reset(1);
346 1 $self->_reset_table( $tag );
347 }
348 elsif( $tag eq 'tfoot' )
349 {
350 1 ▶ if( $list->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($list->is_empty) { } 0 1 1
351 {
352 0 $children->push( $elem );
353 0 $self->reset(1);
354 0 $self->_reset_table( $tag );
355 }
356 else
357 {
358 1 return( $list->first );
359 }
360 }
361 elsif( $tag eq 'thead' )
362 {
363 1 ▶ if( $list->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($list->is_empty) { } 0 1 1
364 {
365 0 my $len = $children->length;
366 0 my $pos;
367 0 ▶ for( my $i = 0; $i < $len; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 0 0 0
368 {
369 0 my $e = $children->[$i];
370 0 ▶ next if( !$e->_is_a( 'HTML::Object::DOM::Node' ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $e->_is_a("HTML::Object::DOM::Node") 0 0 0
371 0 my $tag = $e->tag;
372 0 ▶ if( $tag ne 'caption' && $tag ne 'colgroup' )
Branch: 1 branch
BranchTrueFalseTotal
if ($tag ne "caption" and $tag ne "colgroup") 0 0 0
Condition0%0/3
$tag ne "caption" and $tag ne "colgroup"
!ll&&!rl&&r
000
MC/DC0%0/2
$tag ne "caption" and $tag ne "colgroup"
$tag ne "caption" $tag ne "colgroup"
Truth table0%0/3
A and B
A= $tag ne "caption"B= $tag ne "colgroup"
ABresult
0X0
100
111
373 {
374 0 $pos = $i;
375 0 $children->splice( $i, 0, $elem );
376 0 $self->reset(1);
377 0 $self->_reset_table( $tag );
378 0 last;
379 }
380 }
381 0 ▶ if( !defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pos) 0 0 0
382 {
383 0 $children->push( $elem );
384 0 $self->reset(1);
385 0 $self->_reset_table( $tag );
386 }
387 }
388 else
389 {
390 1 return( $list->first );
391 }
392 }
393 1 return( $elem );
394 }
395  
396 sub _delete_first_element
397 {
398 3 ▶ my $self = shift( @_ );
Subroutine _delete_first_element: called CC=5 SCAR=16.4
399 3 ▶ my $tag = shift( @_ ) || return( $self->error( "No tag was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No tag was provided.'))
l!l
30
MC/DC0%0/1
shift @_ || (return $self->error('No tag was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
400 3 $tag = lc( $tag );
401 3 my $children = $self->children;
402 3 my $len = $children->length;
403 3 ▶ for( my $i = 0; $i < $len; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 15 0 15
404 {
405 15 ▶ if( $self->_is_a( $children->[$i] => 'HTML::Object::Element' ) &&
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($children->[$i], "HTML::Object::Element") and $children->[$i]->tag eq $tag) 3 12 15
Condition66%2/3
$self->_is_a($children->[$i], "HTML::Object::Element") and $children->[$i]->tag eq $tag
!ll&&!rl&&r
0123
MC/DC50%1/2
$self->_is_a($children->[$i], "HTML::Object::Element") and $children->[$i]->tag eq $tag
$self->_is_a($children->[$i], "HTML::Object::Element") $children->[$i]->tag eq $tag
Truth table66%2/3
A and B
A= $self->_is_a($children->[$i], "HTML::Object::Element")B= $children->[$i]->tag eq $tag
ABresult
0X0
100
111
406 $children->[$i]->tag eq $tag )
407 {
408 3 my $elem = $children->[$i];
409 3 $children->splice( $i, 1 );
410 3 $elem->parent( undef );
411 3 $self->reset(1);
412 3 $self->_reset_table( $tag );
413 3 return( $elem );
414 }
415 }
416 0 return;
417 }
418  
419 sub _get_tsection_collection
420 {
421 10 ▶ my $self = shift( @_ );
Subroutine _get_tsection_collection: called CC=6 SCAR=18.0
422 10 ▶ my $tag = shift( @_ ) || return( $self->error( "No tag name was provided for this table section." ) );
Condition50%1/2
shift @_ || (return $self->error('No tag name was provided for this table section.'))
l!l
100
MC/DC0%0/1
shift @_ || (return $self->error('No tag name was provided for this table section.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
423 10 my $cache_name = "_table_collection_${tag}";
424 10 ▶ return( $self->{ $cache_name } ) if( $self->{ $cache_name } && !$self->_is_table_reset( $tag ) );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{$cache_name} and not $self->_is_table_reset($tag) 2 8 10
Condition100%3/3
$self->{$cache_name} and not $self->_is_table_reset($tag)
!ll&&!rl&&r
442
MC/DC100%2/2
$self->{$cache_name} and not $self->_is_table_reset($tag)
$self->{$cache_name} not $self->_is_table_reset($tag)
Truth table100%3/3
A and not(B)
A= $self->{$cache_name}B= not $self->_is_table_reset($tag)
ABresult
0X0
100
111
425 8 my $results = $self->new_array;
426 8 my $children = $self->children;
427 $children->foreach(sub
428 {
429 # if( $_->tag eq $tag && !$self->_is_a( $_ => 'HTML::Object::DOM::Closing' ) )
430 90 ▶ if( $_->tag eq $tag )
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
if ($_->tag eq $tag) 8 82 90
431 {
432 8 $results->push( $_ );
433 }
434 8 });
435 8 ▶ $self->_load_class( 'HTML::Object::DOM::Collection' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Collection") or return $self->pass_error 0 8 8
436 8 ▶ my $col = HTML::Object::DOM::Collection->new( $results ) ||
Condition50%1/2
'HTML::Object::DOM::Collection'->new($results) || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
l!l
80
MC/DC0%0/1
'HTML::Object::DOM::Collection'->new($results) || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
'HTML::Object::DOM::Collection'->new($results)
Truth table50%1/2
A
A= 'HTML::Object::DOM::Collection'->new($results)
Aresult
11
00
437 return( $self->pass_error( HTML::Object::DOM::Collection->error ) );
438 8 $self->{ $cache_name } = $col;
439 8 $self->_remove_table_reset( $tag );
440 8 return( $col );
441 }
442  
443 sub _is_table_reset
444 {
445 26 ▶ my $self = shift( @_ );
Subroutine _is_table_reset: called CC=9 SCAR=28.9
446 26 my @types = @_;
447 26 my $type = shift( @_ );
448 26 ▶ if( scalar( @types ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @types) { } 26 0 26
449 {
450 26 foreach my $type ( @types )
451 {
452 38 ▶ if( defined( $type ) && CORE::length( $type ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $type and length $type) 38 0 38
Condition33%1/3
defined $type and length $type
!ll&&!rl&&r
0038
MC/DC0%0/2
defined $type and length $type
defined $type length $type
Truth table33%1/3
A and B
A= defined $typeB= length $type
ABresult
0X0
100
111
453 {
454 38 ▶ return(1) if( CORE::length( $self->{ "_table_reset_${type}" } ) );
Branch: 1 branch
BranchTrueFalseTotal
if length $$self{"_table_reset_$type"} 22 16 38
455 }
456 }
457 }
458 else
459 {
460 0 for( @{$self->{_reset_fields}} )
461 {
462 0 ▶ return(1) if( CORE::exists( $self->{ $_ } ) && CORE::length( $self->{ $_ } ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{$_} and length $self->{$_} 0 0 0
Condition0%0/3
exists $self->{$_} and length $self->{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->{$_} and length $self->{$_}
exists $self->{$_} length $self->{$_}
Truth table0%0/3
A and B
A= exists $self->{$_}B= length $self->{$_}
ABresult
0X0
100
111
463 }
464 }
465 4 return(0);
466 }
467  
468 sub _remove_table_reset
469 {
470 27 ▶ my $self = shift( @_ );
Subroutine _remove_table_reset: called CC=2 SCAR=6.9
471 27 my @types = @_;
472 27 for( @types )
473 {
474 27 CORE::delete( $self->{ "_table_reset_${_}" } );
475 }
476 27 return( $self );
477 }
478  
479 sub _reset_table
480 {
481 115 ▶ my $self = shift( @_ );
Subroutine _reset_table: called CC=5 SCAR=16.1
482 115 my $type = shift( @_ );
483 115 ▶ if( $type eq 'all' )
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'all') { } 12 103 115
484 {
485 12 for( @{$self->{_reset_fields}} )
486 {
487 60 $self->{ $_ } = 1;
488 }
489 }
490 else
491 {
492 103 $self->{ "_table_reset_${type}" } = 1;
493 }
494 115 ▶ $self->rows if( $type eq 'rows' || $type eq 'all' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "rows" or $type eq "all" 14 101 115
Condition100%3/3
$type eq "rows" or $type eq "all"
l!l&&r!l&&!r
212101
MC/DC100%2/2
$type eq "rows" or $type eq "all"
$type eq "rows" $type eq "all"
Truth table100%3/3
A or B
A= $type eq "rows"B= $type eq "all"
ABresult
1X1
011
000
495 115 $self->reset(1);
496 115 return( $self );
497 }
498  
499 sub _set_get_section : lvalue
500 {
501 6 ▶ my $self = shift( @_ );
Subroutine _set_get_section: called CC=1 SCAR=0.7
502 6 my $tag = shift( @_ );
503 6 my $class = shift( @_ );
504  
505 return( $self->_set_get_callback({
506 get => sub
507 {
508 5 ▶ my $self = shift( @_ );
Subroutine __ANON__: called CC=1 SCAR=0.0
509 5 my $list = $self->_get_tsection_collection( $tag );
510 5 return( $list->first );
511 },
512 set => sub
513 {
514 1 ▶ my $self = shift( @_ );
Subroutine __ANON__: called CC=16 SCAR=36.9
515 1 my $new = shift( @_ );
516 1 ▶ if( !$self->_is_a( $new => $class ) || $new->tag ne $tag )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_is_a($new, $class) or $new->tag ne $tag) 0 1 1
Condition33%1/3
not $self->_is_a($new, $class) or $new->tag ne $tag
l!l&&r!l&&!r
001
MC/DC0%0/2
not $self->_is_a($new, $class) or $new->tag ne $tag
not $self->_is_a($new, $class) $new->tag ne $tag
Truth table33%1/3
not(A) or B
A= not $self->_is_a($new, $class)B= $new->tag ne $tag
ABresult
1X1
011
000
517 {
518 0 return( $self->error({ message => "New ${tag} object provided is not an ${class} object", class => 'HTML::Object::HierarchyRequestError' }) );
519 }
520 1 $new->detach;
521 1 my( $old, $pos );
522 1 my $children = $self->children;
523 1 my $len = $children->length;
524 1 ▶ for( my $i = 0; $i < $len; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $len) 9 1 10
525 {
526 9 my $e = $children->[$i];
527 9 my $e_tag = $e->tag;
528 9 ▶ if( $e_tag eq $tag )
Branch: 2 branches
BranchTrueFalseTotal
if ($e_tag eq $tag) { } 0 9 9
elsif (not defined $pos and $tag eq 'thead' && $e_tag ne 'caption' && $e_tag ne 'colgroup' || $tag eq 'tfoot' && $e_tag ne 'caption' && $e_tag ne 'colgroup' && $e_tag ne 'thead') { } 0 18 18
529 {
530 0 $old = $e;
531 0 $pos = $i;
532 0 last;
533 }
534 # Find out the default position we would insert the new element if there is no previous ($old) element
535 ▶ elsif( !defined( $pos ) &&
Condition33%7/21
not defined $pos and $tag eq "thead" && $e_tag ne "caption" && $e_tag ne "colgroup" || $tag eq "tfoot" && $e_tag ne "caption" && $e_tag ne "colgroup" && $e_tag ne "thead"
!ll&&!rl&&r
090
$tag eq "thead" and $e_tag ne "caption" and $e_tag ne "colgroup" or $tag eq "tfoot" and $e_tag ne "caption" and $e_tag ne "colgroup" and $e_tag ne "thead"
l!l&&r!l&&!r
009
$tag eq "thead" and $e_tag ne "caption" and $e_tag ne "colgroup"
!ll&&!rl&&r
900
$tag eq "thead" and $e_tag ne "caption"
!ll&&!rl&&r
900
$tag eq "tfoot" and $e_tag ne "caption" and $e_tag ne "colgroup" and $e_tag ne "thead"
!ll&&!rl&&r
900
$tag eq "tfoot" and $e_tag ne "caption" and $e_tag ne "colgroup"
!ll&&!rl&&r
900
$tag eq "tfoot" and $e_tag ne "caption"
!ll&&!rl&&r
900
MC/DC0%0/8
not defined $pos and $tag eq "thead" && $e_tag ne "caption" && $e_tag ne "colgroup" || $tag eq "tfoot" && $e_tag ne "caption" && $e_tag ne "colgroup" && $e_tag ne "thead"
not defined $pos $tag eq "thead" $e_tag ne "caption" $e_tag ne "colgroup" $tag eq "tfoot" $e_tag ne "caption" $e_tag ne "colgroup" $e_tag ne "thead"
Truth table5%1/17
not(A) and B and C and D or E and F and G and H
A= not defined $posB= $tag eq "thead"C= $e_tag ne "caption"D= $e_tag ne "colgroup"E= $tag eq "tfoot"F= $e_tag ne "caption"G= $e_tag ne "colgroup"H= $e_tag ne "thead"
ABCDEFGHresult
0XXXXXXX0
10XX0XXX0
10XX10XX0
10XX110X0
10XX11100
110X0XXX0
110X10XX0
110X110X0
110X11100
11100XXX0
111010XX0
1110110X0
111011100
1111XXXX1
10XX11111
110X11111
111011111
536 (
537 ( $tag eq 'thead' && $e_tag ne 'caption' && $e_tag ne 'colgroup' ) ||
538 ( $tag eq 'tfoot' && $e_tag ne 'caption' && $e_tag ne 'colgroup' && $e_tag ne 'thead' )
539 ) )
540 {
541 0 $pos = $i;
542 }
543 }
544  
545 1 ▶ if( !defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $pos) 1 0 1
546 {
547 1 ▶ if( $tag eq 'caption' )
Branch: 1 branch
BranchTrueFalseTotal
if ($tag eq 'caption') { } 1 0 1
548 {
549 1 $pos = 0;
550 }
551 # For thead, or tfoot, put them as the last element
552 else
553 {
554 0 $pos = $len;
555 }
556 }
557  
558 1 $self->reset(1);
559 1 $self->_reset_table( $tag );
560 1 $new->parent( $self );
561 1 ▶ if( defined( $old ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $old) { } 0 1 1
562 {
563 0 $children->splice( $pos, 1, $new );
564 0 return( $old );
565 }
566 else
567 {
568 1 $children->splice( $pos, 0, $new );
569 1 return;
570 }
571 },
572 6 }, @_ ) );
573 }
574  
575 2 1;
576 # NOTE: POD
577 __END__
« lib/HTML/Object/XPath/Step.pm ↑ Summary lib/HTML/Object/EventTarget.pm »