File Coverage

lib/HTML/Object/XPath/Variable.pm
Criterion Covered Total %
statement 20 38 52.6
branch 0 2 0.0
condition n/a
subroutine 7 13 53.8
pod 6 6 100.0
total 33 59 55.9


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