File Coverage

lib/HTML/Object/XPath/Root.pm
Criterion Covered Total %
statement 38 40 95.0
branch 2 4 50.0
condition 2 5 40.0
subroutine 11 13 84.6
pod 5 5 100.0
total 58 67 86.5


line stmt bran cond sub pod time code
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 8     8   55 use strict;
  8         16  
  8         234  
18 8     8   43 use warnings;
  8         12  
  8         210  
19 8     8   38 use parent qw( Module::Generic );
  8         15  
  8         43  
20 8     8   872 use vars qw( $BASE_CLASS $DEBUG $VERSION );
  8         15  
  8         557  
21 8     8   29 our $BASE_CLASS = 'HTML::Object::XPath';
22 8         26 our $DEBUG = 0;
23 8         153 our $VERSION = 'v0.2.0';
24             };
25              
26 8     8   55 use strict;
  8         17  
  8         169  
27 8     8   45 use warnings;
  8         15  
  8         2378  
28              
29             sub new
30             {
31 48     48 1 122 my $this = shift( @_ );
32 48         101 my $str = shift( @_ );
33 48   33     451 return( bless( \$str => ( ref( $this ) || $this ) ) );
34             }
35              
36 0     0 1 0 sub as_string { return; }
37              
38 0     0 1 0 sub as_xml { return( "<Root/>\n" ); }
39              
40             sub evaluate
41             {
42 60     60 1 156 my $self = shift( @_ );
43 60         124 my $nodeset = shift( @_ );
44            
45             # must only ever occur on 1 node
46 60 50       229 die "Can't go to root on > 1 node!" unless $nodeset->size == 1;
47             # return( $self->error( "Can't go to root on > 1 node!" ) ) unless( $nodeset->size == 1 );
48            
49 60         237 my $newset = $self->new_nodeset;
50             # $newset->push($nodeset->get_node(1)->getRootNode());
51 60         327 my $node = $nodeset->get_node(1);
52             # $node->debug(4);
53 60         342 my $rootNode = $node->getRootNode();
54 60         853 $newset->push( $rootNode );
55 60         267 return( $newset );
56             }
57              
58 60     60 1 215 sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); }
59              
60             sub _class_for
61             {
62 60     60   206 my( $self, $mod ) = @_;
63 60         2448 eval( "require ${BASE_CLASS}\::${mod};" );
64 60 50       372 die( $@ ) if( $@ );
65             # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG;
66 60   50     2406 eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) );
67 60         455 return( "${BASE_CLASS}::${mod}" );
68             }
69              
70             1;
71             # NOTE: POD
72             __END__
73              
74             =encoding utf-8
75              
76             =head1 NAME
77              
78             HTML::Object::XPath::Root - HTML Object
79              
80             =head1 SYNOPSIS
81              
82             use HTML::Object::XPath::Root;
83             my $root = HTML::Object::XPath::Root->new ||
84             die( HTML::Object::XPath::Root->error, "\n" );
85              
86             =head1 VERSION
87              
88             v0.2.0
89              
90             =head1 DESCRIPTION
91              
92             This module represents a root element, which is the top element.
93              
94             =head1 CONSTRUCTOR
95              
96             =head2 new
97              
98             Provided with a string, and this returns a new L<HTML::Object::XPath::Root> object.
99              
100             =head1 METHODS
101              
102             =head2 as_string
103              
104             Returns C<undef> in scalar context and an empty list in list context.
105              
106             =head2 as_xml
107              
108             Returns C<<Root/>>
109              
110             =head2 evaluate
111              
112             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.
113              
114             =head2 new_nodeset
115              
116             Returns a new L<HTML::Object::XPath::NodeSet> passing it whatever argument was provided.
117              
118             =head1 AUTHOR
119              
120             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
121              
122             =head1 SEE ALSO
123              
124             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>
125              
126             =head1 COPYRIGHT & LICENSE
127              
128             Copyright(c) 2021 DEGUEST Pte. Ltd.
129              
130             All rights reserved
131              
132             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
133              
134             =cut