Karabiner/Manipulator/Actions/To.pm

filter: Statementstmt 96.1% 101 / 105 Branchbran 77.5% 31 / 40 Conditioncond 87.5% 14 / 16 MC/DCmcdc 80.0% 8 / 10 Subroutinesub 100% 13 / 13 Podpod 100% 7 / 7 totaltotal 91.1% 174 / 191 CC 28 SCAR 20.0
CC
28
Cov
91%
add_key_code
15.1
add_select_input_source
4.2
add_set_variable
4.0
CRAP 7.4
« Karabiner/Manipulator/Actions/From.pm ↑ Summary Karabiner/Manipulator.pm »
1 package JSON::Karabiner::Manipulator::Actions::To ;
2 12 $JSON::Karabiner::Manipulator::Actions::To::VERSION = '0.018';
3 12 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 12 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 12 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 12 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 12 ▶use parent 'JSON::Karabiner::Manipulator::Actions';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 21 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
10 21 my $class = shift;
11 21 my ($type, $value) = @_;
12 21 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 21 ▶ $obj->{mouse_key} => 0,
Condition50%1/2
$value || []
l!l
021
MC/DC0%0/1
$value || []
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
19 return $obj;
20 }
21  
22 78 ▶sub add_key_code {
Subroutine add_key_code: called CC=15 SCAR=27.1
Pod documented
23 78 my $s = shift;
24 78 my @key_codes;
25 78 ▶ if (ref $s) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $s) { } 78 0 78
26 78 @key_codes = @_;
27 } else {
28 0 @key_codes = ($s, @_);
29 0 $s = $main::current_action;
30 }
31 78 my $last_arg = $key_codes[-1];
32 78 my $input_type = 'key_code';
33 78 ▶ 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 66 78
Condition100%3/3
$last_arg and $last_arg =~ /^any|consumer_key_code|pointing_button$/
!ll&&!rl&&r
66012
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 78 ▶ croak 'No key code passed' if !@key_codes;
Branch: 1 branch
BranchTrueFalseTotal
unless @key_codes 6 72 78
38 72 ▶ 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 72 72
39 #TODO: validate $key_code
40  
41 72 $s->_is_exclusive($input_type);
42  
43 72 foreach my $key_code (@key_codes) {
44 90 my %hash;
45 my $letter_code;
46 90 my $ms;
47 90 ▶ if ($key_code =~ /-([A-Z])|-(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_code =~ /-([A-Z])|-(\d+)$/) 24 66 90
48 24 $letter_code = $1;
49 24 $ms = $2;
50 24 $key_code =~ s/-(.*?)$//;
51 }
52  
53 90 $hash{$input_type} = $key_code;
54 90 ▶ $hash{lazy} = JSON::true if $letter_code && $letter_code eq 'L';
Branch: 1 branch
BranchTrueFalseTotal
if $letter_code and $letter_code eq "L" 6 84 90
Condition100%3/3
$letter_code and $letter_code eq "L"
!ll&&!rl&&r
72126
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 90 ▶ $hash{halt} = JSON::true if $letter_code && $letter_code eq 'H';
Branch: 1 branch
BranchTrueFalseTotal
if $letter_code and $letter_code eq "H" 6 84 90
Condition100%3/3
$letter_code and $letter_code eq "H"
!ll&&!rl&&r
72126
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 90 ▶ $hash{repeat} = JSON::true if $letter_code && $letter_code eq 'R';
Branch: 1 branch
BranchTrueFalseTotal
if $letter_code and $letter_code eq "R" 6 84 90
Condition100%3/3
$letter_code and $letter_code eq "R"
!ll&&!rl&&r
72126
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 90 ▶ $hash{hold_down_milliseconds} = $ms if $ms;
Branch: 1 branch
BranchTrueFalseTotal
if $ms 6 84 90
58 90 $s->_push_data(\%hash);
59 90 $s->{last_key_code} = \%hash;
60 }
61 }
62  
63 121 ▶sub _push_data {
Subroutine _push_data: called CC=3 SCAR=11.0
64 121 my $s = shift;
65 121 my $data = shift;
66 121 ▶ if ($s->{def_name} eq 'to_delayed_action') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'def_name'} eq 'to_delayed_action') { } 39 82 121
67 39 ▶ if ($s->{delayed_type} eq 'invoked') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s->{'delayed_type'} eq 'invoked') { } 20 19 39
68 20 push @{$s->{data}{to_if_invoked}}, $data;
69 } else {
70 19 push @{$s->{data}{to_if_canceled}}, $data;
71 }
72 } else {
73 82 push @{$s->{data}}, $data;
74 }
75 }
76  
77 6 ▶sub add_shell_command {
Subroutine add_shell_command: called CC=1 SCAR=0.0
Pod documented
78 6 my $s = shift;
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 12 ▶sub add_select_input_source {
Subroutine add_select_input_source: called CC=4 SCAR=14.5
Pod documented
88 12 my $s = shift;
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 7 ▶sub add_set_variable {
Subroutine add_set_variable: called CC=4 SCAR=13.9
Pod documented
106 7 my $s = shift;
107 7 $s->_is_exclusive('set_variable');
108 7 my $name = shift;
109 7 ▶ croak 'No name passed' unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 7 7
110 7 my $value = shift;
111 7 ▶ croak 'No value passed' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 7 7
112  
113 7 ▶ if ($value =~ /^\d+$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($value =~ /^\d+$/) 1 6 7
114 1 $value = $value + 0;
115 }
116  
117 7 my %hash;
118 7 $hash{set_variable}{name} = $name;
119 7 $hash{set_variable}{value} = $value;
120 7 $s->_push_data(\%hash);
121 }
122  
123 6 ▶sub add_mouse_key {
Subroutine add_mouse_key: called CC=3 SCAR=11.1
Pod documented
124 6 my $s = shift;
125 6 $s->_is_exclusive('mouse_key');
126 6 my $name = shift;
127 6 ▶ croak 'No name passed' unless $name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 6 6
128 6 my $value = shift;
129 6 ▶ croak 'No value passed' unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 6 6
130  
131 #TODO: make sure $names have not been set already
132 #TODO: make sure names are valid
133 6 my %hash;
134 6 $hash{mouse_key}{$name} = $value;
135 6 $s->_push_data(\%hash);
136 }
137  
138 12 ▶sub add_modifiers {
Subroutine add_modifiers: called CC=3 SCAR=11.1
Pod documented
139 12 my $s = shift;
140 12 my $lkc = $s->{last_key_code};
141 12 ▶ croak 'Nothing to attach the modifiers to' if !$lkc;
Branch: 1 branch
BranchTrueFalseTotal
unless $lkc 6 6 12
142 6 my $existing = [];
143 6 ▶ if (exists $lkc->{modifiers} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $lkc->{"modifiers"}) 0 6 6
144 0 $existing = $lkc->{modifiers};
145 }
146  
147 #TODO: check that modifiers are valid
148 6 my @modifiers = @_;
149 6 push @$existing, @modifiers;
150 6 $lkc->{modifiers} = $existing;
151 }
152  
153 # ABSTRACT: To action object
154  
155 12 1;
156  
157 __END__
« Karabiner/Manipulator/Actions/From.pm ↑ Summary Karabiner/Manipulator.pm »