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

filter: Statementstmt 71.1% 74 / 104 Branchbran 36.9% 17 / 46 Conditioncond 34.6% 9 / 26 MC/DCmcdc 25.0% 4 / 16 Subroutinesub 80.9% 17 / 21 Podpod 100% 8 / 8 totaltotal 58.3% 129 / 221 CC 34 SCAR 34.2
CC
34
Cov
57%
deleteRow
90.0
insertRow
57.3
rows
6.0
CRAP 30.5
« blib/lib/HTML/Object/DOM/Element/TableSection.pm ↑ Summary lib/HTML/Object/DOM/Element/TableRow.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/Element/TableSection.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/23
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::TableSection;
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( :tablesection );
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=14.0
Pod documented
32 # could also be tbody o tfoot
33 6 ▶ $self->{tag} = 'thead' if( !defined( $self->{tag} ) || !CORE::length( "$self->{tag}" ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"tag"} and length qq[$self->{"tag"}] 6 0 6
Condition33%1/3
defined $self->{"tag"} and length qq[$self->{"tag"}]
!ll&&!rl&&r
600
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
34 6 $self->{_init_strict_use_sub} = 1;
35 6 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 6 6
36 6 $self->{_section_reset} = 1;
37 my $callback = sub
38 {
39 15 ▶ my $def = shift( @_ );
Subroutine __ANON__: called CC=3 SCAR=11.0
40 # Our children were modified from outside our package.
41 # We need to check if it affects our rows and reset the cache accordingly
42 15 ▶ 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") 13 2 15
Condition100%3/3
$def->{"caller"}[0] eq ref $self or $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Table"
l!l&&r!l&&!r
1113
MC/DC100%2/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 table100%3/3
A or B
A= $def->{"caller"}[0] eq ref $selfB= $def->{"caller"}[0] eq "HTML::Object::DOM::Element::Table"
ABresult
1X1
011
000
43 $def->{caller}->[0] eq 'HTML::Object::DOM::Element::Table' )
44 {
45 13 $self->reset(1);
46 }
47 15 return(1);
48 6 };
49 6 $self->children->callback( add => $callback );
50 6 $self->children->callback( remove => $callback );
51 6 return( $self );
52 }
53  
54 # Note: deprecated property align is inherited
55  
56 # Note: deprecated property ch
57 0 ▶sub ch : lvalue { return( shift->_set_get_property( 'ch', @_ ) ); }
Subroutine ch: not called CC=1 SCAR=6.9
Pod documented
58  
59 # Note: deprecated property chOff
60 0 ▶sub chOff : lvalue { return( shift->_set_get_property( 'choff', @_ ) ); }
Subroutine chOff: not called CC=1 SCAR=6.9
Pod documented
61  
62 sub deleteRow
63 {
64 0 ▶ my $self = shift( @_ );
Subroutine deleteRow: not called CC=9 SCAR=45.0
Pod documented
65 0 my $pos = shift( @_ );
66 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
67 message => "Value provided (" . overload::StrVal( $pos // '' ) . ") is not an integer.",
68 class => 'HTML::Object::IndexSizeError',
69 }) ) if( !defined( $pos ) || !$self->_is_integer( $pos ) );
70 0 my $rows = $self->rows;
71 0 my $size = $rows->size;
72 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if $pos > $size 0 0 0
73 message => "Value provided ($pos) is greater than the zero-based number of rows available (" . $rows->size . ").",
74 class => 'HTML::Object::IndexSizeError',
75 }) ) if( $pos > $size );
76 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
77 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}",
78 class => 'HTML::Object::IndexSizeError',
79 }) ) if( $pos < 0 && abs( $pos ) > $size );
80 0 ▶ $pos = ( $rows->length + $pos ) if( $pos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 0 0
81 0 my $elem = $rows->index( $pos );
82 0 my $children = $self->children;
83 0 my $kid_pos = $children->pos( $elem );
84 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless defined $kid_pos 0 0 0
85 message => "Unable to find the row element among this table children!",
86 class => 'HTML::Object::HierarchyRequestError',
87 }) ) if( !defined( $kid_pos ) );
88 0 $children->splice( $kid_pos, 1 );
89 0 $elem->parent( undef );
90 0 $self->reset(1);
91 0 return( $elem );
92 }
93  
94 sub insertRow
95 {
96 1 ▶ my $self = shift( @_ );
Subroutine insertRow: called CC=13 SCAR=40.5
Pod documented
97 1 my $pos = shift( @_ );
98 1 my $rows = $self->rows;
99 1 my $size = $rows->size;
100 1 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) 0 1 1
101 {
102 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
103 message => "Value provided (" . overload::StrVal( $pos // '' ) . ") is not an integer.",
104 class => 'HTML::Object::IndexSizeError',
105 }) ) if( !$self->_is_integer( $pos ) );
106 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
if $pos > $size 0 0 0
107 message => "Value provided ($pos) is greater than the zero-based number of rows available (" . $rows->size . ").",
108 class => 'HTML::Object::IndexSizeError',
109 }) ) if( $pos > $size );
110 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
111 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}",
112 class => 'HTML::Object::IndexSizeError',
113 }) ) if( $pos < 0 && abs( $pos ) > $size );
114 0 ▶ $pos = ( $rows->length + $pos ) if( $pos < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $pos < 0 0 0 0
115 }
116 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
117 1 my $children = $self->children;
118 1 ▶ my $row = HTML::Object::DOM::Element::TableRow->new( @_ ) ||
Condition50%1/2
'HTML::Object::DOM::Element::TableRow'->new(@_) || (return $self->pass_error('HTML::Object::DOM::Element::TableRow'->error))
l!l
10
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 table50%1/2
A
A= 'HTML::Object::DOM::Element::TableRow'->new(@_)
Aresult
11
00
119 return( $self->pass_error( HTML::Object::DOM::Element::TableRow->error ) );
120 1 $row->close;
121 # A position was provided
122 1 ▶ if( defined( $pos ) )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pos) { } 0 1 1
123 {
124 # ..., but there are no rows yet
125 0 ▶ if( $rows->is_empty )
Branch: 1 branch
BranchTrueFalseTotal
if ($rows->is_empty) { } 0 0 0
126 {
127 0 $children->push( $row );
128 }
129 else
130 {
131 0 my $elem = $rows->index( $pos );
132 0 my $kid_pos = $children->pos( $elem );
133 0 ▶ if( !defined( $kid_pos ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $kid_pos) 0 0 0
134 {
135 0 return( $self->error({
136 message => "Could not find a value at offset $pos (translated to $kid_pos among the table children) amazingly enough.",
137 class => 'HTML::Object::HierarchyRequestError',
138 }) );
139 }
140 0 $children->splice( $kid_pos, 0, $row );
141 }
142 }
143 # 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.
144 else
145 {
146 1 $children->push( $row );
147 }
148 1 $row->parent( $self );
149 1 $self->reset(1);
150 1 return( $row );
151 }
152  
153 sub reset
154 {
155 350 ▶ my $self = shift( @_ );
Subroutine reset: called CC=2 SCAR=6.9
Pod documented
156 350 ▶ if( scalar( @_ ) )
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_) 65 285 350
157 {
158 65 $self->_reset_section;
159 65 return( $self->SUPER::reset( @_ ) );
160 }
161 285 return( $self );
162 }
163  
164 # Note: property rows read-only
165 sub rows
166 {
167 158 ▶ my $self = shift( @_ );
Subroutine rows: called CC=6 SCAR=18.0
Pod documented
168 158 ▶ return( $self->{_section_rows} ) if( $self->{_section_rows} && !$self->_is_section_reset );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_section_rows"} and not $self->_is_section_reset 40 118 158
Condition100%3/3
$self->{"_section_rows"} and not $self->_is_section_reset
!ll&&!rl&&r
611240
MC/DC100%2/2
$self->{"_section_rows"} and not $self->_is_section_reset
$self->{"_section_rows"} not $self->_is_section_reset
Truth table100%3/3
A and not(B)
A= $self->{"_section_rows"}B= not $self->_is_section_reset
ABresult
0X0
100
111
169 118 ▶ my $list = $self->children->grep(sub{ $self->_is_a( $_ => 'HTML::Object::DOM::Element::TableRow' ) });
Subroutine __ANON__: called CC=1 SCAR=0.0
170 118 ▶ unless( $self->{_section_rows} )
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"_section_rows"}) 6 112 118
171 {
172 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
173 6 ▶ $self->{_section_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
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
174 return( $self->pass_error( HTML::Object::DOM::Collection->error ) );
175 }
176 118 $self->{_section_rows}->set( $list );
177 118 $self->_remove_section_reset;
178 118 return( $self->{_section_rows} );
179 }
180  
181 # Note: deprecated property vAlign
182 0 ▶sub vAlign : lvalue { return( shift->_set_get_property( 'valign', @_ ) ); }
Subroutine vAlign: not called CC=1 SCAR=6.9
Pod documented
183  
184 152 ▶sub _is_section_reset { return( CORE::length( shift->{_section_reset} ) ); }
Subroutine _is_section_reset: called CC=1 SCAR=0.0
185  
186 118 ▶sub _remove_section_reset { return( CORE::delete( shift->{_section_reset} ) ); }
Subroutine _remove_section_reset: called CC=1 SCAR=0.0
187  
188 sub _reset_section
189 {
190 118 ▶ my $self = shift( @_ );
Subroutine _reset_section: called CC=3 SCAR=11.0
191 118 $self->{_section_reset}++;
192 # Force cells object update
193 118 $self->rows;
194 118 ▶ if( my $parent = $self->parent )
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->parent) 96 22 118
195 {
196 96 ▶ $parent->_reset_table( $self->{tag} ) if( $parent->can( '_reset_table' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $parent->can("_reset_table") 96 0 96
197 }
198 118 return( $self );
199 }
200  
201 2 1;
202 # NOTE: POD
203 __END__
« blib/lib/HTML/Object/DOM/Element/TableSection.pm ↑ Summary lib/HTML/Object/DOM/Element/TableRow.pm »