Karabiner/Manipulator/Actions/To.pm

filter: Statementstmt 96.1% 99 / 103 Branchbran 76.3% 29 / 38 Conditioncond 87.5% 14 / 16 MC/DCmcdc 80.0% 8 / 10 Subroutinesub 100% 13 / 13 Podpod 100% 7 / 7 totaltotal 90.9% 170 / 187 CC 27 SCAR 20.0
CC
27
Cov
90%
add_key_code
15.1
add_select_input_source
4.2
add_mouse_key
3.0
CRAP 7.4
« Karabiner/Manipulator/Actions/From.pm ↑ Summary Karabiner.pm »
1 package JSON::Karabiner::Manipulator::Actions::To ;
2 10 $JSON::Karabiner::Manipulator::Actions::To::VERSION = '0.011';
3 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 10 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 10 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use parent 'JSON::Karabiner::Manipulator::Actions';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 sub new {
10 18 ▶ my $class = shift;
Subroutine new: called CC=2 SCAR=7.0
Pod documented
11 18 my ($type, $value) = @_;
12 18 my $obj = $class->SUPER::new($type, $value);
13 $obj->{data} = $value || [],
14 $obj->{shell_command} => 0,
15 $obj->{select_input_source} => 0,
16 $obj->{select_input_source_data} => '',
17 $obj->{set_variable} => 0,
18 18 ▶ $obj->{mouse_key} => 0,
Condition50%1/2
$value || []
l!l
018
MC/DC0%0/1
$value || []
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
19 return $obj;
20 }
21  
22 sub add_key_code {
23 77 ▶ my $s = shift;
Subroutine add_key_code: called CC=15 SCAR=27.1
Pod documented
24 77 my @key_codes;
25 77 ▶ if (ref $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s) { } 77 0 77
26 77 @key_codes = @_;
27 } else {
28 0 @key_codes = ($s, @_);
29 0 $s = $main::current_action;
30 }
31 77 my $last_arg = $key_codes[-1];
32 77 my $input_type = 'key_code';
33 77 ▶ if ($last_arg && $last_arg =~ /^any|consumer_key_code|pointing_button$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($last_arg and $last_arg =~ /^any|consumer_key_code|pointing_button$/) 12 65 77
Condition100%3/3
$last_arg and $last_arg =~ /^any|consumer_key_code|pointing_button$/
!ll&&!rl&&r
65912
MC/DC100%2/2
$last_arg and $last_arg =~ /^any|consumer_key_code|pointing_button$/
$last_arg $last_arg =~ /^any|consumer_key_code|pointing_button$/
Truth table100%3/3
A and B
A= $last_argB= $last_arg =~ /^any|consumer_key_code|pointing_button$/
ABresult
0X0
100
111
34 12 $input_type = $last_arg;
35 12 pop @key_codes;
36 }
37 77 ▶ croak 'No key code passed' if !@key_codes;
Branch: 1 branch
BranchTrueFalseTotal
unless @key_codes 6 71 77
38 71 ▶ croak 'You can only set one key_code, consumer_key_code, pointing_button or any' if ($s->{code_set});
Branch: 1 branch
BranchTrueFalseTotal
if $s->{"code_set"} 0 71 71
39 #TODO: validate $key_code
40  
41 71 $s->_is_exclusive($input_type);
42  
43 71 foreach my $key_code (@key_codes) {
44 89 my %hash;
45 my $letter_code;
46 89 my $ms;
47 89 ▶ if ($key_code =~ /-([A-Z])|(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_code =~ /-([A-Z])|(\d+)$/) 24 65 89
48 24 $letter_code = $1;
49 24 $ms = $2;
50 24 $key_code =~ s/-(.*?)$//;
51 }
52  
53 89 $hash{$input_type} = $key_code;
54 89 ▶ $hash{lazy} = JSON::true if $letter_code && $letter_code eq 'L';
Branch: 1 branch
BranchTrueFalseTotal
if $letter_code and $letter_code eq "L" 6 83 89
Condition100%3/3
$letter_code and $letter_code eq "L"
!ll&&!rl&&r
71126
MC/DC100%2/2
$letter_code and $letter_code eq "L"
$letter_code $letter_code eq "L"
Truth table100%3/3
A and B
A= $letter_codeB= $letter_code eq "L"
ABresult
0X0
100
111
55 89 ▶ $hash{halt} = JSON::true if $letter_code && $letter_code eq 'H';
Branch: 1 branch
BranchTrueFalseTotal
if $letter_code and $letter_code eq "H" 6 83 89
Condition100%3/3
$letter_code and $letter_code eq "H"
!ll&&!rl&&r
71126
MC/DC100%2/2
$letter_code and $letter_code eq "H"
$letter_code $letter_code eq "H"
Truth table100%3/3
A and B
A= $letter_codeB= $letter_code eq "H"
ABresult
0X0
100
111
56 89 ▶ $hash{repeat} = JSON::true if $letter_code && $letter_code eq 'R';
Branch: 1 branch
BranchTrueFalseTotal
if $letter_code and $letter_code eq "R" 6 83 89
Condition100%3/3
$letter_code and $letter_code eq "R"
!ll&&!rl&&r
71126
MC/DC100%2/2
$letter_code and $letter_code eq "R"
$letter_code $letter_code eq "R"
Truth table100%3/3
A and B
A= $letter_codeB= $letter_code eq "R"
ABresult
0X0
100
111
57 89 ▶ $hash{hold_down_milliseconds} = $ms if $ms;
Branch: 1 branch
BranchTrueFalseTotal
if $ms 6 83 89
58 89 $s->_push_data(\%hash);
59 89 $s->{last_key_code} = \%hash;
60 }
61 }
62  
63 sub _push_data {
64 119 ▶ my $s = shift;
Subroutine _push_data: called CC=3 SCAR=11.0
65 119 my $data = shift;
66 119 ▶ if ($s->{def_name} eq 'to_delayed_action') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'def_name'} eq 'to_delayed_action') { } 38 81 119
67 38 ▶ if ($s->{delayed_type} eq 'invoked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'delayed_type'} eq 'invoked') { } 19 19 38
68 19 push @{$s->{data}{to_if_invoked}}, $data;
69 } else {
70 19 push @{$s->{data}{to_if_canceled}}, $data;
71 }
72 } else {
73 81 push @{$s->{data}}, $data;
74 }
75 }
76  
77 sub add_shell_command {
78 6 ▶ my $s = shift;
Subroutine add_shell_command: called CC=1 SCAR=0.0
Pod documented
79  
80 6 $s->_is_exclusive('shell_command');
81 6 my $value = shift;
82 6 my %hash;
83 6 $hash{shell_command} = $value;
84 6 $s->_push_data(\%hash);
85 }
86  
87 sub add_select_input_source {
88 12 ▶ my $s = shift;
Subroutine add_select_input_source: called CC=4 SCAR=14.5
Pod documented
89 12 $s->_is_exclusive('select_input_source');
90 12 my $option = shift;
91 12 my $value = shift;
92 12 ▶ if ($option !~ /^language|input_source_id|input_mode_id$/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($option =~ /^language|input_source_id|input_mode_id$/) 0 12 12
93 0 croak "Invalid option: $option";
94 }
95  
96 #TODO: determing if key alredy exists
97 # find existing hash ref
98 12 my $existing = $s->{select_input_source_data};
99 12 ▶ my $select_input_source = $existing || { };
Condition50%1/2
$existing || {}
l!l
012
MC/DC0%0/1
$existing || {}
$existing
Truth table50%1/2
A
A= $existing
Aresult
11
00
100  
101 12 $select_input_source->{$option} = $value;
102 12 ▶ $s->_push_data( { select_input_source => $select_input_source } ) if !$existing;
Branch: 1 branch
BranchTrueFalseTotal
if not $existing 12 0 12
103 }
104  
105 sub add_set_variable {
106 6 ▶ my $s = shift;
Subroutine add_set_variable: called CC=3 SCAR=11.1
Pod documented
107 6 $s->_is_exclusive('set_variable');
108 6 my $name = shift;
109 6 ▶ croak 'No name passed' unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 6 6
110 6 my $value = shift;
111 6 ▶ croak 'No value passed' unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 6 6
112  
113 6 my %hash;
114 6 $hash{set_variable}{name} = $name;
115 6 $hash{set_variable}{value} = $value;
116 6 $s->_push_data(\%hash);
117 }
118  
119 sub add_mouse_key {
120 6 ▶ my $s = shift;
Subroutine add_mouse_key: called CC=3 SCAR=11.1
Pod documented
121 6 $s->_is_exclusive('mouse_key');
122 6 my $name = shift;
123 6 ▶ croak 'No name passed' unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 6 6
124 6 my $value = shift;
125 6 ▶ croak 'No value passed' unless $value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 6 6
126  
127 #TODO: make sure $names have not been set already
128 #TODO: make sure names are valid
129 6 my %hash;
130 6 $hash{mouse_key}{$name} = $value;
131 6 $s->_push_data(\%hash);
132 }
133  
134 sub add_modifiers {
135 12 ▶ my $s = shift;
Subroutine add_modifiers: called CC=3 SCAR=11.1
Pod documented
136 12 my $lkc = $s->{last_key_code};
137 12 ▶ croak 'Nothing to attach the modifiers to' if !$lkc;
Branch: 1 branch
BranchTrueFalseTotal
unless $lkc 6 6 12
138 6 my $existing = [];
139 6 ▶ if (exists $lkc->{modifiers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lkc->{"modifiers"}) 0 6 6
140 0 $existing = $lkc->{modifiers};
141 }
142  
143 #TODO: check that modifiers are valid
144 6 my @modifiers = @_;
145 6 push @$existing, @modifiers;
146 6 $lkc->{modifiers} = $existing;
147 }
148  
149 # ABSTRACT: To action
150  
151 10 1;
152  
153 __END__
« Karabiner/Manipulator/Actions/From.pm ↑ Summary Karabiner.pm »