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 108 ▶ my $self = shift( @_ );
Subroutine _reset_table: called CC=5 SCAR=16.1
482 108 my $type = shift( @_ );
483 108 ▶ if( $type eq 'all' )
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'all') { } 12 96 108
484 {
485 12 for( @{$self->{_reset_fields}} )
486 {
487 60 $self->{ $_ } = 1;
488 }
489 }
490 else
491 {
492 96 $self->{ "_table_reset_${type}" } = 1;
493 }
494 108 ▶ $self->rows if( $type eq 'rows' || $type eq 'all' );
Branch: 1 branch
BranchTrueFalseTotal
if $type eq "rows" or $type eq "all" 14 94 108
Condition100%3/3
$type eq "rows" or $type eq "all"
l!l&&r!l&&!r
21294
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 108 $self->reset(1);
496 108 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__
578  
579 =encoding utf-8
580  
581 =head1 NAME
582  
583 HTML::Object::DOM::Element::Table - HTML Object DOM Table Class
584  
585 =head1 SYNOPSIS
586  
587 use HTML::Object::DOM::Element::Table;
588 my $table = HTML::Object::DOM::Element::Table->new ||
589 die( HTML::Object::DOM::Element::Table->error, "\n" );
590  
591 =head1 VERSION
592  
593 v0.3.0
594  
595 =head1 DESCRIPTION
596  
597 This interface provides special properties and methods (beyond the regular L<HTML::Object::DOM::Element> object interface it also has available to it by inheritance) for manipulating the layout and presentation of tables in an HTML document.
598  
599 Tables can have, in this order:
600  
601 =over 4
602  
603 =item 1. an optional L<caption|HTML::Object::DOM::Element::TableCaption> element,
604  
605 =item 2. zero or more L<colgroup|HTML::Object::DOM::Element::TableCol> elements,
606  
607 =item 3. an optional L<thead|HTML::Object::DOM::Element::TableSection> element,
608  
609 =item 4. either one of the following:
610  
611 =over 8
612  
613 =item * zero or more L<tbody|HTML::Object::DOM::Element::TableSection> elements
614  
615 =item * one or more L<tr|HTML::Object::DOM::Element::TableRow> elements
616  
617 =back
618  
619 =item 5. an optional L<tfoot|HTML::Object::DOM::Element::TableSection> element
620  
621 =back
622  
623 The above is for reference only and is not enforced by this interface.
624  
625 =head1 INHERITANCE
626  
627 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
628 | HTML::Object::Element | --> | HTML::Object::EventTarget | --> | HTML::Object::DOM::Node | --> | HTML::Object::DOM::Element | --> | HTML::Object::DOM::Element::Table |
629 +-----------------------+ +---------------------------+ +-------------------------+ +----------------------------+ +-----------------------------------+
630  
631 =head1 PROPERTIES
632  
633 Inherits properties from its parent L<HTML::Object::DOM::Element>
634  
635 =head2 caption
636  
637 Is a L<table caption element|HTML::Object::DOM::Element::TableCaption> representing the first L<caption|HTML::Object::DOM::Element::TableCaption> that is a child of the element, or C<undef> if none is found.
638  
639 When set, if the object does not represent a L<caption|HTML::Object::DOM::Element::TableCaption>, a C<HTML::Object::HierarchyRequestError> error is returned. If a correct object is given, it is inserted in the tree as the first child of this element and the first L<caption|HTML::Object::DOM::Element::TableCaption> that is a child of this element is removed from the tree, if any, and returned.
640  
641 Example:
642  
643 my $table = $doc->getElementsByTagName( 'table' )->first;
644 my $old_caption = $table->caption( $new_caption );
645 # or
646 $table->caption = $new_caption;
647  
648 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/caption>
649  
650 =head2 rows
651  
652 Read-only.
653  
654 Returns a L<HTML Collection|HTML::Object::DOM::Collection> containing all the rows of the element, that is all C<tr> that are a child of the element, or a child of one of its C<thead>, C<tbody> and C<tfoot> children. The rows members of a C<thead> appear first, in tree order, and those members of a C<tbody> last, also in tree order.
655  
656 Note that for performance improvement, the collection is cached until changes are made that would affect the results.
657  
658 Example:
659  
660 <table id="myTable">
661 <tr></tr>
662 <tbody>
663 <tr></tr>
664 </tbody>
665 </table>
666  
667 my $rows = $doc->getElementById( 'myTable' )->rows;
668 say $rows->length; # 2
669  
670 <table id="myTable2">
671 <tr>
672 <td>
673 <table>
674 <tr></tr>
675 </table>
676 </td>
677 </tr>
678 <tbody>
679 <tr></tr>
680 </tbody>
681 </table>
682  
683 my $rows = $doc->getElementById( 'myTable2' )->rows;
684 say $rows->length; # Still 2
685  
686 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/rows>
687  
688 =head2 tBodies
689  
690 Read-only.
691  
692 Returns a L<HTML Collection|HTML::Object::DOM::Collection> containing all the L<tbody|HTML::Object::DOM::Element::TableSection> of the element.
693  
694 Note that for performance improvement, the collection is cached until changes are made that would affect the results.
695  
696 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/tBodies>
697  
698 =head2 tbodies
699  
700 Alias for L</tBodies>
701  
702 =head2 tFoot
703  
704 Is a L<HTML::Object::DOM::Element::TableSection> representing the first L<tfoot|HTML::Object::DOM::Element::TableSection> that is a child of the element, or C<undef> if none is found.
705  
706 When set, if the object does not represent a L<tfoot|HTML::Object::DOM::Element::TableSection>, a C<HTML::Object::HierarchyRequestError> error is returned.
707  
708 If a correct object is given, it is inserted in the tree immediately before the first element that is neither a L<caption|HTML::Object::DOM::Element::TableCaption>, a L<colgroup|HTML::Object::DOM::Element::TableCol>, nor a L<thead|HTML::Object::DOM::Element::TableSection>, or as the last child if there is no such element, and the first L<tfoot|HTML::Object::DOM::Element::TableSection> that is a child of this element is removed from the tree, if any.
709  
710 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/tFoot>
711  
712 =head2 tHead
713  
714 Is a L<HTML::Object::DOM::Element::TableSection> representing the first L<thead|HTML::Object::DOM::Element::TableSection> that is a child of the element, or C<undef> if none is found.
715  
716 When set, if the object does not represent a L<thead|HTML::Object::DOM::Element::TableSection>, a C<HTML::Object::HierarchyRequestError> error is returned.
717  
718 If a correct object is given, it is inserted in the tree immediately before the first element that is neither a L<caption|HTML::Object::DOM::Element::TableCaption>, nor a L<colgroup|HTML::Object::DOM::Element::TableCol>, or as the last child if there is no such element, and the first L<thead|HTML::Object::DOM::Element::TableSection> that is a child of this element is removed from the tree, if any.
719  
720 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/tHead>
721  
722 =head1 METHODS
723  
724 Inherits methods from its parent L<HTML::Object::DOM::Element>
725  
726 =head2 createCaption
727  
728 Returns an L<HTML::Object::DOM::Element> representing the first L<caption|HTML::Object::DOM::Element::TableCaption> that is a child of the element. If none is found, a new one is created and inserted in the tree as the first child of the C<table> element.
729  
730 Example:
731  
732 <table>
733 <tr><td>Cell 1.1</td><td>Cell 1.2</td><td>Cell 1.3</td></tr>
734 <tr><td>Cell 2.1</td><td>Cell 2.2</td><td>Cell 2.3</td></tr>
735 </table>
736  
737 my $table = $doc->querySelector('table');
738 my $caption = $table->createCaption();
739 $caption->textContent = 'This caption was created by JavaScript!';
740  
741 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/createCaption>
742  
743 =head2 createTBody
744  
745 Returns a L<HTML::Object::DOM::Element::TableSection> representing a new L<tbody|HTML::Object::DOM::Element::TableSection> that is a child of the element. It is inserted in the tree after the last element that is a L<tbody|HTML::Object::DOM::Element::TableSection>, or as the last child if there is no such element.
746  
747 Example:
748  
749 my $mybody = $mytable->createTBody();
750 # Now this should be true: $mybody == mytable->tBodies->item( $mytable->tBodies->length - 1 )
751  
752 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/createTBody>
753  
754 =head2 createTFoot
755  
756 Returns an L<HTML::Object::DOM::Element::TableSection> representing the first L<tfoot|HTML::Object::DOM::Element::TableSection> that is a child of the element. If none is found, a new one is created and inserted in the tree as the last child.
757  
758 Example:
759  
760 my $myfoot = $mytable->createTFoot();
761 # Now this should be true: $myfoot == $mytable->tFoot
762  
763 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/createTFoot>
764  
765 =head2 createTHead
766  
767 Returns an L<HTML::Object::DOM::Element::TableSection> representing the first L<thead|HTML::Object::DOM::Element::TableSection> that is a child of the element. If none is found, a new one is created and inserted in the tree immediately before the first element that is neither a L<caption|HTML::Object::DOM::Element::TableCaption>, nor a L<colgroup|HTML::Object::DOM::Element::TableCol>, or as the last child if there is no such element.
768  
769 Example:
770  
771 my $myhead = mytable->createTHead();
772 # Now this should be true: $myhead == mytable->tHead
773  
774 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/createTHead>
775  
776 =head2 deleteCaption
777  
778 Removes the first L<caption|HTML::Object::DOM::Element::TableCaption> that is a child of the element and returns the object of the caption element.
779  
780 Example:
781  
782 <table>
783 <caption>This caption will be deleted!</caption>
784 <tr><td>Cell 1.1</td><td>Cell 1.2</td></tr>
785 <tr><td>Cell 2.1</td><td>Cell 2.2</td></tr>
786 </table>
787  
788 my $table = $doc->querySelector('table');
789 $table->deleteCaption();
790  
791 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteCaption>
792  
793 =head2 deleteRow
794  
795 Removes the row corresponding to the index given in parameter. If the index value is C<-1> the last row is removed; if it smaller than C<-1> or greater than the amount of rows in the collection, an C<HTML::Object::IndexSizeError> is returned.
796  
797 Example:
798  
799 <table>
800 <tr><td>Cell 1.1</td><td>Cell 1.2</td><td>Cell 1.3</td></tr>
801 <tr><td>Cell 2.1</td><td>Cell 2.2</td><td>Cell 2.3</td></tr>
802 <tr><td>Cell 3.1</td><td>Cell 3.2</td><td>Cell 3.3</td></tr>
803 </table>
804  
805 my $table = $doc->querySelector('table');
806 # Delete second row
807 $table->deleteRow(1);
808  
809 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteRow>
810  
811 =head2 deleteTFoot
812  
813 Removes the first L<tfoot|HTML::Object::DOM::Element::TableSection> that is a child of the element and returns the object of the caption element.
814  
815 Example:
816  
817 <table>
818 <thead><th>Name</th><th>Score</th></thead>
819 <tr><td>Bob</td><td>541</td></tr>
820 <tr><td>Jim</td><td>225</td></tr>
821 <tfoot><th>Average</th><td>383</td></tfoot>
822 </table>
823  
824 my $table = $doc->querySelector('table');
825 $table->deleteTFoot();
826  
827 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteTFoot>
828  
829 =head2 deleteTHead
830  
831 Removes the first L<thead|HTML::Object::DOM::Element::TableSection> that is a child of the element and returns the object of the caption element.
832  
833 Example:
834  
835 <table>
836 <thead><th>Name</th><th>Occupation</th></thead>
837 <tr><td>Bob</td><td>Plumber</td></tr>
838 <tr><td>Jim</td><td>Roofer</td></tr>
839 </table>
840  
841 my $table = $doc->querySelector('table');
842 $table->deleteTHead();
843  
844 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/deleteTHead>
845  
846 =head2 insertRow
847  
848 Returns an L<HTML::Object::DOM::Element::TableRow> representing a new row of the table. It inserts it in the rows collection immediately before the C<tr> element at the given index position, if any was provided. If there are no existing rows yet, a L<tbody|HTML::Object::DOM::Element::TableSection> is created and the new row inserted into it. If a table has multiple C<tbody> elements, by default, the new row is inserted into the last C<tbody>.
849  
850 If the index is not given or is C<-1>, the new row is appended to the collection. If the index is smaller than C<-1>, it will start that far back from the end of the collection array. If index is greater than the number of rows in the collection, an C<HTML::Object::IndexSizeError> error is returned.
851  
852 Example:
853  
854 <table></table>
855  
856 $doc->getElementsByTagName('table')->[0]->insertRow();
857  
858 Table is now:
859  
860 <table>
861 <tbody>
862 <tr></tr>
863 </tbody>
864 </table>
865  
866 But if there are already existing rows and no tbody, the new row will merely be added as the las child of the table.
867  
868 <table>
869 <tr></tr>
870 </table>
871  
872 $doc->getElementsByTagName('table')->[0]->insertRow();
873  
874 Table is now:
875  
876 <table>
877 <tr></tr>
878 <tr></tr>
879 </table>
880  
881 Even if there is a C<tfoot>, the new row will be added after:
882  
883 <table>
884 <tr></tr>
885 <tfoot></tfoot>
886 </table>
887  
888 $doc->getElementsByTagName('table')->[0]->insertRow();
889  
890 Table is now:
891  
892 <table>
893 <tr></tr>
894 <tfoot></tfoot>
895 <tr></tr>
896 </table>
897  
898 If an index is negative, the new row will be added that far back from the end:
899  
900 <table>
901 <tr id="one"></tr>
902 <tr id="two"></tr>
903 <tr id="three"></tr>
904 </table>
905  
906 $doc->getElementsByTagName('table')->[0]->insertRow(-2);
907  
908 Table is now:
909  
910 <table>
911 <tr id="one"></tr>
912 <tr></tr>
913 <tr id="two"></tr>
914 <tr id="three"></tr>
915 </table>
916  
917 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/insertRow>
918  
919 =head2 DEPRECATED PROPERTIES
920  
921 =head2 align
922  
923 Is a string containing an enumerated value reflecting the align attribute. It indicates the alignment of the element's contents with respect to the surrounding context. The possible values are "left", "right", and "center".
924  
925 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/align>
926  
927 =head2 bgColor
928  
929 A string containing the background color of the table. It reflects the obsolete bgcolor attribute.
930  
931 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/bgColor>
932  
933 =head2 border
934  
935 Is a string containing the width in pixels of the border of the table. It reflects the obsolete border attribute.
936  
937 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/border>
938  
939 =head2 cellPadding
940  
941 Is a string containing the width in pixels of the horizontal and vertical sapce between cell content and cell borders. It reflects the obsolete cellpadding attribute.
942  
943 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/cellPadding>
944  
945 =head2 cellSpacing
946  
947 Is a string containing the width in pixels of the horizontal and vertical separation between cells. It reflects the obsolete cellspacing attribute.
948  
949 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/cellSpacing>
950  
951 =head2 frame
952  
953 Is a string containing the type of the external borders of the table. It reflects the obsolete frame attribute and can take one of the following values: C<void>, C<above>, C<below>, C<hsides>, C<vsides>, C<lhs>, C<rhs>, C<box>, or C<border>.
954  
955 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/frame>
956  
957 =head2 rules
958  
959 Is a string containing the type of the internal borders of the table. It reflects the obsolete rules attribute and can take one of the following values: C<none>, C<groups>, C<rows>, C<cols>, or C<all>.
960  
961 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/rules>
962  
963 =head2 summary
964  
965 Is a string containing a description of the purpose or the structure of the table. It reflects the obsolete summary attribute.
966  
967 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/summary>
968  
969 =head2 width
970  
971 Is a string containing the length in pixels or in percentage of the desired width fo the entire table. It reflects the obsolete width attribute.
972  
973 See also L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement/width>
974  
975 =head1 AUTHOR
976  
977 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
978  
979 =head1 SEE ALSO
980  
981 L<Mozilla documentation|https://developer.mozilla.org/en-US/docs/Web/API/HTMLTableElement>, L<Mozilla documentation on table element|https://developer.mozilla.org/en-US/docs/Web/HTML/Element/table>
982  
983 =head1 COPYRIGHT & LICENSE
984  
985 Copyright(c) 2021 DEGUEST Pte. Ltd.
986  
987 All rights reserved
988  
989 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
990  
991 =cut
« lib/HTML/Object/XPath/Step.pm ↑ Summary lib/HTML/Object/EventTarget.pm »