blib/lib/Lingy/Number.pm untested

filter: Statementstmt 0.0% 0 / 63 Branchbran 0.0% 0 / 40 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 16 Podpod 0.0% 0 / 11 totaltotal 0.0% 0 / 130 CC 21 SCAR 23.4
CC
21
Cov
0%
equal_to
12.0
greater_than
12.0
greater_equal
12.0
CRAP 10.3
1 use strict; use warnings;
2 package Lingy::Number;
3  
4 use Lingy::Common;
5 use base 'Lingy::ScalarClass';
6  
7 use overload
8 '""' => sub { 0 + ${$_[0]} },
9 '+' => \&add,
10 '-' => \&subtract,
11 '*' => \&multiply,
12 '/' => \&divide,
13 '==' => \&equal_to,
14 '>' => \&greater_than,
15 '>=' => \&greater_equal,
16 '<' => \&less_than,
17 '<=' => \&less_equal,
18 '%' => \&modulo,
19 cmp => \&comp_pair,
20 ;
21  
22 sub cast {
23 $_[1];
24 }
25  
26 sub equal_to {
27 my ($x, $y) = @_;
28 $x = ref($x) ? $$x : $x;
29 $y = ref($y) ? $$y : $y;
30 BOOLEAN->new($x == $y);
31 }
32  
33 sub greater_than {
34 my ($x, $y) = @_;
35 $x = ref($x) ? $$x : $x;
36 $y = ref($y) ? $$y : $y;
37 BOOLEAN->new($x > $y);
38 }
39  
40 sub greater_equal {
41 my ($x, $y) = @_;
42 $x = ref($x) ? $$x : $x;
43 $y = ref($y) ? $$y : $y;
44 BOOLEAN->new($x >= $y);
45 }
46  
47 sub less_than {
48 my ($x, $y) = @_;
49 $x = ref($x) ? $$x : $x;
50 $y = ref($y) ? $$y : $y;
51 BOOLEAN->new($x < $y);
52 }
53  
54 sub less_equal {
55 my ($x, $y) = @_;
56 $x = ref($x) ? $$x : $x;
57 $y = ref($y) ? $$y : $y;
58 BOOLEAN->new($x <= $y);
59 }
60  
61 sub add {
62 my ($x, $y) = @_;
63 my $class = ref($x);
64 $x = ref($x) ? $$x : $x;
65 $y = ref($y) ? $$y : $y;
66 $class->new($x + $y);
67 }
68  
69 sub subtract {
70 my ($x, $y) = @_;
71 my $class = ref($x);
72 $x = ref($x) ? $$x : $x;
73 $y = ref($y) ? $$y : $y;
74 $class->new($x - $y);
75 }
76  
77 sub multiply {
78 my ($x, $y) = @_;
79 my $class = ref($x);
80 $x = ref($x) ? $$x : $x;
81 $y = ref($y) ? $$y : $y;
82 $class->new($x * $y);
83 }
84  
85 sub divide {
86 my ($x, $y) = @_;
87 my $class = ref($x);
88 $x = ref($x) ? $$x : $x;
89 $y = ref($y) ? $$y : $y;
90 $class->new($x / $y);
91 }
92  
93 sub modulo {
94 my ($x, $y) = @_;
95 my $class = ref($x);
96 $x = ref($x) ? $$x : $x;
97 $y = ref($y) ? $$y : $y;
98 $class->new($x % $y);
99 }
100  
101 1;