blib/lib/HTML/Object/Number.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 83 CC 5 SCAR 13.9
CC
5
Cov
0%
isEqualNode
12.0
as_xml
6.0
to_boolean
6.0
CRAP 4.0
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 use strict;
18 use warnings;
19 warnings::register_categories( 'HTML::Object' );
20 use parent qw( Module::Generic::Number );
21 use vars qw( $VERSION );
22 our $VERSION = 'v0.2.0';
23 };
24  
25 use strict;
26 use warnings;
27  
28 sub as_xml
29 {
30 my $self = shift( @_ );
31 my $n = $self->as_string;
32 return( "<Number>" . ( defined( $n ) ? $n : 'NaN' ) . "</Number>\n" );
33 }
34  
35 sub evaluate { return( $_[0] ); }
36  
37 # Return an empty hash
38 sub getAttributes { return( shift->new_hash ); }
39  
40 # Return an empty array
41 sub getChildNodes { return( shift->new_array ); }
42  
43 sub isEqualNode
44 {
45 my $self = shift( @_ );
46 my $e = shift( @_ ) || return( $self->error( "No html element was provided to insert." ) );
47 return( $self->error( "Element provided (", overload::StrVal( $e ), ") is not an HTML::Object::Element." ) ) if( !$self->_is_a( $e => 'HTML::Object::Element' ) );
48 return(0) if( !$self->_is_a( $e => 'HTML::Object::Number' ) );
49 return( $self->value eq $e->value );
50 }
51  
52 sub string_value { return( $_[0]->value ); }
53  
54 sub to_boolean
55 {
56 require HTML::Object::Boolean;
57 return( shift->as_string ? HTML::Object::Boolean->True : HTML::Object::Boolean->False );
58 }
59  
60 sub to_number { return( $_[0] ); }
61  
62 sub to_literal
63 {
64 require HTML::Object::Literal;
65 return( HTML::Object::Literal->new( shift->as_string ) );
66 }
67  
68 sub value { return( shift->as_string ); }
69  
70 1;
71 # NOTE: POD
72 __END__
73  
74 =encoding utf-8
75  
76 =head1 NAME
77  
78 HTML::Object::Number - Simple numeric values
79  
80 =head1 SYNOPSIS
81  
82 use HTML::Object::Number;
83 my $this = HTML::Object::Number->new ||
84 die( HTML::Object::Number->error, "\n" );
85  
86 =head1 VERSION
87  
88 v0.2.0
89  
90 =head1 DESCRIPTION
91  
92 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.
93  
94 =head1 METHODS
95  
96 =head2 new
97  
98 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.
99  
100 =head2 as_xml
101  
102 Returns a string representation of the current value as xml.
103  
104 =head2 evaluate
105  
106 Returns the current object.
107  
108 =head2 getAttributes
109  
110 Returns an empty L<hash object|Module::Generic::Hash>
111  
112 =head2 getChildNodes
113  
114 Returns an empty L<array object|Module::Generic::Array>
115  
116 =head2 isEqualNode
117  
118 Returns a boolean value which indicates whether or not two elements are of the same type and all their defining data points match.
119  
120 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.
121  
122 See L<for more information|https://developer.mozilla.org/en-US/docs/Web/API/Node/isEqualNode>
123  
124 =head2 string_value
125  
126 Returns the current value.
127  
128 =head2 to_boolean
129  
130 Returns the current value as a L<boolean|HTML::Object::Boolean> object.
131  
132 =head2 to_literal
133  
134 Returns the current value as a L<literal object|HTML::Object::Literal>.
135  
136 =head2 to_number
137  
138 Returns the current object.
139  
140 =head2 value
141  
142 Also as overloaded stringification. Returns the numeric value held.
143  
144 =head1 AUTHOR
145  
146 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
147  
148 =head1 SEE ALSO
149  
150 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>
151  
152 =head1 COPYRIGHT & LICENSE
153  
154 Copyright (c) 2021 DEGUEST Pte. Ltd.
155  
156 All rights reserved
157  
158 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
159  
160 =cut