lib/HTML/Object/XPath/Root.pm

filter: Statementstmt 95.2% 40 / 42 Branchbran 50.0% 2 / 4 Conditioncond 40.0% 2 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 84.6% 11 / 13 Podpod 100% 5 / 5 totaltotal 83.3% 60 / 72 CC 5 SCAR 5.5
CC
5
Cov
86%
_class_for
3.1
new
2.1
evaluate
2.0
CRAP 1.7
« lib/HTML/Object/DOM/Element/Meta.pm ↑ Summary lib/HTML/Object/DOM/Screen.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/XPath/Root.pm
3 ## Version v0.2.0
4 ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/12/04
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::Root;
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 45 ▶ my $this = shift( @_ );
Subroutine new: called CC=2 SCAR=7.6
Pod documented
33 45 my $str = shift( @_ );
34 45 ▶ return( bless( \$str => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0450
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
35 }
36  
37 0 ▶sub as_string { return; }
Subroutine as_string: not called CC=1 SCAR=6.9
Pod documented
38  
39 0 ▶sub as_xml { return( "<Root/>\n" ); }
Subroutine as_xml: not called CC=1 SCAR=6.9
Pod documented
40  
41 sub evaluate
42 {
43 57 ▶ my $self = shift( @_ );
Subroutine evaluate: called CC=2 SCAR=7.0
Pod documented
44 57 my $nodeset = shift( @_ );
45
46 # must only ever occur on 1 node
47 57 ▶ die "Can't go to root on > 1 node!" unless $nodeset->size == 1;
Branch: 1 branch
BranchTrueFalseTotal
unless $nodeset->size == 1 0 57 57
48 # return( $self->error( "Can't go to root on > 1 node!" ) ) unless( $nodeset->size == 1 );
49
50 57 my $newset = $self->new_nodeset;
51 # $newset->push($nodeset->get_node(1)->getRootNode());
52 57 my $node = $nodeset->get_node(1);
53 # $node->debug(4);
54 57 my $rootNode = $node->getRootNode();
55 57 $newset->push( $rootNode );
56 57 return( $newset );
57 }
58  
59 57 ▶sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); }
Subroutine new_nodeset: called CC=1 SCAR=0.0
Pod documented
60  
61 sub _class_for
62 {
63 57 ▶ my( $self, $mod ) = @_;
Subroutine _class_for: called CC=3 SCAR=11.3
64 57 eval( "require ${BASE_CLASS}\::${mod};" );
65 57 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 57 57
66 # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG;
67 57 ▶ eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) );
Condition50%1/2
$HTML::Object::XPath::Root::DEBUG // 0
l!l
570
MC/DC0%0/1
$HTML::Object::XPath::Root::DEBUG // 0
$HTML::Object::XPath::Root::DEBUG
Truth table50%1/2
A
A= $HTML::Object::XPath::Root::DEBUG
Aresult
11
00
68 57 return( "${BASE_CLASS}::${mod}" );
69 }
70  
71 12 1;
72 # NOTE: POD
73 __END__
74  
75 =encoding utf-8
76  
77 =head1 NAME
78  
79 HTML::Object::XPath::Root - HTML Object
80  
81 =head1 SYNOPSIS
82  
83 use HTML::Object::XPath::Root;
84 my $root = HTML::Object::XPath::Root->new ||
85 die( HTML::Object::XPath::Root->error, "\n" );
86  
87 =head1 VERSION
88  
89 v0.2.0
90  
91 =head1 DESCRIPTION
92  
93 This module represents a root element, which is the top element.
94  
95 =head1 CONSTRUCTOR
96  
97 =head2 new
98  
99 Provided with a string, and this returns a new L<HTML::Object::XPath::Root> object.
100  
101 =head1 METHODS
102  
103 =head2 as_string
104  
105 Returns C<undef> in scalar context and an empty list in list context.
106  
107 =head2 as_xml
108  
109 Returns C<<Root/>>
110  
111 =head2 evaluate
112  
113 Provided with a L<node set|HTML::Object::XPath::NodeSet> object and this the first element in the node set, get its root node and return a new L<set|HTML::Object::XPath::NodeSet> with the node as its sole element.
114  
115 =head2 new_nodeset
116  
117 Returns a new L<HTML::Object::XPath::NodeSet> passing it whatever argument was provided.
118  
119 =head1 AUTHOR
120  
121 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
122  
123 =head1 SEE ALSO
124  
125 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>
126  
127 =head1 COPYRIGHT & LICENSE
128  
129 Copyright(c) 2021 DEGUEST Pte. Ltd.
130  
131 All rights reserved
132  
133 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
134  
135 =cut
« lib/HTML/Object/DOM/Element/Meta.pm ↑ Summary lib/HTML/Object/DOM/Screen.pm »