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

filter: Statementstmt 0.0% 0 / 40 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 62 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
init
2.0
as_string
2.0
CRAP 2.0
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/XPath/Variable.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::Variable;
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( $DEBUG $VERSION );
22 our $DEBUG = 0;
23 our $VERSION = 'v0.2.0';
24 };
25  
26 use strict;
27 use warnings;
28  
29 sub init
30 {
31 my $self = shift( @_ );
32 $self->{path_parser} = shift( @_ );
33 $self->{name} = shift( @_ );
34 $self->{_init_strict_use_sub} = 1;
35 $self->SUPER::init( @_ ) || return( $self->pass_error );
36 return( $self );
37 }
38  
39 sub as_string
40 {
41 my $self = shift( @_ );
42 return( '\$' . $self->{name} );
43 }
44  
45 sub as_xml
46 {
47 my $self = shift( @_ );
48 return( "<Variable>" . $self->{name} . "</Variable>\n" );
49 }
50  
51 sub get_value
52 {
53 my $self = shift( @_ );
54 return( $self->{path_parser}->get_var( $self->{name} ) );
55 }
56  
57 sub set_value
58 {
59 my $self = shift( @_ );
60 my $val = shift( @_ );
61 return( $self->{path_parser}->set_var( $self->{name} => $val ) );
62 }
63  
64 sub evaluate
65 {
66 my $self = shift( @_ );
67 my $val = $self->get_value;
68 return( $val );
69 }
70  
71 1;
72 # NOTE: POD
73 __END__
74  
75 =encoding utf-8
76  
77 =head1 NAME
78  
79 HTML::Object::XPath::Variable - HTML Object XPath Variable
80  
81 =head1 SYNOPSIS
82  
83 use HTML::Object::XPath::Variable;
84 my $var = HTML::Object::XPath::Variable->new ||
85 die( HTML::Object::XPath::Variable->error, "\n" );
86  
87 =head1 VERSION
88  
89 v0.2.0
90  
91 =head1 DESCRIPTION
92  
93 This represent a L<HTML::Object::XPath> variable
94  
95 =head1 CONSTRUCTOR
96  
97 =head2 new
98  
99 Provided with a L<HTML::Object::XPath> object and a variable name and this return a new l<HTML::Object::XPath::Variable> object.
100  
101 =head1 METHODS
102  
103 =head2 as_string
104  
105 Returns a string representation of the variable.
106  
107 =head2 as_xml
108  
109 Returns a xml representation of the variable.
110  
111 =head2 get_value
112  
113 Returns the value for the variable set upon object instantiation. This actually calls L<HTML::Object::XPath/get_var>
114  
115 =head2 set_value
116  
117 Set the value for the variable set upon object instantiation. This actually calls L<HTML::Object::XPath/set_var>
118  
119 =head2 evaluate
120  
121 Returns the variable value by returning L</get_value>
122  
123 =head1 AUTHOR
124  
125 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
126  
127 =head1 SEE ALSO
128  
129 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>
130  
131 =head1 COPYRIGHT & LICENSE
132  
133 Copyright(c) 2021 DEGUEST Pte. Ltd.
134  
135 All rights reserved
136  
137 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
138  
139 =cut