Karabiner/Manipulator/Actions/From.pm

filter: Statementstmt 74.1% 63 / 85 Branchbran 37.5% 15 / 40 Conditioncond 38.4% 5 / 13 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 92.3% 12 / 13 Podpod 71.4% 5 / 7 totaltotal 60.8% 101 / 166 CC 27 SCAR 37.3
CC
27
Cov
60%
add_simultaneous_options
132.0
add_key_code
12.7
add_simultaneous
5.0
CRAP 41.6
↑ Summary Karabiner/Manipulator/Actions/To.pm »
1 package JSON::Karabiner::Manipulator::Actions::From ;
2 5 $JSON::Karabiner::Manipulator::Actions::From::VERSION = '0.018';
3 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use parent 'JSON::Karabiner::Manipulator::Actions';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9  
10 8 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
11 8 my $class = shift;
12 8 my ($type, $value) = @_;
13 8 my $obj = $class->SUPER::new($type, $value);
14 $obj->{data} = $value || {},
15 8 ▶ $obj->{has_mandatory_modifiers} = 0;
Condition50%1/2
$value || {}
l!l
08
MC/DC0%0/1
$value || {}
$value
Truth table50%1/2
A
A= $value
Aresult
11
00
16 8 $obj->{has_optional_modifiers} = 0;
17 8 $obj->{has_code_set} = 0;
18 8 return $obj;
19 }
20  
21 9 ▶sub add_key_code {
Subroutine add_key_code: called CC=10 SCAR=25.4
Pod documented
22 9 my $s = shift;
23 9 my @key_codes = @_;
24 9 my $last_arg = $key_codes[-1];
25 9 my $input_type = 'key_code';
26 9 ▶ 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$/) 4 5 9
Condition66%2/3
$last_arg and $last_arg =~ /^any|consumer_key_code|pointing_button$/
!ll&&!rl&&r
054
MC/DC50%1/2
$last_arg and $last_arg =~ /^any|consumer_key_code|pointing_button$/
$last_arg $last_arg =~ /^any|consumer_key_code|pointing_button$/
Truth table66%2/3
A and B
A= $last_argB= $last_arg =~ /^any|consumer_key_code|pointing_button$/
ABresult
0X0
100
111
27 4 $input_type = $last_arg;
28 4 pop @key_codes;
29 }
30 9 ▶ croak 'No key code passed' if !@key_codes;
Branch: 1 branch
BranchTrueFalseTotal
unless @key_codes 0 9 9
31 9 ▶ 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"} 4 5 9
32 #TODO: validate $key_code
33  
34 5 ▶ if (scalar @key_codes > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @key_codes > 1) 0 5 5
35 0 croak 'Only one input type can be entered for "from" defintions';
36 }
37 5 my ($letter_code, $ms);
38 5 ▶ if ($key_codes[0] =~ /-([A-Z])|(\d+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($key_codes[0] =~ /-([A-Z])|(\d+)$/) 0 5 5
39 0 $letter_code = $1;
40 0 $ms = $2;
41 }
42 5 ▶ croak 'Specifiers such as lazy, repeat, halt, and hold_down_in_milliseconds do not apply in "from" actions'
Branch: 1 branch
BranchTrueFalseTotal
if $letter_code or $ms 0 5 5
Condition33%1/3
$letter_code or $ms
l!l&&r!l&&!r
005
MC/DC0%0/2
$letter_code or $ms
$letter_code $ms
Truth table33%1/3
A or B
A= $letter_codeB= $ms
ABresult
1X1
011
000
43 if $letter_code || $ms;
44 5 ▶ if (exists $s->{data}{$input_type}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $s->{"data"}{$input_type}) 0 5 5
45 0 croak 'From action already has that property';
46 }
47 5 $s->{data}{$input_type} = $key_codes[0];
48  
49 5 $s->{code_set} = 1;
50 }
51  
52 1 ▶sub add_any {
Subroutine add_any: called CC=2 SCAR=7.1
Pod documented
53 1 my $s = shift;
54 1 ▶ croak 'You must pass a value' if !$_[0];
Branch: 1 branch
BranchTrueFalseTotal
unless $_[0] 0 1 1
55 1 $s->add_key_code(@_, 'any');
56 }
57  
58 1 ▶sub add_optional_modifiers {
Subroutine add_optional_modifiers: called CC=1 SCAR=0.0
Pod documented
59 1 my $s = shift;
60 1 $s->_add_modifiers('optional', @_);
61 }
62  
63 2 ▶sub add_mandatory_modifiers {
Subroutine add_mandatory_modifiers: called CC=1 SCAR=0.0
Pod documented
64 2 my $s = shift;
65 2 $s->_add_modifiers('mandatory', @_);
66 }
67  
68 3 ▶sub _add_modifiers {
Subroutine _add_modifiers: called CC=2 SCAR=6.9
69 3 my $s = shift;
70 3 my $mod_type = shift;
71 3 my $values = \@_;
72 3 ▶ croak "This action already has $mod_type modifiers" if $s->{"has_${mod_type}_modifiers"};
Branch: 1 branch
BranchTrueFalseTotal
if $$s{"has_${mod_type}_modifiers"} 1 2 3
73  
74 2 $s->{data}{modifiers}{$mod_type} = \@_;
75 2 $s->{"has_${mod_type}_modifiers"} = 1;
76 }
77  
78 2 ▶sub add_simultaneous {
Subroutine add_simultaneous: called CC=5 SCAR=16.2
Pod undocumented
79 2 my $s = shift;
80 2 my @keys = @_;
81 2 ▶ my $key_type = shift @keys if $keys[0] =~ /key_code|pointing|any/i;
Branch: 1 branch
BranchTrueFalseTotal
if $keys[0] =~ /key_code|pointing|any/i 2 0 2
82 2 my @hashes;
83 2 ▶ if (defined $s->{data}{simultaneous}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{"data"}{"simultaneous"}) 1 1 2
84 1 @hashes = @{$s->{data}{simultaneous}};
85 }
86 2 foreach my $key ( @keys ) {
87 6 ▶ push @hashes, { $key_type || 'key_code' => $key };
Condition50%1/2
$key_type || 'key_code'
l!l
60
MC/DC0%0/1
$key_type || 'key_code'
$key_type
Truth table50%1/2
A
A= $key_type
Aresult
11
00
88 }
89 2 $s->{data}{simultaneous} = \@hashes ;
90 }
91  
92 0 ▶sub add_simultaneous_options {
Subroutine add_simultaneous_options: not called CC=11 SCAR=48.8
Pod undocumented
93 0 my $s = shift;
94 0 my $option = shift;
95 0 my @values = @_;
96 0 my @allowed_options = qw ( detect_key_down_uninterruptedly
97 key_down_order key_up_when to_after_key_up );
98 0 my $exists = grep { $_ = $option } @allowed_options;
99 0 ▶ croak "Simultaneous option is not a valid option" if $exists;
Branch: 1 branch
BranchTrueFalseTotal
if $exists 0 0 0
100 0 my $value = $values[0];
101  
102 #TODO: detect if option already exists and die if it does
103 #TODO: offer suggestions if error thrown
104 0 ▶ croak "Simultaneous option $option has already been set" if ($s->{"so_${option}_is_set"} == 1);
Branch: 1 branch
BranchTrueFalseTotal
if $$s{"so_${option}_is_set"} == 1 0 0 0
105  
106 0 ▶ if ($option eq 'detect_key_down_uninterruptedly') {
Branch: 4 branches
BranchTrueFalseTotal
if ($option eq 'detect_key_down_uninterruptedly') { } 0 0 0
elsif ($option eq 'key_down_order' or $option eq 'key_up_order') { } 0 0 0
elsif ($option eq 'key_up_when') { } 0 0 0
elsif ($option eq 'to_after_key_up') { } 0 0 0
107 0 ▶ if ($value !~ /true|false/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /true|false/) 0 0 0
108 0 croak "$value is not a valid option for $option";
109 }
110 ▶ } elsif ($option eq 'key_down_order' || $option eq 'key_up_order') {
Condition0%0/3
$option eq "key_down_order" or $option eq "key_up_order"
l!l&&r!l&&!r
000
MC/DC0%0/2
$option eq "key_down_order" or $option eq "key_up_order"
$option eq "key_down_order" $option eq "key_up_order"
Truth table0%0/3
A or B
A= $option eq "key_down_order"B= $option eq "key_up_order"
ABresult
1X1
011
000
111 0 ▶ if ($value !~ /insenstive|strict|strict_inverse/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /insenstive|strict|strict_inverse/) 0 0 0
112 0 croak "$value is not a valid option for $option";
113 }
114 } elsif ($option eq 'key_up_when') {
115 0 ▶ if ($value !~ /any|when/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($value =~ /any|when/) 0 0 0
116 0 croak "$value is not a valid option for $option";
117 }
118 } elsif ($option eq 'to_after_key_up') {
119 #TODO: Figure out how this is supposed to work
120 0 croak 'This option is currently unspported by JSON::Karabiner';
121 }
122  
123 0 $s->{"so_${option}_is_set"} = 1;
124  
125 }
126  
127 # ABSTRACT: From object definition
128  
129 5 1;
130  
131 __END__
↑ Summary Karabiner/Manipulator/Actions/To.pm »