lib/HTML/Object/XPath/LocationPath.pm

filter: Statementstmt 70.9% 44 / 62 Branchbran 25.0% 4 / 16 Conditioncond 28.5% 2 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 12 / 16 Podpod 100% 8 / 8 totaltotal 61.9% 70 / 113 CC 14 SCAR 17.3
CC
14
Cov
59%
as_string
20.0
push
7.5
as_xml
6.0
CRAP 5.6
« blib/lib/HTML/Object/Event.pm ↑ Summary blib/lib/HTML/Object/DOM/TextTrackList.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/XPath/LocationPath.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/05
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::XPath::LocationPath;
15 BEGIN
16 {
17 12 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶ use vars qw( $BASE_CLASS $DEBUG $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 12 our $BASE_CLASS = 'HTML::Object::XPath';
23 12 our $DEBUG = 0;
24 12 our $VERSION = 'v0.2.0';
25 };
26  
27 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 sub new
31 {
32 85 ▶ my $this = shift( @_ );
Subroutine new: called CC=2 SCAR=8.1
Pod documented
33 85 ▶ return( bless( [] => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0850
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
34 }
35  
36 sub as_string
37 {
38 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=4 SCAR=30.0
Pod documented
39 0 my $string = '';
40 0 ▶ for( my $i = 0; $i < @$self; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$self) 0 0 0
41 {
42 0 ▶ $string .= ( $self->[ $i ]->as_string // '' );
Condition0%0/2
$self->[$i]->as_string // ""
l!l
00
MC/DC0%0/1
$self->[$i]->as_string // ""
$self->[$i]->as_string
Truth table0%0/2
A
A= $self->[$i]->as_string
Aresult
11
00
43 0 ▶ $string .= '/' if( $self->[ $i + 1 ] );
Branch: 1 branch
BranchTrueFalseTotal
if $$self[$i + 1] 0 0 0
44 }
45 0 return( $string );
46 }
47  
48 sub as_xml
49 {
50 0 ▶ my $self = shift( @_ );
Subroutine as_xml: not called CC=2 SCAR=17.9
Pod documented
51 0 my $string = "<LocationPath>\n";
52
53 0 ▶ for (my $i = 0; $i < @$self; $i++ )
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$self) 0 0 0
54 {
55 0 $string .= $self->[ $i ]->as_xml;
56 }
57 0 $string .= "</LocationPath>\n";
58 0 return( $string );
59 }
60  
61 sub evaluate
62 {
63 237 ▶ my $self = shift( @_ );
Subroutine evaluate: called CC=4 SCAR=14.0
Pod documented
64 # context _MUST_ be a single node
65 237 my $context = shift( @_ );
66 237 ▶ die( "No context" ) unless( $context );
Branch: 1 branch
BranchTrueFalseTotal
unless $context 0 237 237
67
68 # I _think_ this is how it should work :)
69 237 my $nodeset = $self->new_nodeset();
70 237 $nodeset->push( $context );
71
72 237 foreach my $step ( @$self )
73 {
74 # For each step
75 # evaluate the step with the nodeset
76 424 my $pos = 1;
77 # die( "Looping !\n" ) if( ref( $step ) eq ref( $self ) );
78 424 ▶ die( "Looping !\n" ) if( $step eq $self );
Branch: 1 branch
BranchTrueFalseTotal
if $step eq $self 0 424 424
79 424 $nodeset = $step->evaluate( $nodeset );
80 }
81 234 return( $nodeset );
82 }
83  
84 237 ▶sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); }
Subroutine new_nodeset: called CC=1 SCAR=0.0
Pod documented
85  
86 0 ▶sub new_root { return( shift->_class_for( 'Root' )->new( @_ ) ); }
Subroutine new_root: not called CC=1 SCAR=6.9
Pod documented
87  
88 # sub push { return( CORE::push( @{$_[0]}, @_ ) ); }
89 sub push
90 {
91 161 ▶ my $self = shift( @_ );
Subroutine push: called CC=4 SCAR=20.1
Pod documented
92 161 ▶ if( $self->debug )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->debug) 0 161 161
93 {
94 0 for( @_ )
95 {
96 0 ▶ if( ref( $_ ) eq ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_ eq ref $self) 0 0 0
97 {
98 0 die( "A LocationPath object was added to its own stack!\n" );
99 }
100 }
101 }
102 161 return( CORE::push( @$self, @_ ) );
103 }
104  
105 sub set_root
106 {
107 0 ▶ my $self = shift( @_ );
Subroutine set_root: not called CC=1 SCAR=6.9
Pod documented
108 0 return( unshift( @$self, $self->new_root ) );
109 }
110  
111 sub _class_for
112 {
113 237 ▶ my( $self, $mod ) = @_;
Subroutine _class_for: called CC=3 SCAR=11.3
114 237 eval( "require ${BASE_CLASS}\::${mod};" );
115 237 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 237 237
116 # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG;
117 237 ▶ eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) );
Condition50%1/2
$HTML::Object::XPath::LocationPath::DEBUG // 0
l!l
2370
MC/DC0%0/1
$HTML::Object::XPath::LocationPath::DEBUG // 0
$HTML::Object::XPath::LocationPath::DEBUG
Truth table50%1/2
A
A= $HTML::Object::XPath::LocationPath::DEBUG
Aresult
11
00
118 237 return( "${BASE_CLASS}::${mod}" );
119 }
120  
121 12 1;
122 # NOTE: POD
123 __END__
124  
125 =encoding utf-8
126  
127 =head1 NAME
128  
129 HTML::Object::XPath::LocationPath - HTML Object XPath Location Path
130  
131 =head1 SYNOPSIS
132  
133 use HTML::Object::XPath::LocationPath;
134 my $this = HTML::Object::XPath::LocationPath->new ||
135 die( HTML::Object::XPath::LocationPath->error, "\n" );
136  
137 =head1 VERSION
138  
139 v0.2.0
140  
141 =head1 DESCRIPTION
142  
143 This module represents a XML LocationPath.
144  
145 =head1 CONSTRUCTOR
146  
147 Takes no argument and returns a new array-based object.
148  
149 =head1 METHODS
150  
151 =head2 as_string
152  
153 For each element in it the current object array, this will call C<as_string> and concatenate those strings separated by C</>. It returns the result as a regular perl string.
154  
155 =head2 as_xml
156  
157 Calls C<as_xml> on each elements in the current object array and returns the concatenated string enclosed in <LocationPath> and </LocationPath>
158  
159 =head2 evaluate
160  
161 Provided with a L<context|HTML::Object::Element>, and this will call C<evaluate> for each object in the stack. It returns a new L<HTML::Object::XPath::NodeSet> object containing the result with the C<context> initially provided as the first in the node set.
162  
163 =head2 new_nodeset
164  
165 Returns a new L<HTML::Object::XPath::NodeSet> passing it whatever argument was provided.
166  
167 =head2 new_root
168  
169 Returns a new L<HTML::Object::XPath::Root> passing it whatever argument was provided.
170  
171 =head2 push
172  
173 Add the elements provided to the object array.
174  
175 =head2 set_root
176  
177 Add a new L<root object|HTML::Object::XPath::Root> as the first element of our internal array.
178  
179 =head1 AUTHOR
180  
181 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
182  
183 =head1 SEE ALSO
184  
185 L<HTML::Object::XPath>, L<HTML::Object::XPath::Boolean>, L<HTML::Object::XPath::Expr>, L<HTML::Object::XPath::Function>, L<HTML::Object::XPath::Literal>, L<HTML::Object::XPath::LocationPath>, L<HTML::Object::XPath::NodeSet>, L<HTML::Object::XPath::Number>, L<HTML::Object::XPath::Root>, L<HTML::Object::XPath::Step>, L<HTML::Object::XPath::Variable>
186  
187 =head1 COPYRIGHT & LICENSE
188  
189 Copyright(c) 2021 DEGUEST Pte. Ltd.
190  
191 All rights reserved
192  
193 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
194  
195 =cut
« blib/lib/HTML/Object/Event.pm ↑ Summary blib/lib/HTML/Object/DOM/TextTrackList.pm »