line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package # hide from PAUSE indexer |
2
|
|
|
|
|
|
|
Calculator; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
35
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
6
|
1
|
|
|
1
|
|
9
|
use Moo; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
14
|
|
7
|
1
|
|
|
1
|
|
448
|
use Types::Standard qw( Num Str ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
23
|
|
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
|
238
|
my ( $self, $seq ) = @_; |
18
|
64
|
|
|
|
|
226
|
my @possible = grep { /\S/ } split( //, $seq ); |
|
231
|
|
|
|
|
718
|
|
19
|
64
|
|
|
|
|
242
|
$self->press($_) for @possible; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub press { |
23
|
283
|
|
|
283
|
0
|
527
|
my ( $self, $key ) = @_; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# Numbers |
26
|
283
|
100
|
|
|
|
1042
|
$self->digit($1) if $key =~ m/^([\d\.])$/; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# Operators |
29
|
283
|
100
|
|
|
|
8180
|
$self->key_operator($1) if $key =~ m/^([\+\-\/\*])$/; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Equals |
32
|
283
|
100
|
|
|
|
2081
|
$self->equalsign if $key eq '='; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Clear |
35
|
283
|
100
|
|
|
|
1992
|
$self->clear if $key eq 'C'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub clear { |
39
|
30
|
|
|
30
|
0
|
64
|
my $self = shift; |
40
|
30
|
|
|
|
|
510
|
$self->left(0); |
41
|
30
|
|
|
|
|
1225
|
$self->right(''); |
42
|
30
|
|
|
|
|
1281
|
$self->operator('+'); |
43
|
30
|
|
|
|
|
1297
|
$self->display('0'); |
44
|
30
|
|
|
|
|
1274
|
$self->equals(''); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub equalsign { |
48
|
28
|
|
|
28
|
0
|
76
|
my $self = shift; |
49
|
28
|
|
|
|
|
91
|
$self->key_operator('+'); |
50
|
28
|
|
|
|
|
1207
|
my $result = $self->left; |
51
|
28
|
|
|
|
|
247
|
$self->clear(); |
52
|
28
|
|
|
|
|
1148
|
$self->equals($result); |
53
|
28
|
|
|
|
|
1106
|
$self->display($result); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub digit { |
57
|
168
|
|
|
168
|
0
|
463
|
my ( $self, $digit ) = @_; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Deal with decimal weirdness |
60
|
168
|
100
|
|
|
|
432
|
if ( $digit eq '.' ) { |
61
|
19
|
50
|
|
|
|
345
|
return if $self->right =~ m/\./; |
62
|
19
|
50
|
|
|
|
469
|
$digit = '0.' unless length( $self->right ); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
168
|
|
|
|
|
3462
|
$self->right( $self->right . $digit ); |
66
|
168
|
|
|
|
|
7836
|
$self->display( $self->right ); |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub key_operator { |
70
|
76
|
|
|
76
|
0
|
207
|
my ( $self, $operator ) = @_; |
71
|
|
|
|
|
|
|
|
72
|
76
|
50
|
|
|
|
1408
|
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
|
|
|
|
|
6376
|
$self->right(''); |
82
|
76
|
|
|
|
|
3270
|
$self->equals(''); |
83
|
|
|
|
|
|
|
|
84
|
76
|
|
|
|
|
5692
|
$self->left( ( eval $cmd ) + 0 ); |
85
|
76
|
|
|
|
|
3441
|
$self->display( $self->left ); |
86
|
|
|
|
|
|
|
|
87
|
76
|
|
|
|
|
4591
|
$self->operator($operator); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |