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   61 use strict;
  8         18  
  8         262  
18 8     8   48 use warnings;
  8         19  
  8         244  
19 8     8   55 use parent qw( Module::Generic );
  8         21  
  8         68  
20 8     8   586 use vars qw( $BASE_CLASS $DEBUG $VERSION );
  8         20  
  8         664  
21 8     8   39 our $BASE_CLASS = 'HTML::Object::XPath';
22 8         20 our $DEBUG = 0;
23 8         164 our $VERSION = 'v0.2.0';
24             };
25              
26 8     8   50 use strict;
  8         34  
  8         196  
27 8     8   47 use warnings;
  8         33  
  8         2635  
28              
29             sub new
30             {
31 48     48 1 187 my $this = shift( @_ );
32 48         118 my $str = shift( @_ );
33 48   33     512 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 136 my $self = shift( @_ );
43 60         134 my $nodeset = shift( @_ );
44            
45             # must only ever occur on 1 node
46 60 50       243 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         226 my $newset = $self->new_nodeset;
50             # $newset->push($nodeset->get_node(1)->getRootNode());
51 60         294 my $node = $nodeset->get_node(1);
52             # $node->debug(4);
53 60         373 my $rootNode = $node->getRootNode();
54 60         826 $newset->push( $rootNode );
55 60         305 return( $newset );
56             }
57              
58 60     60 1 255 sub new_nodeset { return( shift->_class_for( 'NodeSet' )->new( @_ ) ); }
59              
60             sub _class_for
61             {
62 60     60   168 my( $self, $mod ) = @_;
63 60         2556 eval( "require ${BASE_CLASS}\::${mod};" );
64 60 50       347 die( $@ ) if( $@ );
65             # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG;
66 60   50     2514 eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) );
67 60         545 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