blib/lib/Language/Farnsworth/Value/Undef.pm

filter: Statementstmt 37.8% 31 / 82 Branchbran 0.0% 0 / 54 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 47.3% 9 / 19 Podpod 0.0% 0 / 11 totaltotal 24.1% 40 / 166 CC 28 SCAR 30.7
CC
28
Cov
23%
add
30.0
subtract
30.0
modulus
30.0
CRAP 21.6
« blib/lib/Language/Farnsworth/Value/Array.pm ↑ Summary blib/lib/Language/Farnsworth/Value/String.pm »
1 package Language::Farnsworth::Value::Undef;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Language::Farnsworth::Dimension;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use base 'Language::Farnsworth::Value';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 4 ▶use Language::Farnsworth::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 4 our $VERSION = 0.6;
13  
14 use overload
15 4 ▶ '+' => \&add,
Subroutine BEGIN: called CC=1 SCAR=0.0
16 '-' => \&subtract,
17 '*' => \&mult,
18 '/' => \&div,
19 '%' => \&mod,
20 '**' => \&pow,
21 '<=>' => \&compare,
22 4 'bool' => \&bool;
23  
24 4 ▶use base qw(Language::Farnsworth::Value);
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 #this is the REQUIRED fields for Language::Farnsworth::Value subclasses
27 #
28 #dimen => a Language::Farnsworth::Dimension object
29 #
30 #this is so i can make a -> conforms in Language::Farnsworth::Value, to replace the existing code, i'm also planning on adding some definitions such as, TYPE_PARI, TYPE_STRING, TYPE_LAMBDA, TYPE_DATE, etc. to make certain things easier
31  
32 sub new
33 726 ▶{
Subroutine new: called CC=1 SCAR=0.0
Pod undocumented
34 726 my $class = shift;
35 726 my $outmagic = shift; #i'm still not sure on this one
36  
37 726 my $self = {};
38  
39 726 bless $self, $class;
40  
41 726 $self->{outmagic} = $outmagic;
42
43 726 return $self;
44 }
45  
46 sub type
47 0 ▶{
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
48 0 return "undef";
49 }
50  
51 #######
52 #The rest of this code can be GREATLY cleaned up by assuming that $one is of type, Language::Farnsworth::Value::Pari, this means that i can slowly redo a lot of this code
53  
54 sub add
55 0 ▶{
Subroutine add: not called CC=5 SCAR=34.0
Pod undocumented
56 0 my ($one, $two, $rev) = @_;
57  
58 0 ▶ error "Non reference given to addition of undef" unless ref($two);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $two 0 0 0
59  
60 #if we're not being added to a Language::Farnsworth::Value::Pari, the higher class object needs to handle it.
61 0 ▶ error "Scalar value given to addition to undef" if ($two->isa("Language::Farnsworth::Value::Pari"));
Branch: 1 branch
BranchTrueFalseTotal
if $two->isa("Language::Farnsworth::Value::Pari") 0 0 0
62 0 ▶ return $two->add($one, !$rev) unless ($two->ismediumtype());
Branch: 1 branch
BranchTrueFalseTotal
unless $two->ismediumtype 0 0 0
63 0 ▶ if (!$two->istype("Undef"))
Branch: 1 branch
BranchTrueFalseTotal
unless ($two->istype("Undef")) 0 0 0
64 {
65 0 error "Given non undef to undef operation";
66 }
67  
68 #NOTE TO SELF this needs to be more helpful, i'll probably do this by creating an "error" class that'll be captured in ->evalbranch's recursion and use that to add information from the parse tree about WHERE the error occured
69 0 error "Adding undefs is not a good idea\n";
70 }
71  
72 sub subtract
73 0 ▶{
Subroutine subtract: not called CC=5 SCAR=34.0
Pod undocumented
74 0 my ($one, $two, $rev) = @_;
75  
76 0 ▶ error "Non reference given to subtraction of undef" unless ref($two);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $two 0 0 0
77  
78 #if there's a higher type, use it, subtraction otherwise doesn't make sense on arrays
79 0 ▶ error "Scalar value given to subtraction to undef" if ($two->isa("Language::Farnsworth::Value::Pari"));
Branch: 1 branch
BranchTrueFalseTotal
if $two->isa("Language::Farnsworth::Value::Pari") 0 0 0
80 0 ▶ return $two->subtract($one, !$rev) unless ($two->ismediumtype());
Branch: 1 branch
BranchTrueFalseTotal
unless $two->ismediumtype 0 0 0
81 0 ▶ if (!$two->istype("Undef"))
Branch: 1 branch
BranchTrueFalseTotal
unless ($two->istype("Undef")) 0 0 0
82 {
83 0 error "Given non undef to undef operation";
84 }
85  
86 0 error "Subtracting undef? what did you think this would do, create a black hole?";
87 }
88  
89 sub modulus
90 0 ▶{
Subroutine modulus: not called CC=5 SCAR=34.0
Pod undocumented
91 0 my ($one, $two, $rev) = @_;
92  
93 0 ▶ error "Non reference given to modulus of undef" unless ref($two);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $two 0 0 0
94  
95 #if there's a higher type, use it, subtraction otherwise doesn't make sense on arrays
96 0 ▶ error "Scalar value given to modulus to undef" if ($two->isa("Language::Farnsworth::Value::Pari"));
Branch: 1 branch
BranchTrueFalseTotal
if $two->isa("Language::Farnsworth::Value::Pari") 0 0 0
97 0 ▶ return $two->mod($one, !$rev) unless ($two->ismediumtype());
Branch: 1 branch
BranchTrueFalseTotal
unless $two->ismediumtype 0 0 0
98 0 ▶ if (!$two->istype("Undef"))
Branch: 1 branch
BranchTrueFalseTotal
unless ($two->istype("Undef")) 0 0 0
99 {
100 0 error "Given non undef to undefoperation";
101 }
102  
103 0 error "Modulusing undef? what did you think this would do, create a black hole?";
104 }
105  
106 sub mult
107 0 ▶{
Subroutine mult: not called CC=5 SCAR=34.0
Pod undocumented
108 0 my ($one, $two, $rev) = @_;
109  
110 0 ▶ error "Non reference given to multiplication of undef" unless ref($two);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $two 0 0 0
111  
112 #if there's a higher type, use it, subtraction otherwise doesn't make sense on arrays
113 0 ▶ error "Scalar value given to multiplcation of undef" if ($two->isa("Language::Farnsworth::Value::Pari"));
Branch: 1 branch
BranchTrueFalseTotal
if $two->isa("Language::Farnsworth::Value::Pari") 0 0 0
114 0 ▶ return $two->mult($one, !$rev) unless ($two->ismediumtype());
Branch: 1 branch
BranchTrueFalseTotal
unless $two->ismediumtype 0 0 0
115 0 ▶ if (!$two->istype("Undef"))
Branch: 1 branch
BranchTrueFalseTotal
unless ($two->istype("Undef")) 0 0 0
116 {
117 0 error "Given non undef to undef operation";
118 }
119  
120 0 error "Multiplying undefs? what did you think this would do, create a black hole?";
121 }
122  
123 sub div
124 0 ▶{
Subroutine div: not called CC=5 SCAR=34.0
Pod undocumented
125 0 my ($one, $two, $rev) = @_;
126  
127 0 ▶ error "Non reference given to division of undef" unless ref($two);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $two 0 0 0
128  
129 #if there's a higher type, use it, subtraction otherwise doesn't make sense on arrays
130 0 ▶ error "Scalar value given to division of undef" if ($two->isa("Language::Farnsworth::Value::Pari"));
Branch: 1 branch
BranchTrueFalseTotal
if $two->isa("Language::Farnsworth::Value::Pari") 0 0 0
131 0 ▶ return $two->div($one, !$rev) unless ($two->ismediumtype());
Branch: 1 branch
BranchTrueFalseTotal
unless $two->ismediumtype 0 0 0
132 0 ▶ if (!$two->istype("Undef"))
Branch: 1 branch
BranchTrueFalseTotal
unless ($two->istype("Undef")) 0 0 0
133 {
134 0 error "Given non undef to undef operation";
135 }
136  
137 0 error "Dividing undef? what did you think this would do, create a black hole?";
138 }
139  
140 sub bool
141 0 ▶{
Subroutine bool: not called CC=1 SCAR=6.9
Pod undocumented
142 0 my $self = shift;
143  
144 #seems good enough of an idea to me
145 #i have a bug HERE
146 #print "BOOLCONV\n";
147 #print Dumper($self);
148 #print "ENDBOOLCONV\n";
149 0 return 0;
150 }
151  
152 sub pow
153 0 ▶{
Subroutine pow: not called CC=5 SCAR=34.0
Pod undocumented
154 0 my ($one, $two, $rev) = @_;
155  
156 0 ▶ error "Non reference given to exponentiation of undef" unless ref($two);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $two 0 0 0
157  
158 #if there's a higher type, use it, subtraction otherwise doesn't make sense on arrays
159 0 ▶ error "Exponentiating undef? what did you think this would do, create a black hole?" if ($two->isa("Language::Farnsworth::Value::Pari"));
Branch: 1 branch
BranchTrueFalseTotal
if $two->isa("Language::Farnsworth::Value::Pari") 0 0 0
160 0 ▶ return $two->pow($one, !$rev) unless ($two->ismediumtype());
Branch: 1 branch
BranchTrueFalseTotal
unless $two->ismediumtype 0 0 0
161 0 ▶ if (!$two->istype("Undef"))
Branch: 1 branch
BranchTrueFalseTotal
unless ($two->istype("Undef")) 0 0 0
162 {
163 0 error "Given non undef to undef operation";
164 }
165  
166  
167 0 error "Exponentiating undefs? what did you think this would do, create a black hole?";
168 }
169  
170 sub compare
171 0 ▶{
Subroutine compare: not called CC=4 SCAR=30.0
Pod undocumented
172 0 my ($one, $two, $rev) = @_;
173  
174 0 ▶ error "Non reference given to compare of undef" unless ref($two);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $two 0 0 0
175  
176 #if we're not being added to a Language::Farnsworth::Value::Pari, the higher class object needs to handle it.
177 0 ▶ error "Scalar value given to compare of undef" if ($two->isa("Language::Farnsworth::Value::Pari"));
Branch: 1 branch
BranchTrueFalseTotal
if $two->isa("Language::Farnsworth::Value::Pari") 0 0 0
178 0 ▶ return $two->compare($one, !$rev) unless ($two->ismediumtype());
Branch: 1 branch
BranchTrueFalseTotal
unless $two->ismediumtype 0 0 0
179  
180 0 return 0;
181 }
182  
183 sub toperl
184 0 ▶{
Subroutine toperl: not called CC=1 SCAR=6.9
Pod undocumented
185 0 return undef;
186 }
« blib/lib/Language/Farnsworth/Value/Array.pm ↑ Summary blib/lib/Language/Farnsworth/Value/String.pm »