lib/HTML/Object/DOM/XPathResult.pm

filter: Statementstmt 40.2% 29 / 72 Branchbran 0.0% 0 / 20 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 45.0% 9 / 20 Podpod 100% 11 / 11 totaltotal 39.8% 49 / 123 CC 11 SCAR 16.7
CC
11
Cov
32%
iterateNext
12.0
snapshotLength
12.0
init
6.0
CRAP 5.3
« lib/HTML/Object/DOM/Element/Object.pm ↑ Summary lib/HTML/Object/DOM/Text.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/DOM/XPathResult.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2022 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2022/01/01
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::XPathResult;
15 BEGIN
16 {
17 1 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶ use vars qw( @EXPORT %EXPORT_TAGS $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶ use HTML::Object::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 use constant {
24 # A result set containing whatever type naturally results from evaluation of the expression. Note that if the result is a node-set then UNORDERED_NODE_ITERATOR_TYPE is always the resulting type.
25 1 ANY_TYPE => 0,
26 # A result containing a single number. This is useful for example, in an XPath expression using the count() function.
27 NUMBER_TYPE => 1,
28 # A result containing a single string.
29 STRING_TYPE => 2,
30 # A result containing a single boolean value. This is useful for example, in an XPath expression using the not() function.
31 BOOLEAN_TYPE => 3,
32 # A result node-set containing all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document.
33 UNORDERED_NODE_ITERATOR_TYPE => 4,
34 # A result node-set containing all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document.
35 ORDERED_NODE_ITERATOR_TYPE => 5,
36 # A result node-set containing snapshots of all the nodes matching the expression. The nodes may not necessarily be in the same order that they appear in the document.
37 UNORDERED_NODE_SNAPSHOT_TYPE => 6,
38 # A result node-set containing snapshots of all the nodes matching the expression. The nodes in the result set are in the same order that they appear in the document.
39 ORDERED_NODE_SNAPSHOT_TYPE => 7,
40 # A result node-set containing any single node that matches the expression. The node is not necessarily the first node in the document that matches the expression.
41 ANY_UNORDERED_NODE_TYPE => 8,
42 # A result node-set containing the first node in the document that matches the expression.
43 FIRST_ORDERED_NODE_TYPE => 9,
44 1 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
45 1 our @EXPORT = qw(
46 ANY_TYPE NUMBER_TYPE STRING_TYPE BOOLEAN_TYPE
47 UNORDERED_NODE_ITERATOR_TYPE ORDERED_NODE_ITERATOR_TYPE
48 UNORDERED_NODE_SNAPSHOT_TYPE ORDERED_NODE_SNAPSHOT_TYPE
49 ANY_UNORDERED_NODE_TYPE FIRST_ORDERED_NODE_TYPE
50 );
51 1 our %EXPORT_TAGS = (
52 all => [qw(
53 ANY_TYPE NUMBER_TYPE STRING_TYPE BOOLEAN_TYPE
54 UNORDERED_NODE_ITERATOR_TYPE ORDERED_NODE_ITERATOR_TYPE
55 UNORDERED_NODE_SNAPSHOT_TYPE ORDERED_NODE_SNAPSHOT_TYPE
56 ANY_UNORDERED_NODE_TYPE FIRST_ORDERED_NODE_TYPE
57 )]
58 );
59 1 our $VERSION = 'v0.2.0';
60 };
61  
62 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
63 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
64  
65 sub init
66 {
67 0 ▶ my $self = shift( @_ );
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
68 0 $self->{result} = undef;
69 # Any type, by default
70 0 $self->{resulttype} = 0;
71 0 $self->{_init_strict_use_sub} = 1;
72 0 ▶ $self->SUPER::init( @_ ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::init(@_) or return $self->pass_error 0 0 0
73 0 $self->{_pos} = 0;
74 0 return( $self );
75 }
76  
77 # Note: property booleanValue read-only
78 sub booleanValue
79 {
80 0 ▶ my $self = shift( @_ );
Subroutine booleanValue: not called CC=2 SCAR=17.9
Pod documented
81 0 my $res = $self->result;
82 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($res, "HTML::Object::XPath::Boolean") 0 0 0
83 message => 'Result is not a boolean',
84 class => 'HTML::Object::TypeError',
85 }) ) if( !$self->_is_a( $res => 'HTML::Object::XPath::Boolean' ) );
86 0 return( $res );
87 }
88  
89 # Note: property invalidIteratorState read-only
90 0 ▶sub invalidIteratorState : lvalue { return( shift->_set_get_property( 'invaliditeratorstate', @_ ) ); }
Subroutine invalidIteratorState: not called CC=1 SCAR=6.9
Pod documented
91  
92 sub iterateNext
93 {
94 0 ▶ my $self = shift( @_ );
Subroutine iterateNext: not called CC=3 SCAR=24.8
Pod documented
95 0 my $res = $self->result;
96 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($res, "HTML::Object::XPath::NodeSet") 0 0 0
97 message => 'Result is not a NodeSet',
98 class => 'HTML::Object::TypeError',
99 }) ) if( !$self->_is_a( $res => 'HTML::Object::XPath::NodeSet' ) );
100 0 ▶ return if( $self->{_pos} >= $res->size );
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_pos"} >= $res->size 0 0 0
101 0 my $node = $res->index( $self->{_pos} );
102 0 $self->{_pos}++;
103 0 return( $node );
104 }
105  
106 # Note: property numberValue read-only
107 sub numberValue
108 {
109 0 ▶ my $self = shift( @_ );
Subroutine numberValue: not called CC=2 SCAR=17.9
Pod documented
110 0 my $res = $self->result;
111 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($res, "HTML::Object::XPath::Number") 0 0 0
112 message => 'Result is not a number',
113 class => 'HTML::Object::TypeError',
114 }) ) if( !$self->_is_a( $res => 'HTML::Object::XPath::Number' ) );
115 0 return( $res );
116 }
117  
118 # Note: method to store the result, which is an object of various class, so we use _set_get
119 0 ▶sub result { return( shift->_set_get( 'result', @_ ) ); }
Subroutine result: not called CC=1 SCAR=6.9
Pod documented
120  
121 # Note: property resultType read-only
122 0 ▶sub resultType : lvalue { return( shift->_set_get_number( 'resulttype', @_ ) ); }
Subroutine resultType: not called CC=1 SCAR=6.9
Pod documented
123  
124 # Note: property singleNodeValue read-only
125 sub singleNodeValue
126 {
127 0 ▶ my $self = shift( @_ );
Subroutine singleNodeValue: not called CC=2 SCAR=17.9
Pod documented
128 0 my $res = $self->result;
129 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($res, "HTML::Object::DOM::Node") 0 0 0
130 message => 'Result is not a node (HTML::Object::DOM::Node)',
131 class => 'HTML::Object::TypeError',
132 }) ) if( !$self->_is_a( $res => 'HTML::Object::DOM::Node' ) );
133 0 return( $res );
134 }
135  
136 sub snapshotItem
137 {
138 0 ▶ my $self = shift( @_ );
Subroutine snapshotItem: not called CC=2 SCAR=17.9
Pod documented
139 0 my $res = $self->result;
140 0 ▶ if( $self->_is_a( $res => 'HTML::Object::XPath::NodeSet' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($res, 'HTML::Object::XPath::NodeSet')) { } 0 0 0
141 {
142 0 return( $res->[ $self->{_pos} ] );
143 }
144 else
145 {
146 0 return( $res );
147 }
148 }
149  
150 # Note: property snapshotLength read-only
151 sub snapshotLength
152 {
153 0 ▶ my $self = shift( @_ );
Subroutine snapshotLength: not called CC=3 SCAR=24.8
Pod documented
154 0 my $res = $self->result;
155 0 ▶ if( $self->_is_a( $res => 'HTML::Object::XPath::NodeSet' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($res, 'HTML::Object::XPath::NodeSet')) { } 0 0 0
156 {
157 0 return( $res->size );
158 }
159 else
160 {
161 0 ▶ return( ref( $res ) ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
ref $res ? : 0 0 0
162 }
163 }
164  
165 # Note: property stringValue read-only
166 sub stringValue
167 {
168 0 ▶ my $self = shift( @_ );
Subroutine stringValue: not called CC=2 SCAR=17.9
Pod documented
169 0 my $res = $self->result;
170 0 ▶ return( $self->error({
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_a($res, "HTML::Object::XPath::Literal") 0 0 0
171 message => 'Result is not a string (HTML::Object::XPath::Literal)',
172 class => 'HTML::Object::TypeError',
173 }) ) if( !$self->_is_a( $res => 'HTML::Object::XPath::Literal' ) );
174 0 return( $res );
175 }
176  
177 1 1;
178 # NOTE: POD
179 __END__
« lib/HTML/Object/DOM/Element/Object.pm ↑ Summary lib/HTML/Object/DOM/Text.pm »