| 1 | ##---------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ## HTML Object - ~/lib/HTML/Object/DOM/CharacterData.pm | ||||||||||||||||||||||||||||||||||||||||||||||
| 3 | ## Version v0.2.0 | ||||||||||||||||||||||||||||||||||||||||||||||
| 4 | ## Copyright(c) 2021 DEGUEST Pte. Ltd. | ||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ## Author: Jacques Deguest <jack@deguest.jp> | ||||||||||||||||||||||||||||||||||||||||||||||
| 6 | ## Created 2021/12/20 | ||||||||||||||||||||||||||||||||||||||||||||||
| 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::CharacterData; | ||||||||||||||||||||||||||||||||||||||||||||||
| 15 | BEGIN | ||||||||||||||||||||||||||||||||||||||||||||||
| 16 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 36 | ▶ | warnings::register_categories( 'HTML::Object' ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 36 | ▶ | use parent qw( HTML::Object::DOM::Node ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 36 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 36 | our $VERSION = 'v0.2.0'; | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 36 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 36 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # There is no constructor, because this is just an abstract interface to be inherited from by HTML::Object::DOM::Text, HTML::Object::DOM::Comment or HTML::Object::DOM::Space | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | sub after | ||||||||||||||||||||||||||||||||||||||||||||||
| 31 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
after: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | my $parent = $self->parent || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent || (return)
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | my $pos = $parent->children->pos( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | message => "This CharacterData object cannot be found in its parent node.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 37 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | }) ) if( !defined( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | my $list = $self->_get_from_list_of_elements_or_html( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | $self->_sanity_check_for_before_after( $list ) || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 41 | return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $parent->children->splice( $pos + 1, 0, $list->list ); | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | $list->foreach(sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 45 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $_->parent( $parent ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $parent->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub appendData { return( shift->value->append( @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
appendData: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | sub before | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
before: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $parent = $self->parent || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent || (return)
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $pos = $parent->children->pos( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | message => "This CharacterData object cannot be found in its parent node.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 62 | }) ) if( !defined( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | my $list = $self->_get_from_list_of_elements_or_html( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $self->_sanity_check_for_before_after( $list ) || | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | return( $self->pass_error ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | $list->foreach(sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $parent->children->splice( $pos, 0, $_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | $_->parent( $parent ); | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | $pos++; | |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $parent->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | # Note: property | ||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub data : lvalue { return( shift->_set_get_lvalue( 'value', @_ ) ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
data: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||||
| 80 | sub deleteData | ||||||||||||||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deleteData: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | my $offset = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $len = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $offset = "$offset" if( ref( $offset ) && overload::Method( $offset, '""' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $offset and overload::Method($offset, "\"\"")
MC/DC0%0/2
ref $offset and overload::Method($offset, "\"\"")
ref $offset
overload::Method($offset, "\"\"")
Truth table0%0/3
A and B
A= ref $offsetB= overload::Method($offset, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | $len = "$len" if( ref( $len ) && overload::Method( $len, '""' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $len and overload::Method($len, "\"\"")
MC/DC0%0/2
ref $len and overload::Method($len, "\"\"")
ref $len
overload::Method($len, "\"\"")
Truth table0%0/3
A and B
A= ref $lenB= overload::Method($len, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | message => "Offset value provided \"$offset\" is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 89 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | }) ) if( !$self->_is_integer( $offset ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | message => "Length value provided \"$len\" is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 93 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 94 | }) ) if( !$self->_is_integer( $len ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | $offset = int( $offset ); | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | $len = int( $len ); | |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | message => "Offset value is greater than the size of the CharacterData object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | }) ) if( $offset > $self->value->length ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $self->value->substr( $offset, $len, '' ); | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||
| 106 | sub insertData | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
insertData: not called CC=7 SCAR=40.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $offset = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my $str = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | # Nothing to do, stop here | ||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | ▶ | return( $self ) if( !defined( $str ) || !CORE::length( "$str" ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $str and CORE::length "$str"
MC/DC0%0/2
defined $str and CORE::length "$str"
defined $str
CORE::length "$str"
Truth table0%0/3
A and B
A= defined $strB= CORE::length "$str"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | $offset = "$offset" if( ref( $offset ) && overload::Method( $offset, '""' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $offset and overload::Method($offset, "\"\"")
MC/DC0%0/2
ref $offset and overload::Method($offset, "\"\"")
ref $offset
overload::Method($offset, "\"\"")
Truth table0%0/3
A and B
A= ref $offsetB= overload::Method($offset, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | $str = "$str"; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | message => "Offset value provided \"$offset\" is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | }) ) if( !$self->_is_integer( $offset ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | $offset = int( $offset ); | |||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | message => "Offset value is greater than the size of the CharacterData object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 122 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | }) ) if( $offset > $self->value->length ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->value->substr( $offset, 0, $str ); | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # Note: property | ||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub length { return( shift->value->length ); } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
length: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | # Note: property | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | sub nextElementSibling | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
nextElementSibling: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my $parent = $self->parent || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent || (return)
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | my $pos = $parent->children->pos( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 139 | message => "This CharacterData object cannot be found in its parent node.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 140 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | }) ) if( !defined( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | return( $parent->children->index( $pos + 1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | # Note: property | ||||||||||||||||||||||||||||||||||||||||||||||
| 146 | sub previousElementSibling | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
previousElementSibling: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | ▶ | my $parent = $self->parent || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent || (return)
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $pos = $parent->children->pos( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | message => "This CharacterData object cannot be found in its parent node.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 153 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | }) ) if( !defined( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | return if( $pos <= 0 ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | return( $parent->children->index( $pos - 1 ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub remove | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
remove: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | ▶ | my $parent = $self->parent || return; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent || (return)
MC/DC0%0/1
$self->parent || (return)
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $pos = $parent->children->pos( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | message => "This CharacterData object cannot be found in its parent node.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 166 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | }) ) if( !defined( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $parent->children->splice( $pos, 1 ); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | $parent->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||
| 173 | sub replaceData | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replaceData: not called CC=9 SCAR=45.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my $offset = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | my $len = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | my $str = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | # It is ok to be provided an undefined value, but we convert it to an empty string | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # to prevent perl from triggering warnings. | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | $str //= ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$str //= ""
MC/DC0%0/1
$str //= ""
$str
Truth table0%0/2
A
A= $str
| |||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | ▶ | $offset = "$offset" if( ref( $offset ) && overload::Method( $offset, '""' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $offset and overload::Method($offset, "\"\"")
MC/DC0%0/2
ref $offset and overload::Method($offset, "\"\"")
ref $offset
overload::Method($offset, "\"\"")
Truth table0%0/3
A and B
A= ref $offsetB= overload::Method($offset, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | $len = "$len" if( ref( $len ) && overload::Method( $len, '""' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $len and overload::Method($len, "\"\"")
MC/DC0%0/2
ref $len and overload::Method($len, "\"\"")
ref $len
overload::Method($len, "\"\"")
Truth table0%0/3
A and B
A= ref $lenB= overload::Method($len, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | message => "Offset value provided \"$offset\" is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 186 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 187 | }) ) if( !$self->_is_integer( $offset ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 189 | message => "Length value provided \"$len\" is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 190 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 191 | }) ) if( !$self->_is_integer( $len ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | $offset = int( $offset ); | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $len = int( $len ); | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $str = "$str"; | |||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 196 | message => "Offset value is greater than the size of the CharacterData object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 197 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | }) ) if( $offset > $self->value->length ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $self->value->substr( $offset, $len, $str ); | |||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $self->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sub replaceWith | ||||||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
replaceWith: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my $parent = $self->parent || return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$self->parent || (return $self->error({'message', 'This CharacterData has no parent.', 'class', 'HTML::Object::HierarchyRequestError'}))
MC/DC0%0/1
$self->parent || (return $self->error({'message', 'This CharacterData has no parent.', 'class', 'HTML::Object::HierarchyRequestError'}))
$self->parent
Truth table0%0/2
A
A= $self->parent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | message => "This CharacterData has no parent.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 209 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 210 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | my $pos = $parent->children->pos( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | 0 | my $list = _get_from_list_of_elements_or_html( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | message => "This CharacterData object cannot be found in its parent node.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 215 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 216 | }) ) if( !defined( $pos ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | # There is nothing to do | ||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | return( $self ) if( $list->is_empty ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | $parent->children->splice( $pos, 1, $list->list ); | |||||||||||||||||||||||||||||||||||||||||||||
| 220 | $list->foreach(sub | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | $_->parent( $parent ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | }); | |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | $parent->reset(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return( $self ); | |||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||
| 228 | sub substringData | ||||||||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
substringData: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | my $offset = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $len = shift( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | $offset = "$offset" if( ref( $offset ) && overload::Method( $offset, '""' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $offset and overload::Method($offset, "\"\"")
MC/DC0%0/2
ref $offset and overload::Method($offset, "\"\"")
ref $offset
overload::Method($offset, "\"\"")
Truth table0%0/3
A and B
A= ref $offsetB= overload::Method($offset, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | $len = "$len" if( ref( $len ) && overload::Method( $len, '""' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $len and overload::Method($len, "\"\"")
MC/DC0%0/2
ref $len and overload::Method($len, "\"\"")
ref $len
overload::Method($len, "\"\"")
Truth table0%0/3
A and B
A= ref $lenB= overload::Method($len, "\"\"")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 236 | message => "Offset value provided \"$offset\" is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 237 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 238 | }) ) if( !$self->_is_integer( $offset ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 240 | message => "Length value provided \"$len\" is not an integer.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 241 | class => 'HTML::Object::TypeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 242 | }) ) if( !$self->_is_integer( $len ) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | $offset = int( $offset ); | |||||||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | $len = int( $len ); | |||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | return( $self->error({ | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 246 | message => "Offset value is greater than the size of the CharacterData object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 247 | class => 'HTML::Object::IndexSizeError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 248 | }) ) if( $offset > $self->value->length ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | return( $self->value->substr( $offset, $len ) ); | |||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||
| 252 | sub _sanity_check_for_before_after | ||||||||||||||||||||||||||||||||||||||||||||||
| 253 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | ▶ | my $self = shift( @_ ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_sanity_check_for_before_after: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | ▶ | my $list = shift( @_ ) || return( $self->error( "No list of nodes was provided." ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift @_ || (return $self->error('No list of nodes was provided.'))
MC/DC0%0/1
shift @_ || (return $self->error('No list of nodes was provided.'))
shift @_
Truth table0%0/2
A
A= shift @_
| |||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | return( $self->error( "I was expecting an array object, but instead got '$list'." ) ) if( !$self->_is_a( $list => 'Module::Generic::Array' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | my $parent = $self->parent; | |||||||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | my $lineage = $self->lineage; | |||||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ▶ | if( !$list->intersect( $lineage )->is_empty ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 260 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||||||
| 262 | message => "One of the nodes provided is an ancestor of this CharacterData", | ||||||||||||||||||||||||||||||||||||||||||||||
| 263 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 264 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | foreach( @$list ) | |||||||||||||||||||||||||||||||||||||||||||||
| 267 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if( !$self->_is_a( $_ => 'HTML::Object::DOM::DocumentFragment' ) && | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$self->_is_a($_, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($_, 'HTML::Object::DOM::Element') || $self->_is_a($_, 'HTML::Object::DOM::CharacterData')
$self->_is_a($_, "HTML::Object::DOM::DocumentFragment") or $self->_is_a($_, "HTML::Object::DOM::Element")
MC/DC0%0/3
$self->_is_a($_, 'HTML::Object::DOM::DocumentFragment') || $self->_is_a($_, 'HTML::Object::DOM::Element') || $self->_is_a($_, 'HTML::Object::DOM::CharacterData')
$self->_is_a($_, "HTML::Object::DOM::DocumentFragment")
$self->_is_a($_, "HTML::Object::DOM::Element")
$self->_is_a($_, 'HTML::Object::DOM::CharacterData')
Truth table0%0/4
A or B || C
A= $self->_is_a($_, "HTML::Object::DOM::DocumentFragment")B= $self->_is_a($_, "HTML::Object::DOM::Element")C= $self->_is_a($_, 'HTML::Object::DOM::CharacterData')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 269 | !$self->_is_a( $_ => 'HTML::Object::DOM::Element' ) && | ||||||||||||||||||||||||||||||||||||||||||||||
| 270 | !$self->_is_a( $_ => 'HTML::Object::DOM::CharacterData' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 271 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||||||
| 273 | message => "A node provided (" . overload::StrVal( $_ ) . ") is neither a DocumentFragment, an Element nor a CharacterData object.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 274 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 275 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 277 | elsif( $self->_is_a( $_ => 'HTML::Object::DOM::DocumentFragment' ) ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | my $kids = $_->children; | |||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $count = 0; | |||||||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | foreach my $node ( @$kids ) | |||||||||||||||||||||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | ++$count if( $node->isa( 'HTML::Object::DOM::Element' ) ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if( $count > 1 || $node->isa( 'HTML::Object::DOM::Text' ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$count > 1 or $node->isa("HTML::Object::DOM::Text")
MC/DC0%0/2
$count > 1 or $node->isa("HTML::Object::DOM::Text")
$count > 1
$node->isa("HTML::Object::DOM::Text")
Truth table0%0/3
A or B
A= $count > 1B= $node->isa("HTML::Object::DOM::Text")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 285 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||||||
| 287 | message => "More than one Element node was provided or a Text node was provided.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 288 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 289 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if( $self->isa( 'HTML::Object::DOM::Text' ) && $self->_is_a( $parent => 'HTML::Object::DOM::Document' ) ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->isa("HTML::Object::DOM::Text") and $self->_is_a($parent, "HTML::Object::DOM::Document")
MC/DC0%0/2
$self->isa("HTML::Object::DOM::Text") and $self->_is_a($parent, "HTML::Object::DOM::Document")
$self->isa("HTML::Object::DOM::Text")
$self->_is_a($parent, "HTML::Object::DOM::Document")
Truth table0%0/3
A and B
A= $self->isa("HTML::Object::DOM::Text")B= $self->_is_a($parent, "HTML::Object::DOM::Document")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 295 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | return( $self->error({ | |||||||||||||||||||||||||||||||||||||||||||||
| 297 | message => "This CharacterData object is a Text object, and our parent is a Document.", | ||||||||||||||||||||||||||||||||||||||||||||||
| 298 | class => 'HTML::Object::HierarchyRequestError', | ||||||||||||||||||||||||||||||||||||||||||||||
| 299 | }) ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 0 | return(1); | |||||||||||||||||||||||||||||||||||||||||||||
| 302 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 36 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 305 | # NOTE: POD | ||||||||||||||||||||||||||||||||||||||||||||||
| 306 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||