Shortkeys/Manager.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 79 CC 6 SCAR 21.1
CC
6
Cov
0%
listen
20.0
get_shortkey
6.0
get_data
6.0
CRAP 8.3
1 package Win32::Shortkeys::Manager;
2 use strict;
3 use warnings;
4
5 #use Data::Dumper;
6
7 use constant STARTKEY => 226; #<
8
9 sub new {
10 my ($class, $data) = @_;
11 my $self = bless ({}, ref ($class) || $class);
12 $self->{searchOn}= 0;
13 $self->{found} = 0;
14 $self->{data} = $data;
15
16 return $self;
17 }
18
19
20 sub listen {
21 my ($self, $kcode) = @_;
22
23 my %data = %{$self->{data}};
24 #print "Listen to kcode $kcode current: ", defined $self->{current} ? $self->{current} : " undef", "\n";
25
26 $self->{found} = 0;
27 if ($kcode == STARTKEY ) {
28 # $self->{searchOn} = ( $self->{searchOn} ? 0 : 1) ;
29 $self->{searchOn} = 1;
30 $self->{current} = undef;
31 $self->{found}=0;
32 } elsif ($self->{searchOn} && 64 < $kcode && $kcode < 91) {
33 $self->{current} .= chr (32 + $kcode); #lower case letters in {current}
34 #die $self->{current};
35
36 if ( exists $data{ $self->{current} }) {
37 #print $self->{current}, "\n";
38 $self->{found} =1;
39 $self->{searchOn} = 0;
40 }
41
42
43
44 } else {
45 $self->{found} = 0;
46 $self->{searchOn} = 0;
47 $self->{current} = undef;
48
49 }
50
51 # print "listen current: ", ( $self->{current} ? $self->{current} : " undef "), " searchOn: ", $self->{searchOn}, " found: ", $self->{found}, "\n";
52
53 }
54
55
56 sub is_ready {
57 my $self = shift;
58 #print "is_ready ", ( $self->{found} ? " true ": " false "), "\n";
59 $self->{found};
60
61
62 }
63
64 sub get_shortkey {
65 my $self = shift;
66 $self->{found} ? $self->{current} : undef;
67 }
68
69 sub get_data {
70 my $self = shift;
71 #print "get_Data returning ", ($self->{found} ? $self->{data}->{ $self->{current} } : " undef "), "\n";
72 $self->{found} ? $self->{data}->{ $self->{current} }: undef;
73 }
74
75 sub print_all {
76 my $self = shift;
77 my @shks = keys %{ $self->{data} };
78 for my $shk ( @shks ) {
79 print $shk, " -> ", $self->{data}->{$shk}, "\n";
80 }
81 }
82
83 1;