| 1 | ### Data::Quantity::Number::Number; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | ### Change History | ||||||||||||||||||||||||||||
| 4 | # 2000-12-01 Fixed "use of undefined value" in numeric_value | ||||||||||||||||||||||||||||
| 5 | # 1999-08-02 Stripped and corrected separators in numeric_value(). | ||||||||||||||||||||||||||||
| 6 | # 1998-12-02 Created. -Simon | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | package Data::Quantity::Number::Number; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 6 | require 5; | |||||||||||||||||||||||||||
| 11 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 6 | ▶ | use vars qw( $VERSION ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 6 | $VERSION = 0.001; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | use Data::Quantity::Abstract::Base '-isasubclass'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # $clone_q = $quantity->new_instance(); | ||||||||||||||||||||||||||||
| 20 | # $empty_q = Data::Quantity::Number::Number->new_instance(); | ||||||||||||||||||||||||||||
| 21 | 53 | ▶ | sub new_instance { | ||||||||||||||||||||||||||
|
Subroutine
new_instance: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 53 | my $referent = shift; | |||||||||||||||||||||||||||
| 23 | 53 | ▶ | my $class = ref($referent) || $referent; | ||||||||||||||||||||||||||
|
Condition66%2/3
ref $referent || $referent
MC/DC0%0/2
ref $referent || $referent
ref $referent
$referent
Truth table66%2/3
A || B
A= ref $referentB= $referent
| |||||||||||||||||||||||||||||
| 24 | 53 | ▶ | my $num = ( ref($referent) ? $$referent : undef ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 53 | my $num_q = \$num; | |||||||||||||||||||||||||||
| 26 | 53 | bless $num_q, $class; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | # $quantity->init( $n_val ); | ||||||||||||||||||||||||||||
| 30 | 36 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 36 | my $num_q = shift; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 36 | my $n_val = shift; | |||||||||||||||||||||||||||
| 34 | 36 | my $numerals = $num_q->numeric_value( $n_val ); | |||||||||||||||||||||||||||
| 35 | 36 | ▶ | if ( defined $numerals ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | 36 | $num_q->value( $numerals ); | |||||||||||||||||||||||||||
| 37 | } else { | ||||||||||||||||||||||||||||
| 38 | 0 | $num_q->not_a_number( $n_val ); | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | # $n_val = $quantity->value; | ||||||||||||||||||||||||||||
| 43 | # $quantity->value( $n_val ); | ||||||||||||||||||||||||||||
| 44 | 120 | ▶ | sub value { | ||||||||||||||||||||||||||
|
Subroutine
value: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 45 | 120 | my $num_q = shift; | |||||||||||||||||||||||||||
| 46 | 120 | ▶ | croak "object method" if ! ref $num_q; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 120 | ▶ | return $$num_q if ( ! scalar @_ ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 49 | my $n_val = shift; | |||||||||||||||||||||||||||
| 51 | # if ( ! defined $n_val || length($n_val) < 1 ) { | ||||||||||||||||||||||||||||
| 52 | # $$num_q = undef; | ||||||||||||||||||||||||||||
| 53 | # return; | ||||||||||||||||||||||||||||
| 54 | # } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 49 | $$num_q = $n_val; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | # $quantity->not_a_number; | ||||||||||||||||||||||||||||
| 60 | # $quantity->not_a_number( $value ); | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub not_a_number { | ||||||||||||||||||||||||||
|
Subroutine
not_a_number: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 0 | my $num_q = shift; | |||||||||||||||||||||||||||
| 63 | 0 | ▶ | if ( scalar @_ ) { $$num_q = shift; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | bless $num_q, 'Data::Quantity::Number::NAN'; | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # $string = $quantity->readable( @_ ); | ||||||||||||||||||||||||||||
| 68 | 29 | ▶ | sub readable { | ||||||||||||||||||||||||||
|
Subroutine
readable: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 29 | my $num_q = shift; | |||||||||||||||||||||||||||
| 70 | 29 | ▶ | croak "object method" if ! ref $num_q; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 71 | 29 | $num_q->readable_value( $num_q->value(), @_ ); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | # undef = Data::Quantity::Number::Number->scale(); | ||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub scale { | ||||||||||||||||||||||||||
|
Subroutine
scale: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 76 | 0 | return undef; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 6 | ▶ | use vars qw( $ThousandsSeparator $DecimalSeparator $DefaultPlaces ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 80 | 6 | $ThousandsSeparator = ','; | |||||||||||||||||||||||||||
| 81 | 6 | $DecimalSeparator = '.'; | |||||||||||||||||||||||||||
| 82 | 6 | $DefaultPlaces = undef; | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | # $n_val = Data::Quantity::Number::Number->numeric_value( $candidate_n_val ); | ||||||||||||||||||||||||||||
| 85 | 39 | ▶ | sub numeric_value { | ||||||||||||||||||||||||||
|
Subroutine
numeric_value: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 39 | my $class_or_item = shift; | |||||||||||||||||||||||||||
| 87 | 39 | my $n_val = shift; | |||||||||||||||||||||||||||
| 88 | 39 | ▶ | $n_val =~ /\A | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 89 | \-? | ||||||||||||||||||||||||||||
| 90 | (?: \d | \Q$ThousandsSeparator\E \d{3} )* | ||||||||||||||||||||||||||||
| 91 | (?: \Q$DecimalSeparator\E \d+ )? | ||||||||||||||||||||||||||||
| 92 | (?: [eE] \-? \d+ )? | ||||||||||||||||||||||||||||
| 93 | \Z/x | ||||||||||||||||||||||||||||
| 94 | or return undef; | ||||||||||||||||||||||||||||
| 95 | 39 | $n_val =~ s/\Q$ThousandsSeparator\E//g; | |||||||||||||||||||||||||||
| 96 | 39 | ▶ | $n_val =~ s/\Q$DecimalSeparator\E/\./g unless ( $DecimalSeparator eq '.' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | 39 | $n_val; | |||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # $string = $quantity->readable_value($n_val); | ||||||||||||||||||||||||||||
| 101 | # $string = $quantity->readable_value($n_val, $places); | ||||||||||||||||||||||||||||
| 102 | # $string = Data::Quantity::Number::Number->readable_value($n_val); | ||||||||||||||||||||||||||||
| 103 | # $string = Data::Quantity::Number::Number->readable_value($n_val, $places); | ||||||||||||||||||||||||||||
| 104 | 3 | ▶ | sub readable_value { | ||||||||||||||||||||||||||
|
Subroutine
readable_value: called CC=6 SCAR=19.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 3 | my $class_or_item = shift; | |||||||||||||||||||||||||||
| 106 | 3 | my $n_val = shift; | |||||||||||||||||||||||||||
| 107 | 3 | ▶ | my $places = shift || $DefaultPlaces || undef; | ||||||||||||||||||||||||||
|
Condition40%2/5
shift() || $Data::Quantity::Number::Number::DefaultPlaces || undef
shift() or $Data::Quantity::Number::Number::DefaultPlaces
MC/DC0%0/2
shift() || $Data::Quantity::Number::Number::DefaultPlaces || undef
shift()
$Data::Quantity::Number::Number::DefaultPlaces
Truth table33%1/3
A or B
A= shift()B= $Data::Quantity::Number::Number::DefaultPlaces
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 3 | my ($int, $dec) = split(/\./, $n_val, 2); | |||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 3 | $int = reverse join($ThousandsSeparator, reverse($int) =~ m/(\d{1,3})/g); | |||||||||||||||||||||||||||
| 112 | 3 | ▶ | $dec = substr($dec, 0, $places) . ( '0' x ( $places - length($dec) ) ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 113 | if ( defined $places ); | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 3 | ▶ | return $int . | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $dec and length $dec
MC/DC50%1/2
defined $dec and length $dec
defined $dec
length $dec
Truth table66%2/3
A and B
A= defined $decB= length $dec
| |||||||||||||||||||||||||||||
| 116 | ( ( defined($dec) and length($dec) ) ? $DecimalSeparator . $dec : '' ); | ||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | package Data::Quantity::Number::NAN; | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 6 | ▶ | use vars qw( @ISA ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 122 | 6 | push @ISA, 'Data::Quantity::Number::Number'; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 6 | 1; | |||||||||||||||||||||||||||