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

filter: Statementstmt 69.7% 83 / 119 Branchbran 38.0% 19 / 50 Conditioncond 36.6% 11 / 30 MC/DCmcdc 22.2% 4 / 18 Subroutinesub 70.3% 19 / 27 Podpod 100% 14 / 14 totaltotal 58.1% 150 / 258 CC 38 SCAR 34.0
CC
38
Cov
57%
deleteCell
90.0
insertCell
70.4
cells
6.0
CRAP 29.8
« lib/HTML/Object/DOM/Element/TableSection.pm ↑ Summary blib/lib/HTML/Object/DOM/CharacterData.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/TableRow.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/01/07
7 ## Modified 2022/09/18
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::TableRow;
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( :tablerow );
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 our $VERSION = 'v0.2.0';
24 };
25  
26 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 sub init
30 {
31 6 ▶ my $self = shift( @_ );
Subroutine init: called CC=4 SCAR=13.9
Pod documented
32 6 $self->{_init_strict_use_sub} = 1;
33 6 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 6 6
34 6 ▶ $self->{tag} = 'tr' if( !defined( $self->{tag} ) || !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"tag"} and length qq[$self->{"tag"}] 1 5 6
Condition66%2/3
defined $self->{"tag"} and length qq[$self->{"tag"}]
!ll&&!rl&&r
015
MC/DC50%1/2
defined $self->{"tag"} and length qq[$self->{"tag"}]
defined $self->{"tag"} length qq[$self->{"tag"}]
Truth table66%2/3
A and B
A= defined $self->{"tag"}B= length qq[$self->{"tag"}]
ABresult
0X0
100
111
35 6 $self->{_row_reset} = 1;
36 my $callback = sub
37 {
38 12 ▶ my $def = shift( @_ );
Subroutine __ANON__: called CC=3 SCAR=11.0
39 # Our children were modified from outside our package.
40 # We need to check if it affects our rows and reset the cache accordingly
41 12 ▶ unless( $def->{caller}->[0] eq ref( $self ) ||
Branch: 1 branch
BranchTrueFalseTotal
unless ($def->{"caller"}[0] eq ref $self or $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Table") 11 1 12
Condition66%2/3
$def->{"caller"}[0] eq ref $self or $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Table"
l!l&&r!l&&!r
1011
MC/DC50%1/2
$def->{"caller"}[0] eq ref $self or $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Table"
$def->{"caller"}[0] eq ref $self $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Table"
Truth table66%2/3
A or B
A= $def->{"caller"}[0] eq ref $selfB= $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Table"
ABresult
1X1
011
000
42 $def->{caller}->[0] eq 'HTML::Object::DOM::Element::Table' )
43 {
44 11 $self->reset(1);
45 }
46 12 return(1);
47 6 };
48 6 $self->children->callback( add => $callback );
49 6 $self->children->callback( remove => $callback );
50 6 return( $self );
51 }
52  
53 # Note: deprecated property align is inherited
54  
55 # Note: deprecated property bgColor
56 0 ▶sub bgColor : lvalue { return( shift->_set_get_property( 'bgcolor', @_ ) ); }
Subroutine bgColor: not called CC=1 SCAR=6.9
Pod documented
57  
58 0 ▶sub bgcolor : lvalue { return( shift->bgColor( @_ ) ); }
Subroutine bgcolor: not called CC=1 SCAR=6.9
Pod documented
59  
60 # Note: property cells read-only
61 sub cells
62 {
63 68 ▶ my $self = shift( @_ );
Subroutine cells: called CC=6 SCAR=18.0
Pod documented
64 68 ▶ return( $self->{_row_cells} ) if( $self->{_row_cells} && !$self->_is_row_reset );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_row_cells"} and not $self->_is_row_reset 3 65 68
Condition100%3/3
$self->{"_row_cells"} and not $self->_is_row_reset
!ll&&!rl&&r
6593
MC/DC100%2/2
$self->{"_row_cells"} and not $self->_is_row_reset
$self->{"_row_cells"} not $self->_is_row_reset
Truth table100%3/3
A and not(B)
A= $self->{"_row_cells"}B= not $self->_is_row_reset
ABresult
0X0
100
111
65 65 ▶ my $list = $self->children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Element::TableCell' ) });
Subroutine __ANON__: called CC=1 SCAR=0.0
66 # The content of the collection is refreshed, but the collection object itself does not change, so the user can poll it
67 65 ▶ unless( $self->{_row_cells} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_row_cells"}) 6 59 65
68 {
69 6 ▶ $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 6 6
70 6 ▶ $self->{_row_cells} = HTML::Object::DOM::Collection->new ||
Condition50%1/2
'HTML::Object::DOM::Collection'->new || (return $self->pass_error('HTML::Object::DOM::Collection'->error))
l!l
60
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
71 return( $self->pass_error( HTML::Object::DOM::Collection->error ) );
72 }
73 65 $self->{_row_cells}->set( $list );
74 65 $self->_remove_row_reset;
75 65 return( $self->{_row_cells} );
76 }
77  
78 # Note: deprecated property ch
79 0 ▶sub ch : lvalue { return( shift->_set_get_property( 'ch', @_ ) ); }
Subroutine ch: not called CC=1 SCAR=6.9
Pod documented
80  
81 # Note: deprecated property chOff
82 0 ▶sub chOff : lvalue { return( shift->_set_get_property( 'choff', @_ ) ); }
Subroutine chOff: not called CC=1 SCAR=6.9
Pod documented
83  
84 0 ▶sub choff : lvalue { return( shift->chOff( @_ ) ); }
Subroutine choff: not called CC=1 SCAR=6.9
Pod documented
85  
86 sub deleteCell
87 {
88 0 ▶ my $self = shift( @_ );
Subroutine deleteCell: not called CC=9 SCAR=45.0
Pod documented
89 0 my $pos = shift( @_ );
90 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $pos and $self->_is_integer($pos) 0 0 0
Condition0%0/5
defined $pos and $self->_is_integer($pos)
!ll&&!rl&&r
000
$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 table0%0/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
91 message => "Value provided (" . overload::StrVal( $pos // '' ) . ") is not an integer.",
92 class => 'HTML::Object::IndexSizeError',
93 }) ) if( !defined( $pos ) || !$self->_is_integer( $pos ) );
94 0 my $cells = $self->cells;
95 0 my $size = $cells->cells;
96 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if $pos > $size 0 0 0
97 message => "Value provided ($pos) is greater than the zero-based number of cells available (${size}).",
98 class => 'HTML::Object::IndexSizeError',
99 }) ) if( $pos > $size );
100 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
101 message => "Value provided ($pos) is lower than the zero-based number of cells available (${size}). If you want to specify a negative index, it must be between -1 and -${size}",
102 class => 'HTML::Object::IndexSizeError',
103 }) ) if( $pos < 0 && abs( $pos ) > $size );
104 0 ▶ $pos = ( $cells->length + $pos ) if( $pos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 0 0
105 0 my $elem = $cells->index( $pos );
106 0 my $children = $self->children;
107 0 my $kid_pos = $children->pos( $elem );
108 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kid_pos 0 0 0
109 message => "Unable to find the cell element among this row children!",
110 class => 'HTML::Object::HierarchyRequestError',
111 }) ) if( !defined( $kid_pos ) );
112 0 $children->splice( $kid_pos, 1 );
113 0 $elem->parent( undef );
114 0 $self->reset(1);
115 0 return( $elem );
116 }
117  
118 sub insertCell
119 {
120 1 ▶ my $self = shift( @_ );
Subroutine insertCell: called CC=14 SCAR=42.5
Pod documented
121 1 my $pos = shift( @_ );
122 1 my $cells = $self->cells;
123 1 my $size = $cells->size;
124 1 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 0 1 1
125 {
126 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
127 message => "Value provided (" . overload::StrVal( $pos // '' ) . ") is not an integer.",
128 class => 'HTML::Object::IndexSizeError',
129 }) ) if( !$self->_is_integer( $pos ) );
130 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if $pos > $size 0 0 0
131 message => "Value provided ($pos) is greater than the zero-based number of cells available (${size}).",
132 class => 'HTML::Object::IndexSizeError',
133 }) ) if( $pos > $size );
134 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
135 message => "Value provided ($pos) is lower than the zero-based number of cells available (${size}). If you want to specify a negative index, it must be between -1 and -${size}",
136 class => 'HTML::Object::IndexSizeError',
137 }) ) if( $pos < 0 && abs( $pos ) > $size );
138 0 ▶ $pos = ( $cells->length + $pos ) if( $pos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 0 0
139 }
140 1 ▶ $self->_load_class( 'HTML::Object::DOM::Element::TableCell' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("HTML::Object::DOM::Element::TableCell") or return $self->pass_error 0 1 1
141 1 my $children = $self->children;
142 1 ▶ my $cell = HTML::Object::DOM::Element::TableCell->new( @_ ) ||
Condition50%1/2
'HTML::Object::DOM::Element::TableCell'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableCell'->error))
l!l
10
MC/DC0%0/1
'HTML::Object::DOM::Element::TableCell'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableCell'->error))
'HTML::Object::DOM::Element::TableCell'->new(@_)
Truth table50%1/2
A
A= 'HTML::Object::DOM::Element::TableCell'->new(@_)
Aresult
11
00
143 return( $self->pass_error( HTML::Object::DOM::Element::TableCell->error ) );
144 1 $cell->close;
145 # A position was provided
146 1 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) { } 0 1 1
147 {
148 # ..., but there are no cells yet
149 0 ▶ if( $cells->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($cells->is_empty) { } 0 0 0
150 {
151 0 $children->push( $cell );
152 }
153 else
154 {
155 0 my $elem = $cells->index( $pos );
156 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $elem 0 0 0
157 message => "No element could be found at row index $pos",
158 class => 'HTML::Object::HierarchyRequestError',
159 }) ) if( !defined( $elem ) );
160 0 my $kid_pos = $children->pos( $elem );
161 0 ▶ if( !defined( $kid_pos ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $kid_pos) 0 0 0
162 {
163 0 return( $self->error({
164 message => "Could not find a value at offset $pos (translated to $kid_pos among the row children) amazingly enough.",
165 class => 'HTML::Object::HierarchyRequestError',
166 }) );
167 }
168 0 $children->splice( $kid_pos, 0, $cell );
169 }
170 }
171 # otherwise, there are already other cells directly under <tr> and the new cell is just added at the end of the row.
172 else
173 {
174 1 $children->push( $cell );
175 }
176 1 $cell->parent( $self );
177 1 $self->reset(1);
178 1 return( $cell );
179 }
180  
181 sub reset
182 {
183 236 ▶ my $self = shift( @_ );
Subroutine reset: called CC=2 SCAR=6.9
Pod documented
184 236 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 65 171 236
185 {
186 65 $self->_reset_row;
187 65 return( $self->SUPER::reset( @_ ) );
188 }
189 171 return( $self );
190 }
191  
192 # Note: property rowIndex read-only
193 sub rowIndex
194 {
195 1 ▶ my $self = shift( @_ );
Subroutine rowIndex: called CC=2 SCAR=7.0
Pod documented
196 1 ▶ my $parent = $self->parent || return;
Condition50%1/2
$self->parent || (return)
l!l
10
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table50%1/2
A
A= $self->parent
Aresult
11
00
197 1 my $siblings = $parent->children;
198 1 my $pos = $siblings->pos( $self );
199 1 return( $pos );
200 }
201  
202 # Note: property sectionRowIndex read-only
203 sub sectionRowIndex
204 {
205 1 ▶ my $self = shift( @_ );
Subroutine sectionRowIndex: called CC=3 SCAR=12.0
Pod documented
206 1 ▶ my $parent = $self->parent || return;
Condition50%1/2
$self->parent || (return)
l!l
10
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table50%1/2
A
A= $self->parent
Aresult
11
00
207 1 ▶ if( $self->_is_a( $parent => 'HTML::Object::DOM::Element::TableSection' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($parent, "HTML::Object::DOM::Element::TableSection")) 1 0 1
208 {
209 1 return( $parent->children->pos( $self ) );
210 }
211 0 return;
212 }
213  
214 # Note: deprecated property vAlign
215 0 ▶sub vAlign : lvalue { return( shift->_set_get_property( 'valign', @_ ) ); }
Subroutine vAlign: not called CC=1 SCAR=6.9
Pod documented
216  
217 0 ▶sub valign : lvalue { return( shift->vAlign( @_ ) ); }
Subroutine valign: not called CC=1 SCAR=6.9
Pod documented
218  
219 62 ▶sub _is_row_reset { return( CORE::length( shift->{_row_reset} ) ); }
Subroutine _is_row_reset: called CC=1 SCAR=0.0
220  
221 65 ▶sub _remove_row_reset { return( CORE::delete( shift->{_row_reset} ) ); }
Subroutine _remove_row_reset: called CC=1 SCAR=0.0
222  
223 sub _reset_row
224 {
225 65 ▶ my $self = shift( @_ );
Subroutine _reset_row: called CC=3 SCAR=11.0
226 65 $self->{_row_reset}++;
227 # Force it to recompute
228 65 $self->cells;
229 65 ▶ if( my $parent = $self->parent )
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->parent) 53 12 65
230 {
231 53 ▶ $parent->_reset_section if( $parent->can( '_reset_section' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $parent->can("_reset_section") 53 0 53
232 }
233 65 return( $self );
234 }
235  
236 2 1;
237 # NOTE: POD
238 __END__
« lib/HTML/Object/DOM/Element/TableSection.pm ↑ Summary blib/lib/HTML/Object/DOM/CharacterData.pm »