line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # hide from PAUSE indexer |
2
|
|
|
|
|
|
|
Calculator; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
8
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
31
|
|
6
|
1
|
|
|
1
|
|
10
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
7
|
1
|
|
|
1
|
|
457
|
use Types::Standard qw( Num Str ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'left' => ( is => 'rw', isa => Num, default => 0 ); |
10
|
|
|
|
|
|
|
has 'right' => ( is => 'rw', isa => Str, default => '' ); |
11
|
|
|
|
|
|
|
has 'operator' => ( is => 'rw', isa => Str, default => '+' ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has 'display' => ( is => 'rw', isa => Str, default => '0' ); |
14
|
|
|
|
|
|
|
has 'equals' => ( is => 'rw', isa => Str, default => '' ); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub key_in { |
17
|
64
|
|
|
64
|
0
|
200
|
my ( $self, $seq ) = @_; |
18
|
64
|
|
|
|
|
230
|
my @possible = grep { /\S/ } split( //, $seq ); |
|
231
|
|
|
|
|
695
|
|
19
|
64
|
|
|
|
|
243
|
$self->press($_) for @possible; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub press { |
23
|
283
|
|
|
283
|
0
|
546
|
my ( $self, $key ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Numbers |
26
|
283
|
100
|
|
|
|
968
|
$self->digit($1) if $key =~ m/^([\d\.])$/; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Operators |
29
|
283
|
100
|
|
|
|
7670
|
$self->key_operator($1) if $key =~ m/^([\+\-\/\*])$/; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Equals |
32
|
283
|
100
|
|
|
|
1869
|
$self->equalsign if $key eq '='; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Clear |
35
|
283
|
100
|
|
|
|
1878
|
$self->clear if $key eq 'C'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub clear { |
39
|
30
|
|
|
30
|
0
|
60
|
my $self = shift; |
40
|
30
|
|
|
|
|
476
|
$self->left(0); |
41
|
30
|
|
|
|
|
1130
|
$self->right(''); |
42
|
30
|
|
|
|
|
1160
|
$self->operator('+'); |
43
|
30
|
|
|
|
|
1162
|
$self->display('0'); |
44
|
30
|
|
|
|
|
1212
|
$self->equals(''); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub equalsign { |
48
|
28
|
|
|
28
|
0
|
73
|
my $self = shift; |
49
|
28
|
|
|
|
|
76
|
$self->key_operator('+'); |
50
|
28
|
|
|
|
|
1116
|
my $result = $self->left; |
51
|
28
|
|
|
|
|
213
|
$self->clear(); |
52
|
28
|
|
|
|
|
1086
|
$self->equals($result); |
53
|
28
|
|
|
|
|
1070
|
$self->display($result); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub digit { |
57
|
168
|
|
|
168
|
0
|
442
|
my ( $self, $digit ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Deal with decimal weirdness |
60
|
168
|
100
|
|
|
|
402
|
if ( $digit eq '.' ) { |
61
|
19
|
50
|
|
|
|
328
|
return if $self->right =~ m/\./; |
62
|
19
|
50
|
|
|
|
428
|
$digit = '0.' unless length( $self->right ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
168
|
|
|
|
|
2954
|
$self->right( $self->right . $digit ); |
66
|
168
|
|
|
|
|
7467
|
$self->display( $self->right ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub key_operator { |
70
|
76
|
|
|
76
|
0
|
193
|
my ( $self, $operator ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
76
|
50
|
|
|
|
1305
|
my $cmd = |
|
|
100
|
|
|
|
|
|
73
|
|
|
|
|
|
|
$self->left |
74
|
|
|
|
|
|
|
. $self->operator |
75
|
|
|
|
|
|
|
. ( |
76
|
|
|
|
|
|
|
length( $self->right ) |
77
|
|
|
|
|
|
|
? $self->right |
78
|
|
|
|
|
|
|
: ( length( $self->equals ) ? $self->equals : '0' ) |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
76
|
|
|
|
|
6035
|
$self->right(''); |
82
|
76
|
|
|
|
|
3142
|
$self->equals(''); |
83
|
|
|
|
|
|
|
|
84
|
76
|
|
|
|
|
5840
|
$self->left( ( eval $cmd ) + 0 ); |
85
|
76
|
|
|
|
|
3275
|
$self->display( $self->left ); |
86
|
|
|
|
|
|
|
|
87
|
76
|
|
|
|
|
4311
|
$self->operator($operator); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |