File Coverage

lib/HTML/Object/Number.pm
Criterion Covered Total %
statement 19 37 51.3
branch 0 8 0.0
condition 0 2 0.0
subroutine 7 17 41.1
pod 10 10 100.0
total 36 74 48.6


line stmt bran cond sub pod time code
1             ##----------------------------------------------------------------------------
2             ## HTML Object - ~/lib/HTML/Object/Number.pm
3             ## Version v0.2.0
4             ## Copyright(c) 2021 DEGUEST Pte. Ltd.
5             ## Author: Jacques Deguest <jack@deguest.jp>
6             ## Created 2021/04/22
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::Number;
15             BEGIN
16             {
17 7     7   44 use strict;
  7         13  
  7         221  
18 7     7   41 use warnings;
  7         15  
  7         199  
19 7     7   34 use parent qw( Module::Generic::Number );
  7         11  
  7         57  
20 7     7   511 use vars qw( $VERSION );
  7         20  
  7         299  
21 7     7   129 our $VERSION = 'v0.2.0';
22             };
23              
24 7     7   49 use strict;
  7         15  
  7         144  
25 7     7   34 use warnings;
  7         12  
  7         2525  
26              
27             sub as_xml
28             {
29 0     0 1   my $self = shift( @_ );
30 0           my $n = $self->as_string;
31 0 0         return( "<Number>" . ( defined( $n ) ? $n : 'NaN' ) . "</Number>\n" );
32             }
33              
34 0     0 1   sub evaluate { return( $_[0] ); }
35              
36             # Return an empty hash
37 0     0 1   sub getAttributes { return( shift->new_hash ); }
38              
39             # Return an empty array
40 0     0 1   sub getChildNodes { return( shift->new_array ); }
41              
42             sub isEqualNode
43             {
44 0     0 1   my $self = shift( @_ );
45 0   0       my $e = shift( @_ ) || return( $self->error( "No html element was provided to insert." ) );
46 0 0         return( $self->error( "Element provided (", overload::StrVal( $e ), ") is not an HTML::Object::Element." ) ) if( !$self->_is_a( $e => 'HTML::Object::Element' ) );
47 0 0         return(0) if( !$self->_is_a( $e => 'HTML::Object::Number' ) );
48 0           return( $self->value eq $e->value );
49             }
50              
51 0     0 1   sub string_value { return( $_[0]->value ); }
52              
53             sub to_boolean
54             {
55 0     0 1   require HTML::Object::Boolean;
56 0 0         return( shift->as_string ? HTML::Object::Boolean->True : HTML::Object::Boolean->False );
57             }
58              
59 0     0 1   sub to_number { return( $_[0] ); }
60              
61             sub to_literal
62             {
63 0     0 1   require HTML::Object::Literal;
64 0           return( HTML::Object::Literal->new( shift->as_string ) );
65             }
66              
67 0     0 1   sub value { return( shift->as_string ); }
68              
69             1;
70             # NOTE: POD
71             __END__
72              
73             =encoding utf-8
74              
75             =head1 NAME
76              
77             HTML::Object::Number - Simple numeric values
78              
79             =head1 SYNOPSIS
80              
81             use HTML::Object::Number;
82             my $this = HTML::Object::Number->new ||
83             die( HTML::Object::Number->error, "\n" );
84              
85             =head1 VERSION
86              
87             v0.2.0
88              
89             =head1 DESCRIPTION
90              
91             This class holds simple numeric values. It does not support -0, +/- Infinity, or NaN, as the XPath spec says it should, but I am not hurting anyone I do not think.
92              
93             =head1 METHODS
94              
95             =head2 new
96              
97             Provided with a C<number> and this creates a new L<HTML::Object::Number> object. Does some rudimentary numeric checking on the C<number> to ensure it actually is a number.
98              
99             =head2 as_xml
100              
101             Returns a string representation of the current value as xml.
102              
103             =head2 evaluate
104              
105             Returns the current object.
106              
107             =head2 getAttributes
108              
109             Returns an empty L<hash object|Module::Generic::Hash>
110              
111             =head2 getChildNodes
112              
113             Returns an empty L<array object|Module::Generic::Array>
114              
115             =head2 isEqualNode
116              
117             Returns a boolean value which indicates whether or not two elements are of the same type and all their defining data points match.
118              
119             Two elements are equal when they have the same type, defining characteristics (this would be their ID, number of children, and so forth), its attributes match, and so on. The specific set of data points that must match varies depending on the types of the elements.
120              
121             See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode>
122              
123             =head2 string_value
124              
125             Returns the current value.
126              
127             =head2 to_boolean
128              
129             Returns the current value as a L<boolean|HTML::Object::Boolean> object.
130              
131             =head2 to_literal
132              
133             Returns the current value as a L<literal object|HTML::Object::Literal>.
134              
135             =head2 to_number
136              
137             Returns the current object.
138              
139             =head2 value
140              
141             Also as overloaded stringification. Returns the numeric value held.
142              
143             =head1 AUTHOR
144              
145             Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
146              
147             =head1 SEE ALSO
148              
149             L<HTML::Object>, L<HTML::Object::Attribute>, L<HTML::Object::Boolean>, L<HTML::Object::Closing>, L<HTML::Object::Collection>, L<HTML::Object::Comment>, L<HTML::Object::Declaration>, L<HTML::Object::Document>, L<HTML::Object::Element>, L<HTML::Object::Exception>, L<HTML::Object::Literal>, L<HTML::Object::Number>, L<HTML::Object::Root>, L<HTML::Object::Space>, L<HTML::Object::Text>, L<HTML::Object::XQuery>
150              
151             =head1 COPYRIGHT & LICENSE
152              
153             Copyright (c) 2021 DEGUEST Pte. Ltd.
154              
155             All rights reserved
156              
157             This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
158              
159             =cut