Karabiner/Manipulator/Actions/To.pm

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