blib/lib/Dallycot/Value/Numeric.pm

filter: Statementstmt 60.2% 47 / 78 Branchbran 30.0% 3 / 10 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 76.1% 16 / 21 Podpod 0.0% 0 / 16 totaltotal 52.3% 68 / 130 CC 7 SCAR 16.0
CC
7
Cov
57%
to_rdf
20.1
new
3.0
as_text
2.0
CRAP 5.0
« blib/lib/Dallycot/Context.pm ↑ Summary blib/lib/Dallycot/Value/Duration.pm »
1 package Dallycot::Value::Numeric;
2 30 our $AUTHORITY = 'cpan:JSMITH';
3  
4 # ABSTRACT: An arbitrary precision numeric value
5  
6 30 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 30 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 30 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 30 ▶use parent 'Dallycot::Value::Any';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 30 ▶use Promises qw(deferred);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 sub new {
15 562 ▶ my ( $class, $value ) = @_;
Subroutine new: called CC=3 SCAR=11.0
Pod undocumented
16  
17 562 ▶ $class = ref $class || $class;
Condition66%2/3
ref $class || $class
l!l&&r!l&&!r
884740
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table66%2/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
18  
19 562 ▶ return bless [ ref($value) ? $value : Math::BigRat->new($value) ] => $class;
Branch: 1 branch
BranchTrueFalseTotal
ref $value ? : 515 47 562
20 }
21  
22 sub to_rdf {
23 3 ▶ my($self, $model) = @_;
Subroutine to_rdf: called CC=5 SCAR=30.0
Pod undocumented
24  
25 3 ▶ if($self->[0]->is_int) {
Branch: 4 branches
BranchTrueFalseTotal
if ($self->[0]->is_int) { } 3 0 3
elsif ($self->[0]->is_nan) { } 0 0 0
elsif ($self->[0]->is_inf) { } 0 0 0
elsif ($self->[0]->is_inf('-')) { } 0 0 0
26 3 return $model -> integer($self -> [0] -> bstr);
27 }
28 elsif($self -> [0] -> is_nan) {
29 0 my $bnode = $model->bnode;
30 0 $model -> add_type($bnode, 'loc:NotANumber');
31 0 return $bnode;
32 }
33 elsif($self -> [0] -> is_inf) {
34 0 my $bnode = $model -> bnode;
35 0 $model -> add_type($bnode, 'loc:PositiveInfinity');
36 0 return $bnode;
37 }
38 elsif($self -> [0] -> is_inf('-')) {
39 0 my $bnode = $model -> bnode;
40 0 $model -> add_type($bnode, 'loc:NegativeInifinity');
41 0 return $bnode;
42 }
43 else {
44 0 my $bnode = $model -> bnode;
45 0 $model -> add_type($bnode, 'loc:Rational');
46 0 my($n, $d) = $self -> [0] -> parts;
47 0 $model -> add_connection($bnode, 'loc:denominator',
48 $model -> integer($d -> bstr)
49 );
50 0 $model -> add_connection($bnode, 'loc:numerator',
51 $model -> integer($n->bstr)
52 );
53 0 return $bnode;
54 }
55 }
56  
57 sub id {
58 14 ▶ my ($self) = @_;
Subroutine id: called CC=1 SCAR=0.0
Pod undocumented
59 14 return $self->[0]->bstr . "^^Numeric";
60 }
61  
62 2 ▶sub is_defined { return 1 }
Subroutine is_defined: called CC=1 SCAR=0.0
Pod undocumented
63  
64 2 ▶sub is_empty {return}
Subroutine is_empty: called CC=1 SCAR=0.0
Pod undocumented
65  
66 sub as_text {
67 0 ▶ my ($self) = @_;
Subroutine as_text: not called CC=1 SCAR=6.9
Pod undocumented
68  
69 0 return $self->[0]->bstr;
70 }
71  
72 sub value {
73 1262 ▶ my ($self) = @_;
Subroutine value: called CC=1 SCAR=0.0
Pod undocumented
74 1262 return $self->[0];
75 }
76  
77 sub calculate_length {
78 0 ▶ my ( $self, $engine ) = @_;
Subroutine calculate_length: not called CC=1 SCAR=6.9
Pod undocumented
79  
80 0 return $self->new( $self->[0]->copy->bfloor->length );
81 }
82  
83 sub is_equal {
84 92 ▶ my ( $self, $engine, $other ) = @_;
Subroutine is_equal: called CC=1 SCAR=0.0
Pod undocumented
85  
86 92 my $d = deferred;
87  
88 92 $d->resolve( $self->value == $other->value );
89  
90 92 return $d->promise;
91 }
92  
93 sub is_less {
94 18 ▶ my ( $self, $engine, $other ) = @_;
Subroutine is_less: called CC=1 SCAR=0.0
Pod undocumented
95  
96 18 my $d = deferred;
97  
98 18 $d->resolve( $self->value < $other->value );
99  
100 18 return $d->promise;
101 }
102  
103 sub is_less_or_equal {
104 0 ▶ my ( $self, $engine, $other ) = @_;
Subroutine is_less_or_equal: not called CC=1 SCAR=6.9
Pod undocumented
105  
106 0 my $d = deferred;
107  
108 0 $d->resolve( $self->value <= $other->value );
109  
110 0 return $d->promise;
111 }
112  
113 sub is_greater {
114 14 ▶ my ( $self, $engine, $other ) = @_;
Subroutine is_greater: called CC=1 SCAR=0.0
Pod undocumented
115  
116 14 my $d = deferred;
117  
118 14 $d->resolve( $self->value > $other->value );
119  
120 14 return $d->promise;
121 }
122  
123 sub is_greater_or_equal {
124 0 ▶ my ( $self, $engine, $other ) = @_;
Subroutine is_greater_or_equal: not called CC=1 SCAR=6.9
Pod undocumented
125  
126 0 my $d = deferred;
127  
128 0 $d->resolve( $self->value >= $other->value );
129  
130 0 return $d->promise;
131 }
132  
133 sub negated {
134 23 ▶ my($self) = @_;
Subroutine negated: called CC=1 SCAR=0.0
Pod undocumented
135  
136 23 return $self->new( - $self->[0] );
137 }
138  
139 sub successor {
140 65 ▶ my ($self) = @_;
Subroutine successor: called CC=1 SCAR=0.0
Pod undocumented
141  
142 65 my $d = deferred;
143  
144 65 $d->resolve( $self->new( $self->[0]->copy->binc ) );
145  
146 65 return $d->promise;
147 }
148  
149 sub predecessor {
150 0 ▶ my ($self) = @_;
Subroutine predecessor: not called CC=1 SCAR=6.9
Pod undocumented
151  
152 0 my $d = deferred;
153  
154 0 $d->resolve( $self->new( $self->[0]->copy->bdec ) );
155  
156 0 return $d->promise;
157 }
158  
159 30 1;
« blib/lib/Dallycot/Context.pm ↑ Summary blib/lib/Dallycot/Value/Duration.pm »