line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Number::Equation; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
141732
|
use 5.006; |
|
2
|
|
|
|
|
13
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
79
|
|
5
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
206
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
# TODO |
10
|
|
|
|
|
|
|
use overload |
11
|
|
|
|
|
|
|
'+' => \&add, |
12
|
|
|
|
|
|
|
'-' => \&subt, |
13
|
|
|
|
|
|
|
'/' => \&div, |
14
|
|
|
|
|
|
|
'*' => \&mult, |
15
|
0
|
|
|
0
|
|
0
|
'""' => sub { $_[0][0] }, |
16
|
2
|
|
|
2
|
|
2243
|
fallback => 1; |
|
2
|
|
|
|
|
1849
|
|
|
2
|
|
|
|
|
25
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
1
|
|
|
1
|
0
|
84
|
bless [ $_[1], [$_[1]] ], $_[0]; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub add { |
23
|
1
|
|
|
1
|
0
|
4
|
push @{ $_[0][-1] }, '+', $_[1]; |
|
1
|
|
|
|
|
3
|
|
24
|
1
|
|
|
|
|
3
|
$_[0][0] += $_[1]; |
25
|
1
|
|
|
|
|
2
|
$_[0]; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub mult { |
29
|
1
|
|
|
1
|
0
|
5
|
push @{ $_[0][-1] }, '*', $_[1]; |
|
1
|
|
|
|
|
4
|
|
30
|
1
|
|
|
|
|
2
|
$_[0][0] *= $_[1]; |
31
|
1
|
|
|
|
|
2
|
$_[0]; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub subt { |
35
|
2
|
100
|
|
2
|
0
|
27
|
if ($_[2]) { |
36
|
1
|
|
|
|
|
1
|
splice @{ $_[0] }, 1, 0, [$_[1], '-']; |
|
1
|
|
|
|
|
5
|
|
37
|
1
|
|
|
|
|
3
|
$_[0][0] = $_[1] - $_[0][0]; |
38
|
|
|
|
|
|
|
} else { |
39
|
1
|
|
|
|
|
2
|
push @{ $_[0][-1] }, '-', $_[1]; |
|
1
|
|
|
|
|
4
|
|
40
|
1
|
|
|
|
|
3
|
$_[0][0] = $_[0][0] - $_[1]; |
41
|
|
|
|
|
|
|
} |
42
|
2
|
|
|
|
|
4
|
$_[0]; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub div { |
47
|
2
|
100
|
|
2
|
0
|
8
|
if ($_[2]) { |
48
|
1
|
|
|
|
|
1
|
splice @{ $_[0] }, 1, 0, [$_[1], '/']; |
|
1
|
|
|
|
|
4
|
|
49
|
1
|
|
|
|
|
2
|
$_[0][0] = $_[1] / $_[0][0]; |
50
|
|
|
|
|
|
|
} else { |
51
|
1
|
|
|
|
|
2
|
push @{ $_[0][-1] }, '/', $_[1]; |
|
1
|
|
|
|
|
3
|
|
52
|
1
|
|
|
|
|
4
|
$_[0][0] = $_[0][0] / $_[1]; |
53
|
|
|
|
|
|
|
} |
54
|
2
|
|
|
|
|
4
|
$_[0]; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub equation { |
58
|
2
|
|
|
2
|
0
|
7
|
my $query = ''; |
59
|
2
|
|
|
|
|
11
|
my $closing = 0; |
60
|
2
|
|
|
|
|
5
|
for (my $i = 1; $i <= scalar @{ $_[0] } - 1; $i++) { |
|
7
|
|
|
|
|
13
|
|
61
|
5
|
|
|
|
|
7
|
my $equation = $_[0]->[$i]; |
62
|
5
|
|
|
|
|
7
|
$query .= '(' x ((scalar @{ $equation }) / 2) . $equation->[0]; |
|
5
|
|
|
|
|
13
|
|
63
|
5
|
|
|
|
|
7
|
for (my $x = 1; $x <= scalar @{ $equation } - 1; $x++) { |
|
16
|
|
|
|
|
26
|
|
64
|
11
|
|
|
|
|
13
|
my $operator = $equation->[$x++]; |
65
|
11
|
|
|
|
|
13
|
my $val = $equation->[$x]; |
66
|
11
|
100
|
|
|
|
21
|
$query .= ' ' . $operator . ' ' . (defined $val ? ($val . ')') : do { $closing++; "" }); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
6
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
2
|
|
|
|
|
4
|
$query .= ')' x $closing; |
70
|
2
|
|
|
|
|
11
|
$query .= ' = ' . $_[0]->[0]; |
71
|
2
|
|
|
|
|
7
|
return $query; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; # End of Number::Equation |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__; |