line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # hide from PAUSE indexer |
2
|
|
|
|
|
|
|
Calculator; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
11
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
29
|
|
6
|
1
|
|
|
1
|
|
7
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
7
|
1
|
|
|
1
|
|
452
|
use Types::Standard qw( Num Str ); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
16
|
|
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
|
218
|
my ( $self, $seq ) = @_; |
18
|
64
|
|
|
|
|
221
|
my @possible = grep { /\S/ } split( //, $seq ); |
|
231
|
|
|
|
|
630
|
|
19
|
64
|
|
|
|
|
218
|
$self->press($_) for @possible; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub press { |
23
|
283
|
|
|
283
|
0
|
513
|
my ( $self, $key ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Numbers |
26
|
283
|
100
|
|
|
|
972
|
$self->digit($1) if $key =~ m/^([\d\.])$/; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Operators |
29
|
283
|
100
|
|
|
|
7687
|
$self->key_operator($1) if $key =~ m/^([\+\-\/\*])$/; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Equals |
32
|
283
|
100
|
|
|
|
1865
|
$self->equalsign if $key eq '='; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Clear |
35
|
283
|
100
|
|
|
|
1847
|
$self->clear if $key eq 'C'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub clear { |
39
|
30
|
|
|
30
|
0
|
62
|
my $self = shift; |
40
|
30
|
|
|
|
|
490
|
$self->left(0); |
41
|
30
|
|
|
|
|
1131
|
$self->right(''); |
42
|
30
|
|
|
|
|
1204
|
$self->operator('+'); |
43
|
30
|
|
|
|
|
1184
|
$self->display('0'); |
44
|
30
|
|
|
|
|
1202
|
$self->equals(''); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub equalsign { |
48
|
28
|
|
|
28
|
0
|
57
|
my $self = shift; |
49
|
28
|
|
|
|
|
75
|
$self->key_operator('+'); |
50
|
28
|
|
|
|
|
1144
|
my $result = $self->left; |
51
|
28
|
|
|
|
|
227
|
$self->clear(); |
52
|
28
|
|
|
|
|
1136
|
$self->equals($result); |
53
|
28
|
|
|
|
|
1068
|
$self->display($result); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub digit { |
57
|
168
|
|
|
168
|
0
|
436
|
my ( $self, $digit ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Deal with decimal weirdness |
60
|
168
|
100
|
|
|
|
392
|
if ( $digit eq '.' ) { |
61
|
19
|
50
|
|
|
|
340
|
return if $self->right =~ m/\./; |
62
|
19
|
50
|
|
|
|
421
|
$digit = '0.' unless length( $self->right ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
168
|
|
|
|
|
3034
|
$self->right( $self->right . $digit ); |
66
|
168
|
|
|
|
|
7539
|
$self->display( $self->right ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub key_operator { |
70
|
76
|
|
|
76
|
0
|
208
|
my ( $self, $operator ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
76
|
50
|
|
|
|
1406
|
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
|
|
|
|
|
5970
|
$self->right(''); |
82
|
76
|
|
|
|
|
3155
|
$self->equals(''); |
83
|
|
|
|
|
|
|
|
84
|
76
|
|
|
|
|
5721
|
$self->left( ( eval $cmd ) + 0 ); |
85
|
76
|
|
|
|
|
3312
|
$self->display( $self->left ); |
86
|
|
|
|
|
|
|
|
87
|
76
|
|
|
|
|
4465
|
$self->operator($operator); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |