Karabiner/Manipulator.pm

filter: Statementstmt 58.4% 45 / 77 Branchbran 21.4% 6 / 28 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 9 / 12 Podpod 83.3% 5 / 6 totaltotal 52.8% 65 / 123 CC 15 SCAR 32.1
CC
15
Cov
49%
add_parameter
72.0
add_condition
12.0
add_description
6.0
CRAP 24.9
« Karabiner/Manipulator/Actions/From.pm ↑ Summary Karabiner/Manipulator/Conditions/Event_changed_if.pm »
1 package JSON::Karabiner::Manipulator ;
2 15 $JSON::Karabiner::Manipulator::VERSION = '0.008';
3 15 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 15 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 15 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub new {
8 1 ▶ my $class = shift;
Subroutine new: called CC=1 SCAR=0.0
Pod documented
9 1 my $self = {
10 actions => {},
11 _disable_validity_tests => 0,
12 };
13 1 bless $self, $class;
14 1 return $self;
15 }
16  
17 sub add_action {
18 2 ▶ my $s = shift;
Subroutine add_action: called CC=2 SCAR=6.9
Pod documented
19 2 my $type = shift;
20 2 ▶ croak 'To add a action, you must tell me which kind you\'d like to add' if !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 2 2
21  
22 2 my $uctype = ucfirst($type);
23 2 my $package = "JSON::Karabiner::Manipulator::Actions::" . $uctype;
24 2 eval "require $package";
25 2 my $action = $package->new($type);
26 2 my %hash = %{$s->{actions}};
27 2 $type = $action->{def_name};
28 2 $hash{$type} = $action->{data};
29 2 $s->{actions} = \%hash;
30 2 return $action;
31 }
32  
33 sub add_condition {
34 0 ▶ my $s = shift;
Subroutine add_condition: not called CC=3 SCAR=24.8
Pod documented
35 0 my $type = shift;
36 0 ▶ croak 'To add a condition, you must tell me which kind you\'d like to add' if !$type;
Branch: 1 branch
BranchTrueFalseTotal
unless $type 0 0 0
37  
38 0 my $uctype = ucfirst($type);
39 0 my $package = "JSON::Karabiner::Manipulator::Conditions::" . $uctype;
40 0 eval "require $package";
41 0 my $condition = $package->new($type);
42 0 ▶ if (defined $s->{actions}{conditions}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $s->{'actions'}{'conditions'}) { } 0 0 0
43 0 push @{$s->{actions}{conditions}}, $condition;
44 } else {
45 0 $s->{actions}{conditions} = [ $condition ];
46 }
47 0 return $condition;
48 }
49  
50 sub add_description {
51 0 ▶ my $s = shift;
Subroutine add_description: not called CC=2 SCAR=17.9
Pod documented
52 0 my $desc = shift;
53  
54 0 ▶ croak 'To add a description, you must provide one' if !$desc;
Branch: 1 branch
BranchTrueFalseTotal
unless $desc 0 0 0
55 0 $s->{actions}{description} = $desc;
56 }
57  
58 sub add_parameter {
59 0 ▶ my $s = shift;
Subroutine add_parameter: not called CC=8 SCAR=42.8
Pod documented
60 0 my $param = shift;
61 0 my $value = shift;
62 0 ▶ croak 'To add a parameter, you must tell me which kind you\'d like to add' if !$param;
Branch: 1 branch
BranchTrueFalseTotal
unless $param 0 0 0
63 0 ▶ croak 'To add a parameter, you must provide a value' if !$value;
Branch: 1 branch
BranchTrueFalseTotal
unless $value 0 0 0
64  
65 0 my @acceptable_values = qw( to_if_alone_timeout_milliseconds
66 alone_timeout
67 alone
68 to_if_held_down_threshold_milliseconds
69 held_down_threshold
70 down_threshold
71 held_down
72 down
73 to_delayed_action_delay_milliseconds
74 delayed_action_delay
75 action_delay
76 delay
77 simultaneous_threshold_milliseconds
78 simultaneous_threshold
79 simultaneous
80 );
81  
82 0 my $param_exists = grep { $param eq $_ } @acceptable_values;
83 0 ▶ croak "'$param' in an unrecognzed parameter" unless $param_exists;
Branch: 1 branch
BranchTrueFalseTotal
unless $param_exists 0 0 0
84  
85 # get param full name
86 0 ▶ if ($param =~ /alone/) {
Branch: 4 branches
BranchTrueFalseTotal
if ($param =~ /alone/) { } 0 0 0
elsif ($param =~ /down/) { } 0 0 0
elsif ($param =~ /delay/) { } 0 0 0
elsif ($param =~ /simultaneous/) { } 0 0 0
87 0 $param = 'to_if_alone_timeout_milliseconds';
88 } elsif ($param =~ /down/) {
89 0 $param = 'to_if_held_down_threshold_milliseconds';
90 } elsif ($param =~ /delay/) {
91 0 $param = 'to_delayed_action_delay_milliseconds';
92 } elsif ($param =~ /simultaneous/) {
93 0 $param = 'simultaneous_threshold_milliseconds';
94 }
95  
96 0 $s->{actions}{parameters}{"basic.$param"} = $value;
97 }
98  
99 sub TO_JSON {
100 4 ▶ my $obj = shift;
Subroutine TO_JSON: called CC=2 SCAR=6.9
Pod undocumented
101 #TODO: Change this under certain conditions
102 4 $obj->{actions}{type} = 'basic';
103 4 ▶ $obj->_do_validity_checks($obj->{actions}) unless $obj->{_disable_validity_tests};
Branch: 1 branch
BranchTrueFalseTotal
unless $obj->{"_disable_validity_tests"} 3 1 4
104 1 return $obj->{actions};
105 }
106  
107 sub _do_validity_checks {
108 15 ▶ use Data::Dumper qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
109 3 ▶ my $s = shift;
Subroutine _do_validity_checks: called CC=1 SCAR=0.0
110 3 my $actions = shift;
111 3 my $from = $actions->{from};
112 3 $s->_do_from_validity_checks($from);
113 }
114  
115  
116 sub _do_from_validity_checks {
117 3 ▶ my $s = shift;
Subroutine _do_from_validity_checks: called CC=3 SCAR=11.2
118 3 my $from = shift;
119  
120 3 ▶ if (! defined $from) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $from) 2 1 3
121 2 croak "No 'from' action found in the manipulator. You must add a 'from' action.'";
122 }
123  
124 1 ▶ if (! %$from) {
Branch: 1 branch
BranchTrueFalseTotal
unless (%$from) 1 0 1
125 1 croak "The 'from' action is empty. Perform methods on the 'from' action to tell it how to behave.";
126 }
127  
128 0 return;
129  
130 # my @from_keys = keys %$from;
131 # my $has_key_code = grep { $_ =~ /^any|consumer_key_code|key_code$/ } @from_keys;
132 # print Dumper \@from_keys;
133 # if (!$has_key_code && grep { $_ =~ /modifiers/ } @from_keys) {
134 # print Dumper 'aksjdkajsdf';
135 # croak "You cannot have modifiers without anything to modify in a 'from' action.";
136 # }
137 }
138  
139 # ABSTRACT: manipulator object for containing and outputting its data
140  
141 15 1;
142  
143 __END__
« Karabiner/Manipulator/Actions/From.pm ↑ Summary Karabiner/Manipulator/Conditions/Event_changed_if.pm »