lib/Module/Generic/Number.pm

filter: Statementstmt 76.6% 518 / 676 Branchbran 46.4% 159 / 342 Conditioncond 33.5% 45 / 134 MC/DCmcdc 4.0% 3 / 74 Subroutinesub 75.4% 166 / 220 Podpod 94.6% 88 / 93 totaltotal 63.6% 979 / 1539 CC 223 SCAR 25.0
CC
223
Cov
63%
__ANON__
56.0
max
46.6
min
46.6
CRAP 12.2
« lib/Module/Generic/Finfo.pm ↑ Summary lib/Module/Generic/TieHash.pm »
1 ##----------------------------------------------------------------------------
2 ## Module Generic - ~/lib/Module/Generic/Number.pm
3 ## Version v2.5.1
4 ## Copyright(c) 2026 DEGUEST Pte. Ltd.
5 ## Author: Jacques Deguest <jack@deguest.jp>
6 ## Created 2021/03/20
7 ## Modified 2026/07/05
8 ## All rights reserved
9 ##
10 ## This program is free software; you can redistribute it and/or modify it
11 ## under the same terms as Perl itself.
12 ##----------------------------------------------------------------------------
13 package Module::Generic::Number;
14 BEGIN
15 18 ▶{
Subroutine BEGIN: called CC=2 SCAR=8.3
16 18 ▶ use v5.16.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 18 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 18 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 18 warnings::register_categories( 'Module::Generic' );
20 18 ▶ use parent qw( Module::Generic );
Subroutine BEGIN: called CC=1 SCAR=0.0
21 18 ▶ use vars qw( $SUPPORTED_LOCALES $DEFAULT $NUMBER_RE $LOCALE_LOCK );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 18 ▶ use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 18 require POSIX;
24 18 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 18 0 18
25 {
26 18 POSIX->import( qw( cbrt isfinite isinf isnan isnormal signbit ) );
27 }
28 else
29 {
30 0 my $POS_INF = 9**9**9;
31 0 my $NEG_INF = -$POS_INF;
32 *isinf = sub
33 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=18.1
34 0 ▶ return(0) if( !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
35 18 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
36 0 ▶ return( $_[0] == $POS_INF || $_[0] == $NEG_INF );
Condition0%0/3
$_[0] == $POS_INF || $_[0] == $NEG_INF
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] == $POS_INF || $_[0] == $NEG_INF
$_[0] == $POS_INF $_[0] == $NEG_INF
Truth table0%0/3
A || B
A= $_[0] == $POS_INFB= $_[0] == $NEG_INF
ABresult
1X1
011
000
37 0 };
38 *isnan = sub
39 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=10.1
40 0 ▶ return(0) if( !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
41 18 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
42 0 return( $_[0] != $_[0] );
43 0 };
44 0 ▶ *isfinite = sub { my $n = $_[0]; return( $n == $n && $n != $POS_INF && $n != $NEG_INF ? 1 : 0 ); };
Subroutine __ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
BranchTrueFalseTotal
$n == $n && $n != $POS_INF && $n != $NEG_INF ? : 0 0 0
Condition0%0/6
$n == $n and $n != $POS_INF and $n != $NEG_INF
!ll&&!rl&&r
000
$n == $n and $n != $POS_INF
!ll&&!rl&&r
000
MC/DC0%0/3
$n == $n and $n != $POS_INF and $n != $NEG_INF
$n == $n $n != $POS_INF $n != $NEG_INF
Truth table0%0/4
A and B and C
A= $n == $nB= $n != $POS_INFC= $n != $NEG_INF
ABCresult
0XX0
10X0
1100
1111
45 *isnormal = sub
46 0 ▶ {
Subroutine __ANON__: not called CC=7 SCAR=40.3
47 0 my $n = $_[0];
48 0 ▶ return(0) if( $n != $n );
Branch: 1 branch
BranchTrueFalseTotal
if $n != $n 0 0 0
49 0 ▶ return(0) if( $n == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $n == 0 0 0 0
50 0 ▶ return(0) if( $n == $POS_INF || $n == $NEG_INF );
Branch: 1 branch
BranchTrueFalseTotal
if $n == $POS_INF or $n == $NEG_INF 0 0 0
Condition0%0/3
$n == $POS_INF or $n == $NEG_INF
l!l&&r!l&&!r
000
MC/DC0%0/2
$n == $POS_INF or $n == $NEG_INF
$n == $POS_INF $n == $NEG_INF
Truth table0%0/3
A or B
A= $n == $POS_INFB= $n == $NEG_INF
ABresult
1X1
011
000
51 0 ▶ my $abs = $n < 0 ? -$n : $n;
Branch: 1 branch
BranchTrueFalseTotal
$n < 0 ? : 0 0 0
52 0 ▶ return( $abs >= 2.2250738585072014e-308 ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$abs >= 2.2250738585072013831e-308 ? : 0 0 0
53 0 };
54 # signbit: returns non-zero for negative numbers (including -0.0)
55 *signbit = sub
56 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
57 0 my $n = $_[0];
58 0 ▶ return(1) if( $n < 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $n < 0 0 0 0
59 0 ▶ return(0) if( $n > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $n > 0 0 0 0
60 # zero or NaN: check string representation for -0
61 0 ▶ return( sprintf( "%g", $n ) =~ /^-/ ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
sprintf('%g', $n) =~ /^-/u ? : 0 0 0
62 0 };
63 # cbrt: handle negatives correctly (real cube root)
64 *cbrt = sub
65 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=17.9
66 0 my $n = $_[0];
67 0 ▶ return( $n < 0 ? -( ( -$n ) ** ( 1/3 ) ) : $n ** ( 1/3 ) );
Branch: 1 branch
BranchTrueFalseTotal
$n < 0 ? : 0 0 0
68 0 };
69 }
70  
71 # 2026-05-17: Regexp::Common does not install under perl v5.10.1 because of an error in its test t/test_comments.t
72 # use Regexp::Common qw( number );
73 # $NUMBER_RE = $RE{num}{real};
74 18 $NUMBER_RE = qr/(?:(?i)(?:[-+]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[-+]?)(?:[0123456789]+))|))/;
75 18 ▶ use Scalar::Util ();
Subroutine BEGIN: called CC=1 SCAR=0.0
76 18 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
77 # I know there is the nomethod feature, but I need to provide return_object set to true or false
78 # And I do not necessarily want to catch all the operation.
79 319 ▶ '""' => sub { return( shift->{_number} ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
80 # numeric context
81 '0+' => \&as_number,
82 17 ▶ '-' => sub { return( shift->compute( @_, { op => '-', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
83 6 ▶ '+' => sub { return( shift->compute( @_, { op => '+', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
84 3 ▶ '*' => sub { return( shift->compute( @_, { op => '*', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
85 4 ▶ '/' => sub { return( shift->compute( @_, { op => '/', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
86 2 ▶ '%' => sub { return( shift->compute( @_, { op => '%', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
87 # Exponent
88 3 ▶ '**' => sub { return( shift->compute( @_, { op => '**', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
89 # Bitwise AND
90 1 ▶ '&' => sub { return( shift->compute( @_, { op => '&', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
91 # Bitwise OR
92 1 ▶ '|' => sub { return( shift->compute( @_, { op => '|', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
93 # Bitwise XOR
94 1 ▶ '^' => sub { return( shift->compute( @_, { op => '^', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
95 # Bitwise shift left
96 12 ▶ '<<' => sub { return( shift->compute( @_, { op => '<<', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
97 # Bitwise shift right
98 1 ▶ '>>' => sub { return( shift->compute( @_, { op => '>>', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
99 2 ▶ 'x' => sub { return( shift->compute( @_, { op => 'x', return_object => 1, type => 'scalar' }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
100 2 ▶ '+=' => sub { return( shift->compute( @_, { op => '+=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
101 1 ▶ '-=' => sub { return( shift->compute( @_, { op => '-=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
102 2 ▶ '*=' => sub { return( shift->compute( @_, { op => '*=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
103 1 ▶ '/=' => sub { return( shift->compute( @_, { op => '/=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
104 1 ▶ '%=' => sub { return( shift->compute( @_, { op => '%=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
105 1 ▶ '**=' => sub { return( shift->compute( @_, { op => '**=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
106 1 ▶ '<<=' => sub { return( shift->compute( @_, { op => '<<=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
107 1 ▶ '>>=' => sub { return( shift->compute( @_, { op => '>>=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
108 1 ▶ 'x=' => sub { return( shift->compute( @_, { op => 'x=', return_object => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
109 # '.=' => sub { return( shift->compute( @_, { op => '.=', return_object => 1 }) ); },
110 '.=' => sub
111 2 ▶ {
Subroutine __ANON__: called CC=6 SCAR=18.5
112 2 my( $self, $other, $swap ) = @_;
113 2 my $op = '.=';
114 18 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
115 2 ▶ my $operation = $swap ? "${other} ${op} \$self->{_number}" : "\$self->{_number} ${op} ${other}";
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 0 2 2
116 2 my $res = eval( $operation );
117 2 ▶ warn( "Error with formula \"$operation\": $@" ) if( $@ && $self->_warnings_is_enabled( 'Module::Generic' ) );
Branch: 1 branch
BranchTrueFalseTotal
if $@ and $self->_warnings_is_enabled("Module::Generic") 0 2 2
Condition33%1/3
$@ and $self->_warnings_is_enabled("Module::Generic")
!ll&&!rl&&r
200
MC/DC0%0/2
$@ and $self->_warnings_is_enabled("Module::Generic")
$@ $self->_warnings_is_enabled("Module::Generic")
Truth table33%1/3
A and B
A= $@B= $self->_warnings_is_enabled("Module::Generic")
ABresult
0X0
100
111
118 2 ▶ return if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
119 # Concatenated something. If it still look like a number, we return it as an object
120 2 ▶ if( $res =~ /^$NUMBER_RE$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($res =~ /^$NUMBER_RE$/u) { } 1 1 2
121 {
122 1 return( $self->clone( $res ) );
123 }
124 # Otherwise we pass it to the scalar module
125 else
126 {
127 1 return( Module::Generic::Scalar->new( "$res" ) );
128 }
129 },
130 21 ▶ '<' => sub { return( shift->compute( @_, { op => '<', boolean => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
131 2 ▶ '<=' => sub { return( shift->compute( @_, { op => '<=', boolean => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
132 125 ▶ '>' => sub { return( shift->compute( @_, { op => '>', boolean => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
133 112 ▶ '>=' => sub { return( shift->compute( @_, { op => '>=', boolean => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
134 3 ▶ '<=>' => sub { return( shift->compute( @_, { op => '<=>', return_object => 0 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
135 33 ▶ '==' => sub { return( shift->compute( @_, { op => '==', boolean => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
136 3 ▶ '!=' => sub { return( shift->compute( @_, { op => '!=', boolean => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
137 175 ▶ 'eq' => sub { return( shift->compute( @_, { op => 'eq', boolean => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
138 1 ▶ 'ne' => sub { return( shift->compute( @_, { op => 'ne', boolean => 1 }) ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
139 '++' => sub
140 3 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
141 3 my( $self ) = @_;
142 3 return( ++$self->{_number} );
143 },
144 '--' => sub
145 5 ▶ {
Subroutine __ANON__: called CC=1 SCAR=0.0
146 5 my( $self ) = @_;
147 5 return( --$self->{_number} );
148 },
149 18 'fallback' => 1,
150 18 );
151 18 ▶ use constant HAS_THREADS => $Config{useithreads};
Subroutine BEGIN: called CC=1 SCAR=0.0
152 18 if( HAS_THREADS )
153 {
154 require threads;
155 require threads::shared;
156 threads->import();
157 threads::shared->import();
158 18 ▶ our $LOCALE_LOCK :shared;
Subroutine BEGIN: called CC=1 SCAR=0.0
159 }
160 18 our( $VERSION ) = 'v2.5.1';
161 };
162  
163 # use strict;
164 18 ▶no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
165 18 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
166  
167 sub init
168 691 ▶{
Subroutine init: called CC=20 SCAR=32.1
Pod documented
169 691 my $self = shift( @_ );
170 691 ▶ return( $self->error( "No number was provided." ) ) if( !scalar( @_ ) );
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @_ 0 691 691
171 691 my $num = shift( @_ );
172 691 ▶ return( $self->error( "Number provided is undefined" ) ) if( !defined( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $num 0 691 691
173 691 my $opts = $self->_get_args_as_hash( @_ );
174 # Trigger overloading to string operation
175 691 ▶ $num = "$num" if( ref( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
if ref $num 7 684 691
176 691 ▶ return( $self->error( "Number value provided is empty" ) ) if( !CORE::length( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
unless CORE::length $num 0 691 691
177 {
178 18 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
179 691 ▶ return( Module::Generic::Infinity->new( $num ) ) if( isinf( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($num) 1 690 691
180 690 ▶ return( Module::Generic::Nan->new( $num ) ) if( isnan( $num ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($num) 1 689 690
181 }
182 689 ▶ if( !exists( $opts->{locale} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opts->{"locale"} and exists $opts->{"lang"}) 0 689 689
Condition33%1/3
not exists $opts->{"locale"} and exists $opts->{"lang"}
!ll&&!rl&&r
06890
MC/DC0%0/2
not exists $opts->{"locale"} and exists $opts->{"lang"}
not exists $opts->{"locale"} exists $opts->{"lang"}
Truth table33%1/3
not(A) and B
A= not exists $opts->{"locale"}B= exists $opts->{"lang"}
ABresult
0X0
100
111
183 exists( $opts->{lang} ) )
184 {
185 0 $opts->{locale} = CORE::delete( $opts->{lang} );
186 }
187 689 ▶ my $locale = exists( $opts->{locale} ) ? CORE::delete( $opts->{locale} ) : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $opts->{'locale'} ? : 0 689 689
188 689 ▶ $locale //= '';
Condition50%1/2
$locale //= ""
l!l
6890
MC/DC0%0/1
$locale //= ""
$locale
Truth table50%1/2
A
A= $locale
Aresult
11
00
189 689 my( $locale2, $locale_enc ) = split( /\./, $locale, 2 );
190 689 ▶ $locale = $locale2 // '';
Condition50%1/2
$locale2 // ""
l!l
0689
MC/DC0%0/1
$locale2 // ""
$locale2
Truth table50%1/2
A
A= $locale2
Aresult
11
00
191 689 $locale =~ tr/-/_/;
192 689 ▶ $locale = join( '.', $locale, $locale_enc ) if( defined( $locale_enc ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $locale_enc 0 689 689
193 689 $self->{locale} = $locale;
194 689 ▶ $self->debug( CORE::delete( $opts->{debug} ) ) if( exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if exists $opts->{"debug"} 12 677 689
195 # Convert Japanese double bytes numbers to regular digits.
196 689 $num =~ tr/[\x{FF10}-\x{FF19}]+ー/[0-9]+-/;
197 689 ▶ if( $num !~ /^$NUMBER_RE$/ )
Branch: 1 branch
BranchTrueFalseTotal
if (not $num =~ /^$NUMBER_RE$/) { } 1 688 689
198 {
199 1 ▶ $self->_load_class( 'Module::Generic::Number::Format' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Number::Format") or return $self->pass_error 1 0 1
200 1 ▶ my $fmt = Module::Generic::Number::Format->new( "$num", ( $locale ? ( locale => $locale ) : () ) ) ||
Branch: 1 branch
BranchTrueFalseTotal
$locale ? : 0 1 1
Condition50%1/2
'Module::Generic::Number::Format'->new("$num", $locale ? ('locale', $locale) : ()) || (return $self->pass_error('Module::Generic::Number::Format'->error))
l!l
01
MC/DC0%0/1
'Module::Generic::Number::Format'->new("$num", $locale ? ('locale', $locale) : ()) || (return $self->pass_error('Module::Generic::Number::Format'->error))
'Module::Generic::Number::Format'->new("$num", $locale ? ('locale', $locale) : ())
Truth table50%1/2
A
A= 'Module::Generic::Number::Format'->new("$num", $locale ? ('locale', $locale) : ())
Aresult
11
00
201 return( $self->pass_error( Module::Generic::Number::Format->error ) );
202 0 $self->{_number} = $fmt->as_string;
203 }
204 else
205 {
206 688 $self->{_number} = $num;
207 }
208 688 $self->{_init_strict_use_sub} = 1;
209 # $self->SUPER::init( %$opts ) || return( $self->pass_error );
210 688 my $rv = $self->SUPER::init( %$opts );
211 688 ▶ return( $self->pass_error ) if( !defined( $rv ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $rv 0 688 688
212 688 $self->{_original} = $num;
213 688 $self->{_fields} = [qw( locale _number )];
214 688 ▶ return( $self->error( "Invalid number: $num (", overload::StrVal( $num ), ")" ) ) if( !defined( $self->{_number} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_number"} 0 688 688
215 688 return( $self );
216 }
217  
218 4 ▶sub abs { return( shift->_func( 'abs' ) ); }
Subroutine abs: called CC=1 SCAR=0.0
Pod documented
219  
220 # sub asin { return( shift->_func( 'asin', { posix => 1 } ) ); }
221  
222 # This class does not convert to an HASH, but the TO_JSON method will convert to a string
223 1 ▶sub as_hash { return( $_[0] ); }
Subroutine as_hash: called CC=1 SCAR=0.0
Pod documented
224  
225 1 ▶sub atan { return( shift->_func( 'atan', { posix => 1 } ) ); }
Subroutine atan: called CC=1 SCAR=0.0
Pod documented
226  
227 1 ▶sub atan2 { return( shift->_func( 'atan2', @_ ) ); }
Subroutine atan2: called CC=1 SCAR=0.0
Pod documented
228  
229 sub as_array
230 1 ▶{
Subroutine as_array: called CC=3 SCAR=11.4
Pod documented
231 1 my $self = shift( @_ );
232 1 ▶ return( $self->error( 'as_array() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
233 1 ▶ $self->_load_class( 'Module::Generic::Array' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Array") or return $self->pass_error 1 0 1
234 1 return( Module::Generic::Array->new( [ $self->{_number} ] ) );
235 }
236  
237 sub as_boolean
238 4 ▶{
Subroutine as_boolean: called CC=4 SCAR=14.2
Pod documented
239 4 my $self = shift( @_ );
240 4 ▶ return( $self->error( 'as_boolean() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 4 4
241 4 ▶ $self->_load_class( 'Module::Generic::Boolean' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Boolean") or return $self->pass_error 4 0 4
242 4 ▶ return( Module::Generic::Boolean->new( $self->{_number} ? 1 : 0 ) );
Branch: 1 branch
BranchTrueFalseTotal
$self->{'_number'} ? : 2 2 4
243 }
244  
245 sub as_number
246 105 ▶{
Subroutine as_number: called CC=2 SCAR=7.1
Pod documented
247 105 my $self = shift( @_ );
248 105 ▶ return( $self->error( 'as_number() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 105 105
249 105 return( $self->{_number} + 0 );
250 }
251  
252 sub as_scalar
253 1 ▶{
Subroutine as_scalar: called CC=3 SCAR=11.4
Pod documented
254 1 my $self = shift( @_ );
255 1 ▶ return( $self->error( 'as_scalar() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
256 1 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 1 0 1
257 1 return( Module::Generic::Scalar->new( $self->{_number} ) );
258 }
259  
260 7 ▶sub as_string { return( shift->{_number} ) }
Subroutine as_string: called CC=1 SCAR=0.0
Pod documented
261  
262 sub cbrt
263 1 ▶{
Subroutine cbrt: called CC=7 SCAR=32.5
264 1 my $self = shift( @_ );
265 1 ▶ return( $self->error( 'cbrt() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
266 1 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 1 0 1
267 {
268 1 return( $self->_func( 'cbrt', { posix => 1 } ) );
269 }
270 else
271 {
272 0 my $n = $self->{_number};
273 # Handle negative numbers properly: cbrt(-x) = -cbrt(x)
274 0 ▶ my $res = $n < 0 ? -( ( -$n ) ** ( 1/3 ) ) : $n ** ( 1/3 );
Branch: 1 branch
BranchTrueFalseTotal
$n < 0 ? : 0 0 0
275 0 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
276 0 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 0 0 0
277 0 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 0 0 0
278 # No need to explicitly clear errors here, because clone() does it for us.
279 0 return( $self->clone( $res ) );
280 }
281 }
282  
283 1 ▶sub ceil { return( shift->_func( 'ceil', { posix => 1 } ) ); }
Subroutine ceil: called CC=1 SCAR=0.0
Pod documented
284  
285 sub chr
286 1 ▶{
Subroutine chr: called CC=3 SCAR=11.4
Pod documented
287 1 my $self = shift( @_ );
288 1 ▶ return( $self->error( 'chr() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
289 1 ▶ $self->_load_class( 'Module::Generic::Scalar' ) || return( $self->pass_error );
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or return $self->pass_error 1 0 1
290 1 return( Module::Generic::Scalar->new( CORE::chr( $self->{_number} ) ) );
291 }
292  
293 sub clone
294 81 ▶{
Subroutine clone: called CC=11 SCAR=26.6
Pod documented
295 81 my $self = shift( @_ );
296 81 ▶ return( $self->error( 'clone() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 1 80 81
297 80 my $new;
298 # Called as a class function
299 80 ▶ if( !$self->_is_object( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->_is_object($self)) { } 0 80 80
300 {
301 0 ▶ my $num = shift( @_ ) // 0;
Condition0%0/2
shift @_ // 0
l!l
00
MC/DC0%0/1
shift @_ // 0
shift @_
Truth table0%0/2
A
A= shift @_
Aresult
11
00
302 0 $new = $self->new( $num );
303 0 ▶ return( $self->pass_error ) if( !defined( $new ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 0 0
304 }
305 else
306 {
307 80 ▶ my $num = @_ ? shift( @_ ) : $self->{_number};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 77 3 80
308 80 ▶ my $actual_num = $self->_is_a( $num => 'Module::Generic::Number' ) ? $num->{_number} : $num;
Branch: 1 branch
BranchTrueFalseTotal
$self->_is_a($num, 'Module::Generic::Number') ? : 0 80 80
309 80 ▶ return( Module::Generic::Infinity->new( $actual_num ) ) if( isinf( $actual_num ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($actual_num) 0 80 80
310 80 ▶ return( Module::Generic::Nan->new( $actual_num ) ) if( isnan( $actual_num ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($actual_num) 0 80 80
311 80 $new = $self->SUPER::clone;
312 80 ▶ return( $self->pass_error ) if( !defined( $new ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $new 0 80 80
313 80 $new->{_number} = $actual_num;
314 80 my $old_fmt = CORE::delete( $new->{_formatter} );
315 80 ▶ if( $old_fmt )
Branch: 1 branch
BranchTrueFalseTotal
if ($old_fmt) 54 26 80
316 {
317 54 my $fmt = $old_fmt->clone( $actual_num );
318 54 $new->{_formatter} = $fmt;
319 }
320 80 $new->clear_error;
321 }
322 80 return( $new );
323 }
324  
325 sub compute
326 539 ▶{
Subroutine compute: called CC=22 SCAR=33.8
Pod undocumented
327 539 my $self = shift( @_ );
328 539 my $opts = pop( @_ );
329 539 my( $other, $swap, $nomethod, $bitwise ) = @_;
330 539 ▶ return( $self->error( 'compute() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 539 539
331 539 ▶ if( !defined( $opts ) ||
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"} or not defined $opts->{"op"} or not CORE::length $opts->{"op"}) 0 539 539
Condition33%4/12
not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"} or not defined $opts->{"op"} or not CORE::length $opts->{"op"}
l!l&&r!l&&!r
00539
not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"} or not defined $opts->{"op"}
l!l&&r!l&&!r
00539
not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"}
l!l&&r!l&&!r
00539
not defined $opts or ref $opts ne "HASH"
l!l&&r!l&&!r
00539
MC/DC0%0/5
not defined $opts or ref $opts ne "HASH" or not exists $opts->{"op"} or not defined $opts->{"op"} or not CORE::length $opts->{"op"}
not defined $opts ref $opts ne "HASH" not exists $opts->{"op"} not defined $opts->{"op"} not CORE::length $opts->{"op"}
Truth table16%1/6
not(A) or B or not(C) or not(D) or not(E)
A= not defined $optsB= ref $opts ne "HASH"C= not exists $opts->{"op"}D= not defined $opts->{"op"}E= not CORE::length $opts->{"op"}
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
332 ref( $opts ) ne 'HASH' ||
333 !exists( $opts->{op} ) ||
334 !defined( $opts->{op} ) ||
335 !length( $opts->{op} ) )
336 {
337 0 die( "No argument 'op' provided" );
338 }
339 539 my $op = $opts->{op};
340  
341 539 my $allowed =
342 {
343 '+' => 1, '-' => 1, '*' => 1, '/' => 1, '%' => 1, '**' => 1,
344 '&' => 1, '|' => 1, '^' => 1, '<<' => 1, '>>' => 1, 'x' => 1,
345 '+=' => 1, '-=' => 1, '*=' => 1, '/=' => 1, '%=' => 1, '**=' => 1,
346 '<<=' => 1, '>>=' => 1, 'x=' => 1,
347 '<' => 1, '<=' => 1, '>' => 1, '>=' => 1, '<=>' => 1,
348 '==' => 1, '!=' => 1, 'eq' => 1, 'ne' => 1,
349 };
350 539 ▶ die( "Unsupported operator '$op'" ) if( !$allowed->{ $op } );
Branch: 1 branch
BranchTrueFalseTotal
unless $allowed->{$op} 0 539 539
351  
352 # my $other_val = Scalar::Util::blessed( $other ) ? $other : "\"$other\"";
353 # my $operation = $swap ? ( defined( $other_val ) ? $other_val : 'undef' ) . " ${op} \$self->{_number}" : "\$self->{_number} ${op} " . ( defined( $other_val ) ? $other_val : 'undef' );
354 539 my $left = $self->{_number};
355 539 my $right = $other;
356 539 ▶ if( Scalar::Util::blessed( $right ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (builtin::blessed($right) and ref $right and exists $right->{"_number"}) 28 511 539
Condition66%4/6
builtin::blessed($right) and ref $right and exists $right->{"_number"}
!ll&&!rl&&r
511028
builtin::blessed($right) and ref $right
!ll&&!rl&&r
511028
MC/DC33%1/3
builtin::blessed($right) and ref $right and exists $right->{"_number"}
builtin::blessed($right) ref $right exists $right->{"_number"}
Truth table50%2/4
A and B and C
A= builtin::blessed($right)B= ref $rightC= exists $right->{"_number"}
ABCresult
0XX0
10X0
1100
1111
357 ref( $right ) &&
358 exists( $right->{_number} ) )
359 {
360 28 $right = $right->{_number};
361 }
362  
363 539 ▶ my $operation = $swap ? "\$right ${op} \$left" : "\$left ${op} \$right";
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 136 403 539
364  
365 18 ▶ no warnings 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
366 18 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
367 539 local $@;
368 539 my $res = eval( $operation );
369 539 ▶ if( $@ )
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 539 539
370 {
371 0 ▶ warn( "Error with formula \"$operation\" using object $self having number '$self->{_number}': $@" )
Branch: 1 branch
BranchTrueFalseTotal
if $self->_warnings_is_enabled("Module::Generic") 0 0 0
372 if( $self->_warnings_is_enabled( 'Module::Generic' ) );
373 0 return;
374 }
375  
376 539 ▶ if( $opts->{return_object} )
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->{'return_object'}) { } 64 475 539
elsif ($opts->{'boolean'}) { } 472 3 475
377 {
378 # Here we need to die, because we are inside 'compute', which is call in overloading. We simply cannot return an error object.
379 64 ▶ $self->_load_class( 'Module::Generic::Scalar' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Scalar") or die "Unable to load Module::Generic::Scalar" 64 0 64
380 die( "Unable to load Module::Generic::Scalar" );
381 64 ▶ return( Module::Generic::Scalar->new( $res ) ) if( $opts->{type} eq 'scalar' );
Branch: 1 branch
BranchTrueFalseTotal
if $opts->{"type"} eq "scalar" 2 62 64
382 62 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 5 57 62
383 57 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 4 53 57
384 # undef may be returned for example on platform supporting NaN when using <=>
385 53 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 53 53
386 # If the operator is a self-assignent, then we modifie our own object, and return it
387 # 1) because there is no need to create a new object; and
388 # 2) because the user might expect the returned object to be the same (i.e. same even using Scalar::Util::refaddr) as the one before the operation
389 53 ▶ if( $op =~ /=$/ )
Branch: 1 branch
BranchTrueFalseTotal
if ($op =~ /=$/) { } 11 42 53
390 {
391 11 $self->{_number} = $res;
392 11 return( $self );
393 }
394 else
395 {
396 42 return( $self->clone( $res ) );
397 }
398 }
399 elsif( $opts->{boolean} )
400 {
401 # return( $res ? $self->true : $self->false );
402 472 return( $res );
403 }
404 else
405 {
406 3 return( $res );
407 }
408 }
409  
410 1 ▶sub cos { return( shift->_func( 'cos' ) ); }
Subroutine cos: called CC=1 SCAR=0.0
Pod documented
411  
412 6 ▶sub currency { return( shift->_call_formatter( 'currency', @_ ) ); }
Subroutine currency: called CC=1 SCAR=0.0
Pod documented
413  
414 11 ▶sub decimal { return( shift->_call_formatter( 'decimal', @_ ) ); }
Subroutine decimal: called CC=1 SCAR=0.0
Pod documented
415  
416 0 ▶sub decimal_fill { return( shift->_call_formatter( 'decimal_fill', @_ ) ); }
Subroutine decimal_fill: not called CC=1 SCAR=6.9
Pod documented
417  
418 0 ▶sub default { return( shift->_call_formatter( 'default', @_ ) ); }
Subroutine default: not called CC=1 SCAR=6.9
Pod documented
419  
420 0 ▶sub encoding { return( shift->_call_formatter( 'encoding', @_ ) ); }
Subroutine encoding: not called CC=1 SCAR=6.9
Pod documented
421  
422 1 ▶sub exp { return( shift->_func( 'exp' ) ); }
Subroutine exp: called CC=1 SCAR=0.0
Pod documented
423  
424 2 ▶sub floor { return( shift->_func( 'floor', { posix => 1 } ) ); }
Subroutine floor: called CC=1 SCAR=0.0
Pod documented
425  
426 6 ▶sub format { return( shift->_call_formatter( 'format', @_ ) ); }
Subroutine format: called CC=1 SCAR=0.0
Pod documented
427  
428 2 ▶sub format_binary { return( shift->_call_formatter( 'format_binary', @_ ) ); }
Subroutine format_binary: called CC=1 SCAR=0.0
Pod documented
429  
430 5 ▶sub format_bytes { return( shift->_call_formatter( 'format_bytes', @_ ) ); }
Subroutine format_bytes: called CC=1 SCAR=0.0
Pod documented
431  
432 2 ▶sub format_hex { return( shift->_call_formatter( 'format_hex', @_ ) ); }
Subroutine format_hex: called CC=1 SCAR=0.0
Pod documented
433  
434 4 ▶sub format_money { return( shift->_call_formatter( 'format_money', @_ ) ); }
Subroutine format_money: called CC=1 SCAR=0.0
Pod documented
435  
436 1 ▶sub format_negative { return( shift->_call_formatter( 'format_negative', @_ ) ); }
Subroutine format_negative: called CC=1 SCAR=0.0
Pod documented
437  
438 0 ▶sub format_picture { return( shift->_call_formatter( 'format_picture', @_ ) ); }
Subroutine format_picture: not called CC=1 SCAR=6.9
Pod documented
439  
440 # <https://stackoverflow.com/a/483708/4814971>
441 sub from_binary
442 1 ▶{
Subroutine from_binary: called CC=8 SCAR=24.4
Pod documented
443 1 my $self = shift( @_ );
444 1 my $binary = shift( @_ );
445 1 ▶ return( $self->error( 'from_binary() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
446 1 ▶ return( $self->error( "No binary value was provided to instantiate a new number object." ) ) if( !defined( $binary ) || !CORE::length( $binary ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $binary and CORE::length $binary 0 1 1
Condition33%1/3
defined $binary and CORE::length $binary
!ll&&!rl&&r
001
MC/DC0%0/2
defined $binary and CORE::length $binary
defined $binary CORE::length $binary
Truth table33%1/3
A and B
A= defined $binaryB= CORE::length $binary
ABresult
0X0
100
111
447 # Nice trick to convert from binary to decimal. See perlfunc -> oct
448 1 my $res = CORE::oct( "0b${binary}" );
449 1 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 1 1
450 # try-catch
451 1 local $@;
452 my $rv = eval
453 1 {
454 1 $self->clone( $res );
455 };
456 1 ▶ if( $@ )
Branch: 2 branches
BranchTrueFalseTotal
if ($@) { } 0 1 1
elsif (not defined $rv and $self->error) { } 0 2 2
457 {
458 0 return( $self->error( "Error while getting number from binary value \"$binary\": $@" ) );
459 }
460 ▶ elsif( !defined( $rv ) && $self->error )
Condition33%1/3
not defined $rv and $self->error
!ll&&!rl&&r
100
MC/DC0%0/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table33%1/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
461 {
462 0 return( $self->pass_error );
463 }
464 1 return( $rv );
465 }
466  
467 sub from_hex
468 1 ▶{
Subroutine from_hex: called CC=5 SCAR=17.5
Pod documented
469 1 my $self = shift( @_ );
470 1 my $hex = shift( @_ );
471 1 ▶ return( $self->error( 'from_hex() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
472 1 ▶ return( $self->error( "No hex value was provided to instantiate a new number object." ) ) if( !defined( $hex ) || !CORE::length( $hex ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $hex and CORE::length $hex 0 1 1
Condition33%1/3
defined $hex and CORE::length $hex
!ll&&!rl&&r
001
MC/DC0%0/2
defined $hex and CORE::length $hex
defined $hex CORE::length $hex
Truth table33%1/3
A and B
A= defined $hexB= CORE::length $hex
ABresult
0X0
100
111
473 1 my $res = CORE::hex( $hex );
474 # hex() actually does not return undef
475 1 ▶ return( $self->error( "Error while getting number from hexadecimal value \"$hex\": $!" ) ) if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 1 1
476 # No need to explicitly call clear_error() here, because clone() does it for us.
477 1 return( $self->clone( $res ) );
478 }
479  
480 0 ▶sub gibi_suffix { return( shift->_call_formatter( 'gibi_suffix', @_ ) ); }
Subroutine gibi_suffix: not called CC=1 SCAR=6.9
Pod documented
481  
482 0 ▶sub giga_suffix { return( shift->_call_formatter( 'giga_suffix', @_ ) ); }
Subroutine giga_suffix: not called CC=1 SCAR=6.9
Pod documented
483  
484 7 ▶sub grouping { return( shift->_call_formatter( 'grouping', @_ ) ); }
Subroutine grouping: called CC=1 SCAR=0.0
Pod documented
485  
486 1 ▶sub int { return( shift->_func( 'int' ) ); }
Subroutine int: called CC=1 SCAR=0.0
Pod documented
487  
488 {
489 18 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
490 18 *is_decimal = \&is_float;
491 }
492  
493 sub is_decimal { return( ( shift->{_number} % 1 ) != 0 ); }
494  
495 0 ▶sub is_empty { return( CORE::length( shift->{_number} ) == 0 ); }
Subroutine is_empty: not called CC=1 SCAR=6.9
Pod documented
496  
497 0 ▶sub is_even { return( !( shift->{_number} % 2 ) ); }
Subroutine is_even: not called CC=1 SCAR=6.9
Pod documented
498  
499 1 ▶sub is_finite { return( isfinite( shift->{_number} ) ? 1 : 0 ); }
Subroutine is_finite: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
isfinite(+(shift())->{'_number'}) ? : 1 0 1
500  
501 1 ▶sub is_float { return( (POSIX::modf( shift->{_number} ))[0] != 0 ); }
Subroutine is_float: called CC=1 SCAR=0.0
Pod documented
502  
503 0 ▶sub is_infinite { return( isinf( shift->{_number} ) ? 1 : 0 ); }
Subroutine is_infinite: not called CC=2 SCAR=17.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
isinf(+(shift())->{'_number'}) ? : 0 0 0
504  
505 1 ▶sub is_int { return( (POSIX::modf( shift->{_number} ))[0] == 0 ); }
Subroutine is_int: called CC=1 SCAR=0.0
Pod documented
506  
507 1 ▶sub is_nan { return( isnan( shift->{_number} ) ); }
Subroutine is_nan: called CC=1 SCAR=0.0
Pod documented
508  
509 {
510 18 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
511 18 *is_neg = \&is_negative;
512 }
513  
514 4 ▶sub is_negative { return( signbit( shift->{_number} ) != 0 ? 1 : 0 ); }
Subroutine is_negative: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
signbit(+(shift())->{'_number'}) != 0 ? : 2 2 4
515  
516 1 ▶sub is_normal { return( isnormal( shift->{_number} ) ? 1 : 0 ); }
Subroutine is_normal: called CC=2 SCAR=7.6
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
isnormal(+(shift())->{'_number'}) ? : 1 0 1
517  
518 0 ▶sub is_odd { return( shift->{_number} % 2 ); }
Subroutine is_odd: not called CC=1 SCAR=6.9
Pod documented
519  
520 {
521 18 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
522 18 *is_pos = \&is_positive;
523 }
524  
525 4 ▶sub is_positive { return( signbit( shift->{_number} ) == 0 ? 1 : 0 ); }
Subroutine is_positive: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
signbit(+(shift())->{'_number'}) == 0 ? : 3 1 4
526  
527 0 ▶sub kibi_suffix { return( shift->_call_formatter( 'kibi_suffix', @_ ) ); }
Subroutine kibi_suffix: not called CC=1 SCAR=6.9
Pod documented
528  
529 0 ▶sub kilo_suffix { return( shift->_call_formatter( 'kilo_suffix', @_ ) ); }
Subroutine kilo_suffix: not called CC=1 SCAR=6.9
Pod documented
530  
531 0 ▶sub lang { return( shift->locale( @_ ) ); }
Subroutine lang: not called CC=1 SCAR=6.9
Pod documented
532  
533 1 ▶sub length { return( $_[0]->clone( CORE::length( $_[0]->{_number} ) ) ); }
Subroutine length: called CC=1 SCAR=0.0
Pod documented
534  
535 15 ▶sub locale { return( shift->_set_get_scalar_as_object(
Subroutine locale: called CC=1 SCAR=2.6
Pod documented
536 {
537 field => 'locale',
538 callbacks =>
539 {
540 get => sub
541 15 ▶ {
Subroutine __ANON__: called CC=2 SCAR=6.9
542 15 my( $self ) = @_;
543 15 ▶ if( $self->{_formatter} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"_formatter"}) 2 13 15
544 {
545 2 return( $self->{_formatter}->locale );
546 }
547 13 return( $self->{locale} );
548 },
549 set => sub
550 0 ▶ {
Subroutine __ANON__: not called CC=4 SCAR=30.0
551 0 my( $self, $locale ) = @_;
552 0 ( $locale, my $locale_enc ) = split( /\./, $locale, 2 );
553 0 $locale =~ tr/-/_/;
554 0 ▶ $locale = join( '.', $locale, $locale_enc ) if( defined( $locale_enc ) );
Branch: 1 branch
BranchTrueFalseTotal
if defined $locale_enc 0 0 0
555 # If we have a formatter, we pass along the locale value.
556 0 ▶ if( defined( $locale ) && $self->{_formatter} )
Branch: 1 branch
BranchTrueFalseTotal
if (defined $locale and $self->{"_formatter"}) 0 0 0
Condition0%0/3
defined $locale and $self->{"_formatter"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $locale and $self->{"_formatter"}
defined $locale $self->{"_formatter"}
Truth table0%0/3
A and B
A= defined $localeB= $self->{"_formatter"}
ABresult
0X0
100
111
557 {
558 0 $self->{_formatter}->set_locale( $locale );
559 }
560 0 return( $locale );
561 },
562 }
563 15 }, @_ ) ); }
564  
565 1 ▶sub log { return( shift->_func( 'log' ) ); }
Subroutine log: called CC=1 SCAR=0.0
Pod documented
566  
567 sub log2
568 1 ▶{
Subroutine log2: called CC=6 SCAR=29.1
Pod documented
569 1 my $self = shift( @_ );
570 1 ▶ return( $self->error( 'log2() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 1 1
571 1 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 1 0 1
572 {
573 1 return( $self->_func( 'log2', { posix => 1 } ) );
574 }
575 else
576 {
577 0 my $n = $self->{_number};
578 0 my $res = ( CORE::log( $n ) / CORE::log(2) );
579 0 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
580 0 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 0 0 0
581 0 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 0 0 0
582 0 return( $self->clone( $res ) );
583 }
584 }
585  
586 1 ▶sub log10 { return( shift->_func( 'log10', { posix => 1 } ) ); }
Subroutine log10: called CC=1 SCAR=0.0
Pod documented
587  
588 sub max
589 3 ▶{
Subroutine max: called CC=9 SCAR=38.4
Pod documented
590 3 my $self = shift( @_ );
591 3 my $other = shift( @_ );
592 3 ▶ return( $self->error( 'max() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 3 3
593 3 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 3 0 3
594 {
595 3 return( $self->_func( 'fmax', $other, { posix => 1 } ) );
596 }
597 else
598 {
599 0 my $n = $self->{_number};
600 # fmax: if one is NaN, return the other; otherwise the larger.
601 # We don't fully replicate IEEE NaN semantics here, just the common case.
602 0 my $res;
603 0 ▶ if( isnan( $n ) ) { $res = $other; }
Branch: 2 branches
BranchTrueFalseTotal
if (isnan($n)) { } 0 0 0
elsif (isnan($other)) { } 0 0 0
604 0 elsif( isnan( $other ) ) { $res = $n; }
605 0 ▶ else { $res = $n > $other ? $n : $other; }
Branch: 1 branch
BranchTrueFalseTotal
$n > $other ? : 0 0 0
606 0 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
607 0 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 0 0 0
608 0 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 0 0 0
609 # No need to explicitly call clear_error() here, because clone() does it for us.
610 0 return( $self->clone( $res ) );
611 }
612 }
613  
614 0 ▶sub mebi_suffix { return( shift->_call_formatter( 'mebi_suffix', @_ ) ); }
Subroutine mebi_suffix: not called CC=1 SCAR=6.9
Pod documented
615  
616 0 ▶sub mega_suffix { return( shift->_call_formatter( 'mega_suffix', @_ ) ); }
Subroutine mega_suffix: not called CC=1 SCAR=6.9
Pod documented
617  
618 sub min
619 2 ▶{
Subroutine min: called CC=9 SCAR=38.4
Pod documented
620 2 my $self = shift( @_ );
621 2 my $other = shift( @_ );
622 2 ▶ return( $self->error( 'min() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 2 2
623 2 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 2 0 2
624 {
625 2 return( $self->_func( 'fmin', $other, { posix => 1 } ) );
626 }
627 else
628 {
629 0 my $n = $self->{_number};
630 0 my $res;
631 0 ▶ if( isnan( $n ) ) { $res = $other; }
Branch: 2 branches
BranchTrueFalseTotal
if (isnan($n)) { } 0 0 0
elsif (isnan($other)) { } 0 0 0
632 0 elsif( isnan( $other ) ) { $res = $n; }
633 0 ▶ else { $res = $n < $other ? $n : $other; }
Branch: 1 branch
BranchTrueFalseTotal
$n < $other ? : 0 0 0
634 0 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
635 0 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 0 0 0
636 0 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 0 0 0
637 # No need to explicitly call clear_error() here, because clone() does it for us.
638 0 return( $self->clone( $res ) );
639 }
640 }
641  
642 1 ▶sub mod { return( shift->_func( 'fmod', @_, { posix => 1 } ) ); }
Subroutine mod: called CC=1 SCAR=0.0
Pod documented
643  
644 5 ▶sub mon_decimal { return( shift->_call_formatter( 'mon_decimal', @_ ) ); }
Subroutine mon_decimal: called CC=1 SCAR=0.0
Pod documented
645  
646 5 ▶sub mon_grouping { return( shift->_call_formatter( 'mon_grouping', @_ ) ); }
Subroutine mon_grouping: called CC=1 SCAR=0.0
Pod documented
647  
648 5 ▶sub mon_thousand { return( shift->_call_formatter( 'mon_thousand', @_ ) ); }
Subroutine mon_thousand: called CC=1 SCAR=0.0
Pod documented
649  
650 0 ▶sub neg_format { return( shift->_call_formatter( 'neg_format', @_ ) ); }
Subroutine neg_format: not called CC=1 SCAR=6.9
Pod documented
651  
652 1 ▶sub oct { return( shift->_func( 'oct' ) ); }
Subroutine oct: called CC=1 SCAR=0.0
Pod documented
653  
654 1 ▶sub posix_strict { return( shift->_call_formatter( 'posix_strict', @_ ) ); }
Subroutine posix_strict: called CC=1 SCAR=0.0
Pod documented
655  
656 0 ▶sub position_neg { return( shift->_call_formatter( 'position_neg', @_ ) ); }
Subroutine position_neg: not called CC=1 SCAR=6.9
Pod documented
657  
658 0 ▶sub position_pos { return( shift->_call_formatter( 'position_pos', @_ ) ); }
Subroutine position_pos: not called CC=1 SCAR=6.9
Pod documented
659  
660 0 ▶sub pow { return( shift->_func( 'pow', @_, { posix => 1 } ) ); }
Subroutine pow: not called CC=1 SCAR=6.9
Pod documented
661  
662 4 ▶sub precede { return( shift->_call_formatter( 'precede', @_ ) ); }
Subroutine precede: called CC=1 SCAR=0.0
Pod documented
663  
664 0 ▶sub precede_neg { return( shift->_call_formatter( 'precede_neg', @_ ) ); }
Subroutine precede_neg: not called CC=1 SCAR=6.9
Pod documented
665  
666 0 ▶sub precede_pos { return( shift->_call_formatter( 'precede_pos', @_ ) ); }
Subroutine precede_pos: not called CC=1 SCAR=6.9
Pod documented
667  
668 19 ▶sub precision { return( shift->_call_formatter( 'precision', @_ ) ); }
Subroutine precision: called CC=1 SCAR=0.0
Pod documented
669  
670 0 ▶sub rand { return( shift->_func( 'rand' ) ); }
Subroutine rand: not called CC=1 SCAR=6.9
Pod documented
671  
672 0 ▶sub real { return( shift->{_number} ); }
Subroutine real: not called CC=1 SCAR=6.9
Pod documented
673  
674 3 ▶sub round { return( shift->_call_formatter_and_replace( 'round', @_ ) ); }
Subroutine round: called CC=1 SCAR=0.0
Pod documented
675  
676 2 ▶sub round_zero { return( shift->_call_formatter_and_replace( 'round_zero', @_ ) ); }
Subroutine round_zero: called CC=1 SCAR=0.0
Pod documented
677  
678 1 ▶sub round2 { return( shift->_call_formatter_and_replace( 'round2', @_ ) ); }
Subroutine round2: called CC=1 SCAR=0.0
Pod documented
679  
680 7 ▶sub scalar { return( shift->as_string ); }
Subroutine scalar: called CC=1 SCAR=0.0
Pod documented
681  
682 0 ▶sub sign_neg { return( shift->_call_formatter( 'sign_neg', @_ ) ); }
Subroutine sign_neg: not called CC=1 SCAR=6.9
Pod documented
683  
684 0 ▶sub sign_pos { return( shift->_call_formatter( 'sign_pos', @_ ) ); }
Subroutine sign_pos: not called CC=1 SCAR=6.9
Pod documented
685  
686 0 ▶sub space_neg { return( shift->_call_formatter( 'space_neg', @_ ) ); }
Subroutine space_neg: not called CC=1 SCAR=6.9
Pod documented
687  
688 3 ▶sub space_pos { return( shift->_call_formatter( 'space_pos', @_ ) ); }
Subroutine space_pos: called CC=1 SCAR=0.0
Pod documented
689  
690 1 ▶sub sin { return( shift->_func( 'sin' ) ); }
Subroutine sin: called CC=1 SCAR=0.0
Pod documented
691  
692 {
693 18 ▶ no warnings 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
694 18 *space = \&space_pos;
695 }
696  
697 1 ▶sub sqrt { return( shift->_func( 'sqrt' ) ); }
Subroutine sqrt: called CC=1 SCAR=0.0
Pod documented
698  
699 1 ▶sub symbol { return( shift->_call_formatter( 'symbol', @_ ) ); }
Subroutine symbol: called CC=1 SCAR=0.0
Pod documented
700  
701 1 ▶sub tan { return( shift->_func( 'tan', { posix => 1 } ) ); }
Subroutine tan: called CC=1 SCAR=0.0
Pod documented
702  
703 6 ▶sub thousand { return( shift->_call_formatter( 'thousand', @_ ) ); }
Subroutine thousand: called CC=1 SCAR=0.0
Pod documented
704  
705 sub unformat
706 2 ▶{
Subroutine unformat: called CC=5 SCAR=16.9
Pod documented
707 2 my $self = shift( @_ );
708 2 my $num = shift( @_ );
709 2 ▶ return( $self->error( 'unformat() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 2 2
710 2 ▶ my $fmt = $self->_get_formatter || return( $self->pass_error );
Condition50%1/2
$self->_get_formatter || (return $self->pass_error)
l!l
20
MC/DC0%0/1
$self->_get_formatter || (return $self->pass_error)
$self->_get_formatter
Truth table50%1/2
A
A= $self->_get_formatter
Aresult
11
00
711 # Module::Generic::Number::Format->unformat returns a raw number
712 2 my $num2 = $fmt->unformat( $num );
713 2 ▶ if( !defined( $num2 ) && $fmt->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $num2 and $fmt->error) 0 2 2
Condition33%1/3
not defined $num2 and $fmt->error
!ll&&!rl&&r
200
MC/DC0%0/2
not defined $num2 and $fmt->error
not defined $num2 $fmt->error
Truth table33%1/3
not(A) and B
A= not defined $num2B= $fmt->error
ABresult
0X0
100
111
714 {
715 0 return( $self->pass_error( $fmt->error ) );
716 }
717 2 my $clone = $self->clone;
718 2 $clone->{_original} = $num;
719 2 $clone->{_number} = $num2;
720 # We keep whatever parameters we have for the previous value, we clone the formatter with the new value.
721 2 $clone->{_formatter} = $fmt->clone( $num2 );
722 2 $clone->debug( $self->debug );
723 2 $clone->clear_error;
724 2 return( $clone );
725 }
726  
727 # Returns a scalar
728 sub _call_formatter
729 99 ▶{
Subroutine _call_formatter: called CC=12 SCAR=27.0
730 99 my $self = shift( @_ );
731 99 ▶ my $meth = shift( @_ ) ||
Condition50%1/2
shift @_ || (return $self->error('No Module::Generic::Number::Format method name was provided.'))
l!l
990
MC/DC0%0/1
shift @_ || (return $self->error('No Module::Generic::Number::Format method name was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
732 return( $self->error( "No Module::Generic::Number::Format method name was provided." ) );
733 99 my @args = @_;
734 99 ▶ my $fmt = $self->_get_formatter || return( $self->pass_error );
Condition50%1/2
$self->_get_formatter || (return $self->pass_error)
l!l
990
MC/DC0%0/1
$self->_get_formatter || (return $self->pass_error)
$self->_get_formatter
Truth table50%1/2
A
A= $self->_get_formatter
Aresult
11
00
735 99 my $code = $fmt->can( $meth );
736 99 ▶ unless( defined( $code ) && ref( $code ) eq 'CODE' )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $code and ref $code eq "CODE") 0 99 99
Condition33%1/3
defined $code and ref $code eq "CODE"
!ll&&!rl&&r
0099
MC/DC0%0/2
defined $code and ref $code eq "CODE"
defined $code ref $code eq "CODE"
Truth table33%1/3
A and B
A= defined $codeB= ref $code eq "CODE"
ABresult
0X0
100
111
737 {
738 0 return( $self->error( "The method \"$meth\" is not supported by Module::Generic::Number::Format" ) );
739 }
740 99 my @rv;
741 99 ▶ if( wantarray() )
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) { } 2 97 99
742 {
743 # @rv = $fmt->$meth( scalar( @args ) ? @args : () );
744 2 ▶ @rv = $code->( $fmt, scalar( @args ) ? @args : () );
Branch: 1 branch
BranchTrueFalseTotal
scalar @args ? : 0 2 2
745 2 ▶ if( !scalar( @rv ) && $fmt->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not scalar @rv and $fmt->error) 0 2 2
Condition33%1/3
not scalar @rv and $fmt->error
!ll&&!rl&&r
200
MC/DC0%0/2
not scalar @rv and $fmt->error
not scalar @rv $fmt->error
Truth table33%1/3
not(A) and B
A= not scalar @rvB= $fmt->error
ABresult
0X0
100
111
746 {
747 0 return( $self->pass_error( $fmt->error ) );
748 }
749 2 $self->clear_error;
750 2 return( @rv );
751 }
752 else
753 {
754 # $rv[0] = $fmt->$meth( scalar( @args ) ? @args : () );
755 97 ▶ $rv[0] = $code->( $fmt, scalar( @args ) ? @args : () );
Branch: 1 branch
BranchTrueFalseTotal
scalar @args ? : 58 39 97
756 97 ▶ if( !defined( $rv[0] ) && $fmt->error )
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $rv[0] and $fmt->error) 1 96 97
Condition66%2/3
not defined $rv[0] and $fmt->error
!ll&&!rl&&r
9601
MC/DC50%1/2
not defined $rv[0] and $fmt->error
not defined $rv[0] $fmt->error
Truth table66%2/3
not(A) and B
A= not defined $rv[0]B= $fmt->error
ABresult
0X0
100
111
757 {
758 1 return( $self->pass_error( $fmt->error ) );
759 }
760 96 $self->clear_error;
761 # Whether we are called in void context or not, this is the same.
762 96 return( $rv[0] );
763 }
764 }
765  
766 # Same as _call_formatter, except we clone ourself and use the output as the new number value.
767 sub _call_formatter_and_replace
768 6 ▶{
Subroutine _call_formatter_and_replace: called CC=3 SCAR=11.0
769 6 my $self = shift( @_ );
770 # Module::Generic::Number::Format returns a scalar, always.
771 6 my $rv = $self->_call_formatter( @_ );
772 6 ▶ return( $self->pass_error ) if( !defined( $rv ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $rv and $self->error 1 5 6
Condition66%2/3
not defined $rv and $self->error
!ll&&!rl&&r
501
MC/DC50%1/2
not defined $rv and $self->error
not defined $rv $self->error
Truth table66%2/3
not(A) and B
A= not defined $rvB= $self->error
ABresult
0X0
100
111
773 # Keep the formatter, but with the new value.
774 5 my $fmt = $self->_get_formatter->clone( $rv );
775 5 my $clone = $self->clone( $rv );
776 5 $clone->{_formatter} = $fmt;
777 5 return( $clone );
778 }
779  
780 sub _func
781 20 ▶{
Subroutine _func: called CC=11 SCAR=24.3
782 20 my $self = shift( @_ );
783 20 ▶ my $func = shift( @_ ) || return( $self->error( "No function was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No function was provided.'))
l!l
200
MC/DC0%0/1
shift @_ || (return $self->error('No function was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
784 20 ▶ return( $self->error( '_func() can only be called on an instance of ', __PACKAGE__ ) ) unless( $self->_is_object( $self ) );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_object($self) 0 20 20
785 20 my $opts = {};
786 18 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
787 20 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 10 10 20
788 20 ▶ my $namespace = $opts->{posix} ? 'POSIX' : 'CORE';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'posix'} ? : 10 10 20
789 20 ▶ my $val = @_ ? shift( @_ ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 16 20
790 20 ▶ my $expr = defined( $val ) ? "${namespace}::${func}( \$self->{_number}, $val )" : "${namespace}::${func}( \$self->{_number} )";
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 4 16 20
791 20 local $@;
792 # Should we avoid warnings?
793 18 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
794 20 my $res = eval( $expr );
795 20 ▶ return( $self->error( $@ ) ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 20 20
796 20 $self->clear_error;
797 20 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 20 20
798 20 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 0 20 20
799 20 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 0 20 20
800 20 return( $self->clone( $res ) );
801 }
802  
803 sub _get_formatter
804 106 ▶{
Subroutine _get_formatter: called CC=4 SCAR=14.2
805 106 my $self = shift( @_ );
806 106 my $fmt = $self->{_formatter};
807 106 ▶ if( $self->_is_a( $fmt => 'Module::Generic::Number::Format' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_a($fmt, 'Module::Generic::Number::Format')) { } 93 13 106
808 {
809 # We already have a formatter object set
810 }
811 else
812 {
813 13 $fmt = $self->_instantiate_format;
814 13 ▶ return( $self->pass_error ) if( !defined( $fmt ) && $self->error );
Branch: 1 branch
BranchTrueFalseTotal
if not defined $fmt and $self->error 0 13 13
Condition33%1/3
not defined $fmt and $self->error
!ll&&!rl&&r
1300
MC/DC0%0/2
not defined $fmt and $self->error
not defined $fmt $self->error
Truth table33%1/3
not(A) and B
A= not defined $fmtB= $self->error
ABresult
0X0
100
111
815 13 $self->{_formatter} = $fmt;
816 }
817 106 return( $fmt );
818 }
819  
820 sub _instantiate_format
821 13 ▶{
Subroutine _instantiate_format: called CC=14 SCAR=34.9
822 13 my $self = shift( @_ );
823 13 ▶ if( !ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $self) 0 13 13
824 {
825 0 return( $self->error( "_instantiate_format() must be called on an object." ) );
826 }
827 13 my $opts = $self->_get_args_as_hash( @_ );
828 # effectively same as $self->{_number}
829 # my $num = $self->as_number;
830 13 my $num = $self->{_number};
831 13 my $locale = $self->locale;
832 13 my $debug = $self->debug;
833 13 ▶ $opts->{debug} = $debug if( $debug && !CORE::exists( $opts->{debug} ) );
Branch: 1 branch
BranchTrueFalseTotal
if $debug and not exists $opts->{"debug"} 0 13 13
Condition33%1/3
$debug and not exists $opts->{"debug"}
!ll&&!rl&&r
1300
MC/DC0%0/2
$debug and not exists $opts->{"debug"}
$debug not exists $opts->{"debug"}
Truth table33%1/3
A and not(B)
A= $debugB= not exists $opts->{"debug"}
ABresult
0X0
100
111
834 # The option 'locale' or 'lang' are interchangeable, because they point to the same method
835 13 ▶ if( !CORE::exists( $opts->{locale} ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $opts->{"locale"} || exists $opts->{"lang"} and defined $locale and CORE::length($locale // "")) 0 13 13
Condition36%4/11
not exists $opts->{"locale"} || exists $opts->{"lang"} and defined $locale and CORE::length($locale // "")
!ll&&!rl&&r
0130
not exists $opts->{"locale"} || exists $opts->{"lang"} and defined $locale
!ll&&!rl&&r
0013
exists $opts->{'locale'} || exists $opts->{'lang'}
l!l&&r!l&&!r
0013
$locale // ""
l!l
130
MC/DC0%0/4
not exists $opts->{"locale"} || exists $opts->{"lang"} and defined $locale and CORE::length($locale // "")
exists $opts->{'locale'} exists $opts->{'lang'} defined $locale $locale
Truth table20%1/5
not(A || B) and C and D
A= exists $opts->{'locale'}B= exists $opts->{'lang'}C= defined $localeD= $locale
ABCDresult
1XXX0
01XX0
000X0
00100
00111
836 !CORE::exists( $opts->{lang} ) &&
837 defined( $locale ) &&
838 CORE::length( $locale // '' ) )
839 {
840 0 $opts->{locale} = $locale;
841 }
842 13 ▶ if( !defined( $num ) || !CORE::length( $num // '' ) )
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $num and CORE::length($num // "")) 0 13 13
Condition40%2/5
defined $num and CORE::length($num // "")
!ll&&!rl&&r
0013
$num // ""
l!l
130
MC/DC0%0/2
defined $num and CORE::length($num // "")
defined $num $num
Truth table33%1/3
A and B
A= defined $numB= $num
ABresult
0X0
100
111
843 {
844 0 return( $self->error( "No number is currently defined on our instance. A number is required to instantiate a number formatter." ) );
845 }
846 13 ▶ $self->_load_class( 'Module::Generic::Number::Format' ) ||
Branch: 1 branch
BranchTrueFalseTotal
$self->_load_class("Module::Generic::Number::Format") or return $self->pass_error 13 0 13
847 return( $self->pass_error );
848 13 ▶ my $fmt = Module::Generic::Number::Format->new( $num, %$opts ) ||
Condition50%1/2
'Module::Generic::Number::Format'->new($num, %$opts) || (return $self->pass_error('Module::Generic::Number::Format'->error))
l!l
130
MC/DC0%0/1
'Module::Generic::Number::Format'->new($num, %$opts) || (return $self->pass_error('Module::Generic::Number::Format'->error))
'Module::Generic::Number::Format'->new($num, %$opts)
Truth table50%1/2
A
A= 'Module::Generic::Number::Format'->new($num, %$opts)
Aresult
11
00
849 return( $self->pass_error( Module::Generic::Number::Format->error ) );
850 13 return( $fmt );
851 }
852  
853 sub FREEZE
854 5 ▶{
Subroutine FREEZE: called CC=8 SCAR=22.3
Pod undocumented
855 5 my $self = CORE::shift( @_ );
856 5 ▶ my $serialiser = CORE::shift( @_ ) // '';
Condition50%1/2
shift @_ // ""
l!l
50
MC/DC0%0/1
shift @_ // ""
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
857 5 my $class = CORE::ref( $self );
858  
859 # We keep a strict allow-list to avoid accidentally freezing DBI handles or other
860 # process-local state.
861 5 my @props = ( @{$self->{_fields}} );
862  
863 5 my $hash = {};
864 5 foreach my $prop ( @props )
865 {
866 10 ▶ if( CORE::exists( $self->{ $prop } ) &&
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE") 10 0 10
Condition33%2/6
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
!ll&&!rl&&r
0010
exists $self->{$prop} and defined $self->{$prop}
!ll&&!rl&&r
0010
MC/DC0%0/3
exists $self->{$prop} and defined $self->{$prop} and ref $self->{$prop} ne "CODE"
exists $self->{$prop} defined $self->{$prop} ref $self->{$prop} ne "CODE"
Truth table25%1/4
A and B and C
A= exists $self->{$prop}B= defined $self->{$prop}C= ref $self->{$prop} ne "CODE"
ABCresult
0XX0
10X0
1100
1111
867 defined( $self->{ $prop } ) &&
868 CORE::ref( $self->{ $prop } ) ne 'CODE' )
869 {
870 10 $hash->{ $prop } = $self->{ $prop };
871 }
872 }
873  
874 # Return an array reference rather than a list so this works with Sereal and CBOR.
875 # On or before Sereal version 4.023, Sereal did not support multiple values returned.
876 5 ▶ if( $serialiser eq 'Sereal' )
Branch: 1 branch
BranchTrueFalseTotal
if ($serialiser eq "Sereal") 2 3 5
877 {
878 2 require Sereal::Encoder;
879 2 require version;
880  
881 2 ▶ if( version->parse( Sereal::Encoder->VERSION ) <= version->parse( '4.023' ) )
Branch: 1 branch
BranchTrueFalseTotal
if ("version"->parse("Sereal::Encoder"->VERSION) <= "version"->parse("4.023")) 0 2 2
882 {
883 0 CORE::return( [$class, $hash] );
884 }
885 }
886  
887 # But Storable wants a list with the first element being the serialised element
888 5 CORE::return( $class, $hash );
889 }
890  
891 3 ▶sub STORABLE_freeze { CORE::return( CORE::shift->FREEZE( @_ ) ); }
Subroutine STORABLE_freeze: called CC=1 SCAR=0.0
Pod undocumented
892  
893 3 ▶sub STORABLE_thaw { CORE::return( CORE::shift->THAW( @_ ) ); }
Subroutine STORABLE_thaw: called CC=1 SCAR=0.0
Pod undocumented
894  
895 # NOTE: CBOR will call the THAW method with the stored classname as first argument, the constant string CBOR as second argument, and all values returned by FREEZE as remaining arguments.
896 # NOTE: Storable calls it with a blessed object it created followed with $cloning and any other arguments initially provided by STORABLE_freeze
897 sub THAW
898 5 ▶{
Subroutine THAW: called CC=10 SCAR=27.6
Pod undocumented
899 5 my( $self, undef, @args ) = @_;
900 5 ▶ my $ref = ( CORE::scalar( @args ) == 1 && CORE::ref( $args[0] ) eq 'ARRAY' ) ? CORE::shift( @args ) : \@args;
Branch: 1 branch
BranchTrueFalseTotal
scalar @args == 1 && ref $args[0] eq 'ARRAY' ? : 0 5 5
Condition33%1/3
scalar @args == 1 and ref $args[0] eq "ARRAY"
!ll&&!rl&&r
500
MC/DC0%0/2
scalar @args == 1 and ref $args[0] eq "ARRAY"
scalar @args == 1 ref $args[0] eq "ARRAY"
Truth table33%1/3
A and B
A= scalar @args == 1B= ref $args[0] eq "ARRAY"
ABresult
0X0
100
111
901 5 ▶ my $class = ( CORE::defined( $ref ) && CORE::ref( $ref ) eq 'ARRAY' && CORE::scalar( @$ref ) > 1 ) ? CORE::shift( @$ref ) : ( CORE::ref( $self ) || $self );
Branch: 1 branch
BranchTrueFalseTotal
defined $ref && ref $ref eq 'ARRAY' && scalar @$ref > 1 ? : 5 0 5
Condition22%2/9
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
!ll&&!rl&&r
005
defined $ref and ref $ref eq "ARRAY"
!ll&&!rl&&r
005
ref $self or $self
l!l&&r!l&&!r
000
MC/DC0%0/3
defined $ref and ref $ref eq "ARRAY" and scalar @$ref > 1
defined $ref ref $ref eq "ARRAY" scalar @$ref > 1
MC/DC0%0/2
ref $self or $self
ref $self $self
Truth table25%1/4
A and B and C
A= defined $refB= ref $ref eq "ARRAY"C= scalar @$ref > 1
ABCresult
0XX0
10X0
1100
1111
Truth table0%0/3
A or B
A= ref $selfB= $self
ABresult
1X1
011
000
902 5 ▶ my $hash = CORE::ref( $ref ) eq 'ARRAY' ? CORE::shift( @$ref ) : {};
Branch: 1 branch
BranchTrueFalseTotal
ref $ref eq 'ARRAY' ? : 5 0 5
903 5 my $new;
904 # Storable pattern requires to modify the object it created rather than returning a new one
905 5 ▶ if( CORE::ref( $self ) )
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) { } 3 2 5
906 {
907 3 foreach( CORE::keys( %$hash ) )
908 {
909 6 $self->{ $_ } = CORE::delete( $hash->{ $_ } );
910 }
911 3 $new = $self;
912 }
913 else
914 {
915 2 $new = CORE::bless( $hash => $class );
916 }
917 5 CORE::return( $new );
918 }
919  
920 0 ▶sub TO_JSON { return( shift->as_number ); }
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod documented
921  
922 # NOTE: package Module::Generic::NumberSpecial
923 package Module::Generic::NumberSpecial;
924 BEGIN
925 18 ▶{
Subroutine BEGIN: called CC=2 SCAR=8.4
926 18 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
927 18 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
928 18 ▶ use parent -norequire, qw( Module::Generic::Number );
Subroutine BEGIN: called CC=1 SCAR=0.0
929 18 ▶ use vars qw( $POS_INF $NEG_INF );
Subroutine BEGIN: called CC=1 SCAR=0.0
930 0 ▶ use overload ('""' => sub{ $_[0]->{_number} },
Subroutine BEGIN: called CC=1 SCAR=3.1
Subroutine __ANON__: not called CC=1 SCAR=6.9
931 0 ▶ '+=' => sub{ &_catchall( @_[0..2], '+' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
932 0 ▶ '-=' => sub{ &_catchall( @_[0..2], '-' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
933 1 ▶ '*=' => sub{ &_catchall( @_[0..2], '*' ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
934 0 ▶ '/=' => sub{ &_catchall( @_[0..2], '/' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
935 0 ▶ '%=' => sub{ &_catchall( @_[0..2], '%' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
936 0 ▶ '**=' => sub{ &_catchall( @_[0..2], '**' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
937 0 ▶ '<<=' => sub{ &_catchall( @_[0..2], '<<' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
938 0 ▶ '>>=' => sub{ &_catchall( @_[0..2], '>>' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
939 0 ▶ 'x=' => sub{ &_catchall( @_[0..2], 'x' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
940 0 ▶ '.=' => sub{ &_catchall( @_[0..2], '.' ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
941 18 nomethod => \&_catchall,
942 fallback => 1,
943 18 );
944 18 $POS_INF = 9**9**9;
945 18 $NEG_INF = -$POS_INF;
946 18 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 18 0 18
947 {
948 18 require POSIX;
949 18 POSIX->import( qw( isinf isnan ) );
950 }
951 else
952 {
953 *isinf = sub
954 0 ▶ {
Subroutine __ANON__: not called CC=3 SCAR=18.1
955 0 ▶ return(0) if( !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
956 18 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
957 0 ▶ return( $_[0] == $POS_INF || $_[0] == $NEG_INF );
Condition0%0/3
$_[0] == $Module::Generic::NumberSpecial::POS_INF || $_[0] == $Module::Generic::NumberSpecial::NEG_INF
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0] == $Module::Generic::NumberSpecial::POS_INF || $_[0] == $Module::Generic::NumberSpecial::NEG_INF
$_[0] == $Module::Generic::NumberSpecial::POS_INF $_[0] == $Module::Generic::NumberSpecial::NEG_INF
Truth table0%0/3
A || B
A= $_[0] == $Module::Generic::NumberSpecial::POS_INFB= $_[0] == $Module::Generic::NumberSpecial::NEG_INF
ABresult
1X1
011
000
958 0 };
959 *isnan = sub
960 0 ▶ {
Subroutine __ANON__: not called CC=2 SCAR=10.1
961 0 ▶ return(0) if( !defined( $_[0] ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $_[0] 0 0 0
962 18 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
963 0 return( $_[0] != $_[0] );
964 0 };
965 }
966 18 ▶ use Wanted;
Subroutine BEGIN: called CC=1 SCAR=0.0
967 18 our( $VERSION ) = '0.1.0';
968 };
969  
970 sub new
971 17 ▶{
Subroutine new: called CC=9 SCAR=35.0
972 17 my $this = CORE::shift( @_ );
973 17 my $val = CORE::shift( @_ );
974 17 ▶ if( $] < 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.022") 0 17 17
975 {
976 0 my $str = "$val";
977 0 my $is_nan;
978 {
979 # Suppress numeric comparison warnings: on perl < 5.22, IEEE special values
980 # may carry a non-numeric string representation depending on the C library,
981 # and the standard NaN-detection idiom ($val != $val) will warn if $val
982 # happens to be a plain non-numeric string. The check is still semantically
983 # correct.
984 0 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.2
985 0 $is_nan = ( $val != $val );
986 }
987 # Fallback to string pattern matching (covers libc variants like:
988 # "nan", "-nan", "nan(0x...)", "1.#QNAN", "1.#IND", "nanq", etc.)
989 0 ▶ $is_nan ||= ( $str =~ /^[+-]?(?:nan|1\.\#(?:ind|qnan|snan))/i );
Condition0%0/3
$is_nan ||= $str =~ /^[+-]?(?:nan|1\.\#(?:ind|qnan|snan))/i
l!l&&r!l&&!r
000
MC/DC0%0/2
$is_nan ||= $str =~ /^[+-]?(?:nan|1\.\#(?:ind|qnan|snan))/i
$is_nan $str =~ /^[+-]?(?:nan|1\.\#(?:ind|qnan|snan))/i
Truth table0%0/3
A ||= B
A= $is_nanB= $str =~ /^[+-]?(?:nan|1\.\#(?:ind|qnan|snan))/i
ABresult
1X1
011
000
990 0 ▶ if( $is_nan )
Branch: 1 branch
BranchTrueFalseTotal
if ($is_nan) { } 0 0 0
991 {
992 0 $val = 'NaN';
993 }
994 else
995 {
996 18 ▶ no warnings 'numeric';
Subroutine BEGIN: called CC=1 SCAR=0.0
997 0 ▶ if( $val == $POS_INF )
Branch: 3 branches
BranchTrueFalseTotal
if ($val == $POS_INF) { } 0 0 0
elsif ($val == -$POS_INF) { } 0 0 0
elsif ($str =~ /^([+-]?)(?:inf(?:inity)?|1\.\#inf)/i) { } 0 0 0
998 {
999 0 $val = 'Inf';
1000 }
1001 elsif( $val == -$POS_INF )
1002 {
1003 0 $val = '-Inf';
1004 }
1005 elsif( $str =~ /^([+-]?)(?:inf(?:inity)?|1\.\#inf)/i )
1006 {
1007 0 ▶ $val = ( $1 eq '-' ) ? '-Inf' : 'Inf';
Branch: 1 branch
BranchTrueFalseTotal
$1 eq '-' ? : 0 0 0
1008 }
1009 }
1010 }
1011 17 ▶ return( bless( { _number => $val } => ( ref( $this ) || $this ) ) );
Condition66%2/3
ref $this || $this
l!l&&r!l&&!r
1160
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table66%2/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
1012 }
1013  
1014 1 ▶sub clone { return( shift->new( @_ ) ); }
Subroutine clone: called CC=1 SCAR=0.0
1015  
1016 0 ▶sub is_finite { return(0); }
Subroutine is_finite: not called CC=1 SCAR=6.9
1017  
1018 0 ▶sub is_float { return(0); }
Subroutine is_float: not called CC=1 SCAR=6.9
1019  
1020 0 ▶sub is_infinite { return(0); }
Subroutine is_infinite: not called CC=1 SCAR=6.9
1021  
1022 0 ▶sub is_int { return(0); }
Subroutine is_int: not called CC=1 SCAR=6.9
1023  
1024 0 ▶sub is_nan { return(0); }
Subroutine is_nan: not called CC=1 SCAR=6.9
1025  
1026 2 ▶sub is_normal { return(0); }
Subroutine is_normal: called CC=1 SCAR=0.0
1027  
1028 0 ▶sub length { return( CORE::length( shift->{_number} ) ); }
Subroutine length: not called CC=1 SCAR=6.9
1029  
1030 sub round_zero
1031 0 ▶{
Subroutine round_zero: not called CC=6 SCAR=37.4
1032 0 my $self = shift( @_ );
1033 0 my @args = @_;
1034 0 ▶ if( $] >= 5.022 )
Branch: 1 branch
BranchTrueFalseTotal
if ($] >= 5.022) { } 0 0 0
1035 {
1036 0 return( $self->_func( 'round', @args, { posix => 1 } ) );
1037 }
1038 else
1039 {
1040 0 my $n = $self->{_number};
1041 # round to nearest, ties away from zero (same semantics as C99 round())
1042 0 my $res;
1043 0 ▶ if( $n >= 0 )
Branch: 1 branch
BranchTrueFalseTotal
if ($n >= 0) { } 0 0 0
1044 {
1045 0 $res = CORE::int( $n + 0.5 );
1046 }
1047 else
1048 {
1049 0 $res = -CORE::int( -$n + 0.5 );
1050 }
1051 0 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 0 0
1052 0 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 0 0 0
1053 0 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 0 0 0
1054 0 return( $self->clone( $res ) );
1055 }
1056 }
1057  
1058 sub _catchall
1059 1 ▶{
Subroutine _catchall: called CC=7 SCAR=22.3
1060 1 my( $self, $other, $swap, $op ) = @_;
1061 18 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1062 1 ▶ my $expr = $swap ? "$other $op $self->{_number}" : "$self->{_number} $op $other";
Branch: 1 branch
BranchTrueFalseTotal
$swap ? : 0 1 1
1063 1 local $@;
1064 1 my $res = eval( $expr );
1065 1 ▶ CORE::warn( "Error evaluating expression \"$expr\": $@" ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
1066 1 ▶ return if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
1067 1 ▶ return( Module::Generic::Number->new( $res ) ) if( isnormal( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnormal($res) 0 1 1
1068 1 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 1 0 1
1069 0 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 0 0 0
1070 0 return( $res );
1071 }
1072  
1073 sub _func
1074 6 ▶{
Subroutine _func: called CC=11 SCAR=24.2
1075 6 my $self = shift( @_ );
1076 6 ▶ my $func = shift( @_ ) || return( $self->error( "No function was provided." ) );
Condition50%1/2
shift @_ || (return $self->error('No function was provided.'))
l!l
60
MC/DC0%0/1
shift @_ || (return $self->error('No function was provided.'))
shift @_
Truth table50%1/2
A
A= shift @_
Aresult
11
00
1077 6 my $opts = {};
1078 18 ▶ no strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1079 6 ▶ $opts = pop( @_ ) if( ref( $_[-1] ) eq 'HASH' );
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[-1] eq "HASH" 4 2 6
1080 6 ▶ my $namespace = $opts->{posix} ? 'POSIX' : 'CORE';
Branch: 1 branch
BranchTrueFalseTotal
$opts->{'posix'} ? : 4 2 6
1081 6 ▶ my $val = @_ ? shift( @_ ) : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 3 3 6
1082 6 ▶ my $expr = defined( $val ) ? "${namespace}::${func}( $self->{_number}, $val )" : "${namespace}::${func}( $self->{_number} )";
Branch: 1 branch
BranchTrueFalseTotal
defined $val ? : 3 3 6
1083 6 local $@;
1084 6 my $res = eval( $expr );
1085 6 ▶ CORE::warn( $@ ) if( $@ );
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 6 6
1086 6 ▶ return if( !defined( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $res 0 6 6
1087 # return( Module::Generic::Number->new( $res ) ) if( isnormal( $res ) );
1088 6 ▶ return( $self->clone( $res ) ) if( isnormal( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnormal($res) 0 6 6
1089 6 ▶ return( Module::Generic::Infinity->new( $res ) ) if( isinf( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isinf($res) 4 2 6
1090 2 ▶ return( Module::Generic::Nan->new( $res ) ) if( isnan( $res ) );
Branch: 1 branch
BranchTrueFalseTotal
if isnan($res) 0 2 2
1091 2 return( $res );
1092 }
1093  
1094 # NOTE: AUTOLOAD
1095 AUTOLOAD
1096 7 ▶{
Subroutine AUTOLOAD: called CC=2 SCAR=7.6
1097 7 my( $method ) = our $AUTOLOAD =~ /([^:]+)$/;
1098 # If we are chained, return our null object, so the chain continues to work
1099 7 ▶ if( want( 'OBJECT' ) )
Branch: 1 branch
BranchTrueFalseTotal
if (want("OBJECT")) 0 7 7
1100 {
1101 # No, this is NOT a typo. rreturn() is a function of module Wanted
1102 0 rreturn( $_[0] );
1103 }
1104 # Otherwise, we return infinity, whether positive or negative or NaN depending on what was set
1105 7 return( $_[0]->{_number} );
1106 };
1107  
1108 # NOTE: DESTROY
1109 0 ▶DESTROY {};
Subroutine DESTROY: not called CC=1 SCAR=0.0
1110  
1111 # NOTE: package Module::Generic::Infinity
1112 # Purpose is to allow chaining of methods when infinity is returned
1113 # At the end of the chain, Inf or -Inf is returned
1114 package Module::Generic::Infinity;
1115 BEGIN
1116 18 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
1117 18 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1118 18 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1119 18 ▶ use parent -norequire, qw( Module::Generic::NumberSpecial );
Subroutine BEGIN: called CC=1 SCAR=0.0
1120 18 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
1121 1 ▶ '""' => sub { return( $_[0]->{_number} ); },
Subroutine __ANON__: called CC=1 SCAR=0.0
1122 18 fallback => 1,
1123 18 );
1124  
1125 18 our( $VERSION ) = '0.1.0';
1126 };
1127  
1128 1 ▶sub is_infinite { return(1); }
Subroutine is_infinite: called CC=1 SCAR=0.0
1129  
1130 # NOTE: package Module::Generic::Nan
1131 package Module::Generic::Nan;
1132 BEGIN
1133 18 ▶{
Subroutine BEGIN: called CC=1 SCAR=0.0
1134 18 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
1135 18 ▶ use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
1136 18 ▶ use parent -norequire, qw( Module::Generic::NumberSpecial );
Subroutine BEGIN: called CC=1 SCAR=0.0
1137 18 ▶ use overload (
Subroutine BEGIN: called CC=1 SCAR=0.0
1138 1 ▶ '""' => sub { 'NaN' },
Subroutine __ANON__: called CC=1 SCAR=0.0
1139 18 fallback => 1,
1140 18 );
1141 18 our( $VERSION ) = '0.1.0';
1142 };
1143  
1144 1 ▶sub is_nan { return(1); }
Subroutine is_nan: called CC=1 SCAR=0.0
1145  
1146 18 1;
1147  
1148 __END__
« lib/Module/Generic/Finfo.pm ↑ Summary lib/Module/Generic/TieHash.pm »