blib/lib/HTML/Object/XPath/Root.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 71 CC 3 SCAR 11.2
CC
3
Cov
0%
evaluate
6.0
_class_for
6.0
BEGIN
2.0
CRAP 3.1
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 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( Module::Generic );
21 use vars qw( $BASE_CLASS $DEBUG $VERSION );
22 our $BASE_CLASS = 'HTML::Object::XPath';
23 our $DEBUG = 0;
24 our $VERSION = 'v0.2.0';
25 };
26  
27 use strict;
28 use warnings;
29  
30 sub new
31 {
32 my $this = shift( @_ );
33 my $str = shift( @_ );
34 return( bless( \$str => ( ref( $this ) || $this ) ) );
35 }
36  
37 sub as_string { return; }
38  
39 sub as_xml { return( "<Root/>\n" ); }
40  
41 sub evaluate
42 {
43 my $self = shift( @_ );
44 my $nodeset = shift( @_ );
45
46 # must only ever occur on 1 node
47 die "Can't go to root on > 1 node!" unless $nodeset->size == 1;
48 # return( $self->error( "Can't go to root on > 1 node!" ) ) unless( $nodeset->size == 1 );
49
50 my $newset = $self->new_nodeset;
51 # $newset->push($nodeset->get_node(1)->getRootNode());
52 my $node = $nodeset->get_node(1);
53 # $node->debug(4);
54 my $rootNode = $node->getRootNode();
55 $newset->push( $rootNode );
56 return( $newset );
57 }
58  
59 sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); }
60  
61 sub _class_for
62 {
63 my( $self, $mod ) = @_;
64 eval( "require ${BASE_CLASS}\::${mod};" );
65 die( $@ ) if( $@ );
66 # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG;
67 eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) );
68 return( "${BASE_CLASS}::${mod}" );
69 }
70  
71 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