lib/HTML/Object/XPath/Number.pm

filter: Statementstmt 64.9% 37 / 57 Branchbran 6.2% 1 / 16 Conditioncond 20.0% 1 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 54.5% 12 / 22 Podpod 100% 13 / 13 totaltotal 55.1% 64 / 116 CC 11 SCAR 14.4
CC
11
Cov
50%
_class_for
12.0
as_string
6.0
as_xml
6.0
CRAP 4.2
« blib/lib/HTML/Object/DOM/Element/Output.pm ↑ Summary lib/HTML/Object/DOM/Comment.pm »
1 ##----------------------------------------------------------------------------
2 ## HTML Object - ~/lib/HTML/Object/XPath/Number.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::Number;
15 BEGIN
16 {
17 12 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 12 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 12 ▶ warnings::register_categories( 'HTML::Object' );
Subroutine BEGIN: called CC=1 SCAR=0.0
20 12 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 12 ▶ use vars qw( $TRUE $FALSE $BASE_CLASS $DEBUG $VERSION );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 12 ▶ use HTML::Object::XPath::Boolean;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 12 our $TRUE = HTML::Object::XPath::Boolean->True;
24 12 our $FALSE = HTML::Object::XPath::Boolean->False;
25 12 our $BASE_CLASS = 'HTML::Object::XPath';
26 12 our $DEBUG = 0;
27 12 our $VERSION = 'v0.2.0';
28 };
29  
30 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
31 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 sub new
34 {
35 32 ▶ my $this = shift( @_ );
Subroutine new: called CC=3 SCAR=12.3
Pod documented
36 32 my $number = shift( @_ );
37 32 ▶ if( $number !~ /^[[:blank:]\h]*[+-]?(\d+(\.\d*)?|\.\d+)[[:blank:]\h]*$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (not $number =~ /^[[:blank:]\h]*[+-]?(\d+(\.\d*)?|\.\d+)[[:blank:]\h]*$/) { } 0 32 32
38 {
39 0 $number = undef;
40 }
41 else
42 {
43 32 $number =~ s/^[[:blank:]\h]*(.*)[[:blank:]\h]*$/$1/;
44 }
45 32 ▶ return( bless( \$number => ( ref( $this ) || $this ) ) );
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
0320
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
46 }
47  
48 sub as_string
49 {
50 0 ▶ my $self = shift( @_ );
Subroutine as_string: not called CC=2 SCAR=17.9
Pod documented
51 0 ▶ return( defined( $$self ) ? $$self : 'NaN' );
Branch: 1 branch
BranchTrueFalseTotal
defined $$self ? : 0 0 0
52 }
53  
54 sub as_xml
55 {
56 0 ▶ my $self = shift( @_ );
Subroutine as_xml: not called CC=2 SCAR=17.9
Pod documented
57 0 ▶ return( "<Number>" . ( defined( $$self ) ? $$self : 'NaN' ) . "</Number>\n" );
Branch: 1 branch
BranchTrueFalseTotal
defined $$self ? : 0 0 0
58 }
59  
60 sub cmp
61 {
62 0 ▶ my $self = shift( @_ );
Subroutine cmp: not called CC=2 SCAR=17.9
Pod documented
63 0 my( $other, $swap ) = @_;
64 0 ▶ return( $swap ? $other <=> $$self : $$self <=> $other );
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 0 0 0
65 }
66  
67 46 ▶sub evaluate { return( $_[0] ); }
Subroutine evaluate: called CC=1 SCAR=0.0
Pod documented
68  
69 0 ▶sub getAttributes { return( wantarray() ? () : [] ); }
Subroutine getAttributes: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
70  
71 0 ▶sub getChildNodes { return( wantarray() ? () : [] ); }
Subroutine getChildNodes: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
72  
73 0 ▶sub new_literal { return( shift->_class_for( 'Literal' )->new( @_ ) ); }
Subroutine new_literal: not called CC=1 SCAR=6.9
Pod documented
74  
75 0 ▶sub string_value { return $_[0]->value }
Subroutine string_value: not called CC=1 SCAR=6.9
Pod documented
76  
77 0 ▶sub to_boolean { return( ${$_[0]} ? $TRUE : $FALSE ); }
Subroutine to_boolean: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
${$_[0];} ? : 0 0 0
78  
79 0 ▶sub to_literal { $_[0]->new_literal( $_[0]->as_string ); }
Subroutine to_literal: not called CC=1 SCAR=6.9
Pod documented
80  
81 16 ▶sub to_number { $_[0]; }
Subroutine to_number: called CC=1 SCAR=0.0
Pod documented
82  
83 66 ▶sub value { return( ${$_[0]} ); }
Subroutine value: called CC=1 SCAR=0.0
Pod documented
84  
85 sub _class_for
86 {
87 0 ▶ my( $self, $mod ) = @_;
Subroutine _class_for: not called CC=3 SCAR=24.8
88 0 eval( "require ${BASE_CLASS}\::${mod};" );
89 0 ▶ die( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
90 # ${"${BASE_CLASS}\::${mod}\::DEBUG"} = $DEBUG;
91 0 ▶ eval( "\$${BASE_CLASS}\::${mod}\::DEBUG = " . ( $DEBUG // 0 ) );
Condition0%0/2
$HTML::Object::XPath::Number::DEBUG // 0
l!l
00
MC/DC0%0/1
$HTML::Object::XPath::Number::DEBUG // 0
$HTML::Object::XPath::Number::DEBUG
Truth table0%0/2
A
A= $HTML::Object::XPath::Number::DEBUG
Aresult
11
00
92 0 return( "${BASE_CLASS}::${mod}" );
93 }
94  
95 12 1;
96 # NOTE: POD
97 __END__
98  
99 =encoding utf-8
100  
101 =head1 NAME
102  
103 HTML::Object::XPath::Number - HTML Object XPath Number Class
104  
105 =head1 SYNOPSIS
106  
107 use HTML::Object::XPath::Number;
108 my $num = HTML::Object::XPath::Number->new ||
109 die( HTML::Object::XPath::Number->error, "\n" );
110  
111 =head1 VERSION
112  
113 v0.2.0
114  
115 =head1 DESCRIPTION
116  
117 This module holds simple numeric values. It doesn't support -0, +/- Infinity, or NaN, as the XPath spec says it should.
118  
119 =head1 METHODS
120  
121 =head2 new
122  
123 Provided with a C<number> and this creates a new L<HTML::Object::XPath::Number> object, with the value in C<number>. Does some
124 rudimentary numeric checking on C<number> to ensure it actually is a number.
125  
126 =head2 as_string
127  
128 Returns a string representation of the number, or C<NaN> is undefined.
129  
130 =head2 as_xml
131  
132 Same as L</as_string>, but in xml format.
133  
134 =head2 cmp
135  
136 Returns the equivalent of perl's own L<perlop/cmp> operation.
137  
138 =head2 evaluate
139  
140 Returns the current object.
141  
142 =head2 getAttributes
143  
144 Returns an empty array reference in scalar context and an empty list in list context.
145  
146 =head2 getChildNodes
147  
148 Returns an empty array reference in scalar context and an empty list in list context.
149  
150 =head2 new_literal
151  
152 Returns a new L<HTML::Object::XPath::Literal> object, passing it whatever arguments was provided.
153  
154 =head2 string_value
155  
156 Returns the value of the current object by calling L</value>
157  
158 =head2 to_boolean
159  
160 Returns true if the current object has a L<true|HTML::Object::XPath::Boolean> value, or L<false|HTML::Object::XPath::Boolean> otherwise.
161  
162 =head2 to_literal
163  
164 Returns a new L<HTML::Object::XPath::Litteral> object of the stringification of the current object.
165  
166 =head2 to_number
167  
168 Returns the current object.
169  
170 =head2 value
171  
172 This returns the numeric value held. This is also the method used to return the value from strinfgification.
173  
174 =head1 AUTHOR
175  
176 Jacques Deguest E<lt>F<jack@deguest.jp>E<gt>
177  
178 =head1 SEE ALSO
179  
180 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>
181  
182 =head1 COPYRIGHT & LICENSE
183  
184 Copyright(c) 2021 DEGUEST Pte. Ltd.
185  
186 This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
187  
188 =cut
« blib/lib/HTML/Object/DOM/Element/Output.pm ↑ Summary lib/HTML/Object/DOM/Comment.pm »