line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JSON::Karabiner::Manipulator ; |
2
|
|
|
|
|
|
|
$JSON::Karabiner::Manipulator::VERSION = '0.016'; |
3
|
18
|
|
|
18
|
|
249037
|
use strict; |
|
18
|
|
|
|
|
68
|
|
|
18
|
|
|
|
|
550
|
|
4
|
18
|
|
|
18
|
|
93
|
use warnings; |
|
18
|
|
|
|
|
43
|
|
|
18
|
|
|
|
|
418
|
|
5
|
18
|
|
|
18
|
|
86
|
use Carp; |
|
18
|
|
|
|
|
50
|
|
|
18
|
|
|
|
|
1009
|
|
6
|
18
|
|
|
18
|
|
143
|
use Exporter; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
3637
|
|
7
|
|
|
|
|
|
|
our @EXPORT = qw'new_manipulator add_action add_description add_condition add_parameter add_key_code |
8
|
|
|
|
|
|
|
add_key_code add_any add_optional_modifiers add_mandatory_modifiers add_simultaneous add_simultaneous_options add_consumer_key_code add_pointing_button add_shell_command add_select_input_source add_set_variable add_mouse_key add_modifiers |
9
|
|
|
|
|
|
|
add_identifier add_description add_value add_bundle_identifiers add_file_path add_input_source add_keyboard_types add_variable add_description _dump_json _fake_write_file write_file'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub import { |
12
|
2
|
|
|
2
|
|
27
|
strict->import; |
13
|
2
|
|
|
|
|
29
|
warnings->import; |
14
|
2
|
|
|
|
|
4112
|
goto &Exporter::import |
15
|
|
|
|
|
|
|
} |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
sub new_manipulator { |
18
|
30
|
|
|
30
|
0
|
4432
|
my $class = 'JSON::Karabiner::Manipulator'; |
19
|
30
|
100
|
|
|
|
168
|
shift if $_[0] =~ /^JSON::Karabiner::Manipulator$/; |
20
|
|
|
|
|
|
|
|
21
|
30
|
|
|
|
|
74
|
my @kb_obj_args = @_; |
22
|
30
|
|
|
|
|
192
|
my $self = { |
23
|
|
|
|
|
|
|
actions => {}, |
24
|
|
|
|
|
|
|
_disable_validity_tests => 0, |
25
|
|
|
|
|
|
|
_kb_obj_args => \@kb_obj_args, |
26
|
|
|
|
|
|
|
_fake_write_flag => 0, |
27
|
|
|
|
|
|
|
}; |
28
|
30
|
|
|
|
|
74
|
bless $self, $class; |
29
|
|
|
|
|
|
|
{ |
30
|
18
|
|
|
18
|
|
149
|
no warnings 'once'; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
3486
|
|
|
30
|
|
|
|
|
48
|
|
31
|
30
|
|
|
|
|
69
|
$main::current_manip = $self; |
32
|
|
|
|
|
|
|
} |
33
|
30
|
|
|
|
|
119
|
return $self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub AUTOLOAD { |
37
|
19
|
|
|
19
|
|
1991
|
our $AUTOLOAD; |
38
|
19
|
|
|
|
|
42
|
my $program = $AUTOLOAD; |
39
|
19
|
|
|
|
|
123
|
my ($func) = $program =~ /.*::(.*)$/; |
40
|
19
|
|
|
|
|
95
|
my @action_functions = qw (add_key_code add_any add_optional_modifiers add_mandatory_modifiers add_simultaneous add_simultaneous_options add_consumer_key_code add_pointing_button add_shell_command add_select_input_source add_set_variable add_mouse_key add_modifiers); |
41
|
|
|
|
|
|
|
|
42
|
19
|
|
|
|
|
46
|
my $is_action_function = grep { $_ eq $func } @action_functions; |
|
247
|
|
|
|
|
421
|
|
43
|
19
|
100
|
|
|
|
63
|
if ($is_action_function) { |
44
|
6
|
|
|
|
|
9
|
my $current_action; |
45
|
|
|
|
|
|
|
{ |
46
|
18
|
|
|
18
|
|
141
|
no warnings 'once'; |
|
18
|
|
|
|
|
36
|
|
|
18
|
|
|
|
|
2156
|
|
|
6
|
|
|
|
|
10
|
|
47
|
6
|
|
|
|
|
10
|
$current_action = $main::current_action; |
48
|
|
|
|
|
|
|
} |
49
|
6
|
|
|
|
|
24
|
$current_action->$func(@_); |
50
|
6
|
|
|
|
|
24
|
return; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
13
|
|
|
|
|
71
|
my @condition_functions = qw(add_identifier add_description add_value add_bundle_identifiers add_file_path add_input_source add_keyboard_types add_variable add_description); |
54
|
|
|
|
|
|
|
|
55
|
13
|
|
|
|
|
30
|
my $is_condition_function = grep { $_ eq $func } @condition_functions; |
|
117
|
|
|
|
|
231
|
|
56
|
13
|
50
|
|
|
|
566
|
if ($is_condition_function) { |
57
|
0
|
|
|
|
|
0
|
my $current_condition; |
58
|
|
|
|
|
|
|
{ |
59
|
18
|
|
|
18
|
|
143
|
no warnings 'once'; |
|
18
|
|
|
|
|
39
|
|
|
18
|
|
|
|
|
20218
|
|
|
0
|
|
|
|
|
0
|
|
60
|
0
|
|
|
|
|
0
|
$current_condition = $main::current_condition; |
61
|
|
|
|
|
|
|
} |
62
|
0
|
|
|
|
|
0
|
$current_condition->$func(@_); |
63
|
0
|
|
|
|
|
0
|
return; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub _get_args { |
69
|
39
|
|
|
39
|
|
107
|
my @args = @_; |
70
|
39
|
50
|
|
|
|
121
|
croak "No args passed" unless @args; |
71
|
|
|
|
|
|
|
|
72
|
39
|
|
|
|
|
72
|
my $s = shift; |
73
|
39
|
|
|
|
|
66
|
my $type; |
74
|
39
|
100
|
|
|
|
105
|
if (ref $s) { |
75
|
33
|
|
|
|
|
65
|
$type = shift; |
76
|
|
|
|
|
|
|
} else { |
77
|
6
|
|
|
|
|
12
|
$type = $s; |
78
|
6
|
|
|
|
|
9
|
$s = $main::current_manip; |
79
|
|
|
|
|
|
|
} |
80
|
39
|
|
|
|
|
131
|
return ($s, $type, @_); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub add_action { |
84
|
30
|
|
|
30
|
1
|
3458
|
my ($s, $type) = _get_args(@_); |
85
|
30
|
50
|
|
|
|
81
|
croak 'To add a action, you must tell me which kind you\'d like to add' if !$type; |
86
|
|
|
|
|
|
|
|
87
|
30
|
|
|
|
|
112
|
my $uctype = ucfirst($type); |
88
|
30
|
|
|
|
|
90
|
my $package = "JSON::Karabiner::Manipulator::Actions::" . $uctype; |
89
|
30
|
|
|
|
|
2171
|
eval "require $package"; |
90
|
30
|
|
|
|
|
265
|
my $action = $package->new($type); |
91
|
29
|
|
|
|
|
70
|
my %hash = %{$s->{actions}}; |
|
29
|
|
|
|
|
146
|
|
92
|
29
|
|
|
|
|
70
|
$type = $action->{def_name}; |
93
|
29
|
|
|
|
|
72
|
$hash{$type} = $action->{data}; |
94
|
29
|
|
|
|
|
82
|
$s->{actions} = \%hash; |
95
|
29
|
|
|
|
|
103
|
return $action; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
sub add_condition { |
99
|
7
|
|
|
7
|
1
|
2183
|
my ($s, $type) = _get_args(@_); |
100
|
7
|
50
|
|
|
|
18
|
croak 'To add a condition, you must tell me which kind you\'d like to add' if !$type; |
101
|
|
|
|
|
|
|
|
102
|
7
|
|
|
|
|
21
|
my $uctype = ucfirst($type); |
103
|
7
|
|
|
|
|
27
|
my $package = "JSON::Karabiner::Manipulator::Conditions::" . $uctype; |
104
|
7
|
|
|
|
|
525
|
eval "require $package"; |
105
|
7
|
|
|
|
|
75
|
my $condition = $package->new($type); |
106
|
7
|
100
|
|
|
|
32
|
if (defined $s->{actions}{conditions}) { |
107
|
5
|
|
|
|
|
13
|
push @{$s->{actions}{conditions}}, $condition; |
|
5
|
|
|
|
|
16
|
|
108
|
|
|
|
|
|
|
} else { |
109
|
2
|
|
|
|
|
6
|
$s->{actions}{conditions} = [ $condition ]; |
110
|
|
|
|
|
|
|
} |
111
|
7
|
|
|
|
|
33
|
return $condition; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub add_description { |
115
|
1
|
|
|
1
|
1
|
331
|
my ($s, $desc) = _get_args(@_); |
116
|
|
|
|
|
|
|
|
117
|
1
|
50
|
|
|
|
4
|
croak 'To add a description, you must provide one' if !$desc; |
118
|
1
|
|
|
|
|
5
|
$s->{actions}{description} = $desc; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub add_parameter { |
122
|
1
|
|
|
1
|
1
|
327
|
my ($s, $param, $value) = _get_args(@_); |
123
|
1
|
50
|
|
|
|
4
|
croak 'To add a parameter, you must tell me which kind you\'d like to add' if !$param; |
124
|
1
|
50
|
|
|
|
3
|
croak 'To add a parameter, you must provide a value' if !$value; |
125
|
|
|
|
|
|
|
|
126
|
1
|
|
|
|
|
6
|
my @acceptable_values = qw( to_if_alone_timeout_milliseconds |
127
|
|
|
|
|
|
|
alone_timeout |
128
|
|
|
|
|
|
|
alone |
129
|
|
|
|
|
|
|
to_if_held_down_threshold_milliseconds |
130
|
|
|
|
|
|
|
held_down_threshold |
131
|
|
|
|
|
|
|
down_threshold |
132
|
|
|
|
|
|
|
held_down |
133
|
|
|
|
|
|
|
down |
134
|
|
|
|
|
|
|
to_delayed_action_delay_milliseconds |
135
|
|
|
|
|
|
|
delayed_action_delay |
136
|
|
|
|
|
|
|
action_delay |
137
|
|
|
|
|
|
|
delay |
138
|
|
|
|
|
|
|
simultaneous_threshold_milliseconds |
139
|
|
|
|
|
|
|
simultaneous_threshold |
140
|
|
|
|
|
|
|
simultaneous |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
1
|
|
|
|
|
3
|
my $param_exists = grep { $param eq $_ } @acceptable_values; |
|
15
|
|
|
|
|
27
|
|
144
|
1
|
50
|
|
|
|
3
|
croak "'$param' in an unrecognzed parameter" unless $param_exists; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
# get param full name |
147
|
1
|
50
|
|
|
|
9
|
if ($param =~ /alone/) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
148
|
1
|
|
|
|
|
5
|
$param = 'to_if_alone_timeout_milliseconds'; |
149
|
|
|
|
|
|
|
} elsif ($param =~ /down/) { |
150
|
0
|
|
|
|
|
0
|
$param = 'to_if_held_down_threshold_milliseconds'; |
151
|
|
|
|
|
|
|
} elsif ($param =~ /delay/) { |
152
|
0
|
|
|
|
|
0
|
$param = 'to_delayed_action_delay_milliseconds'; |
153
|
|
|
|
|
|
|
} elsif ($param =~ /simultaneous/) { |
154
|
0
|
|
|
|
|
0
|
$param = 'simultaneous_threshold_milliseconds'; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
1
|
|
|
|
|
13
|
$s->{actions}{parameters}{"basic.$param"} = $value; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub TO_JSON { |
161
|
32
|
|
|
32
|
0
|
71
|
my $obj = shift; |
162
|
|
|
|
|
|
|
#TODO: Change this under certain conditions |
163
|
32
|
|
|
|
|
83
|
$obj->{actions}{type} = 'basic'; |
164
|
32
|
100
|
|
|
|
130
|
$obj->_do_validity_checks($obj->{actions}) unless $obj->{_disable_validity_tests}; |
165
|
29
|
|
|
|
|
468
|
return $obj->{actions}; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub _do_validity_checks { |
169
|
10
|
|
|
10
|
|
16
|
my $s = shift; |
170
|
10
|
|
|
|
|
17
|
my $actions = shift; |
171
|
10
|
|
|
|
|
24
|
my $from = $actions->{from}; |
172
|
10
|
|
|
|
|
33
|
$s->_do_from_validity_checks($from); |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
sub _dump_json { |
176
|
5
|
|
|
5
|
|
469
|
my $s = $main::current_manip; |
177
|
5
|
|
|
|
|
12
|
my @kb_obj_args = @{$s->{_kb_obj_args}}; |
|
5
|
|
|
|
|
16
|
|
178
|
5
|
100
|
|
|
|
14
|
if (!@kb_obj_args) { |
179
|
2
|
|
|
|
|
48
|
croak "The _dump_json method cannot be run on this manipulator."; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
|
182
|
3
|
|
|
|
|
508
|
require JSON::Karabiner; |
183
|
3
|
|
|
|
|
11
|
my $little_title = shift @kb_obj_args; |
184
|
3
|
|
|
|
|
9
|
unshift @kb_obj_args, 'SET WITH write_file METHOD'; |
185
|
3
|
|
|
|
|
16
|
my $kb_obj = JSON::Karabiner->new( @kb_obj_args ); |
186
|
|
|
|
|
|
|
|
187
|
3
|
|
|
|
|
12
|
my $rule = $kb_obj->add_rule($little_title); |
188
|
3
|
|
|
|
|
11
|
my $temp_manip = $rule->add_manipulator(); |
189
|
3
|
|
|
|
|
6
|
%{$temp_manip} = %{$s}; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
12
|
|
190
|
3
|
|
|
|
|
12
|
$kb_obj->_dump_json; |
191
|
|
|
|
|
|
|
} |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub write_file { |
194
|
3
|
|
|
3
|
0
|
6
|
my $s = $main::current_manip; |
195
|
3
|
|
|
|
|
6
|
my $title = shift; |
196
|
3
|
|
|
|
|
5
|
my @kb_obj_args = @{$s->{_kb_obj_args}}; |
|
3
|
|
|
|
|
9
|
|
197
|
3
|
50
|
|
|
|
22
|
if (!@kb_obj_args) { |
198
|
0
|
|
|
|
|
0
|
croak "The _write_file method cannot be run on this manipulator."; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
|
201
|
3
|
0
|
33
|
|
|
9
|
croak 'You must supply a title for the first manipulator' if !$title && !$main::file_written; |
202
|
3
|
50
|
|
|
|
23
|
if (!$title) { |
203
|
0
|
|
|
|
|
0
|
$title = $main::file_title_written; |
204
|
|
|
|
|
|
|
} |
205
|
|
|
|
|
|
|
|
206
|
3
|
|
|
|
|
592
|
require JSON::Karabiner; |
207
|
3
|
|
|
|
|
11
|
my $little_title = shift @kb_obj_args; |
208
|
3
|
|
|
|
|
9
|
unshift @kb_obj_args, $title; |
209
|
3
|
|
|
|
|
13
|
my $kb_obj = JSON::Karabiner->new( @kb_obj_args ); |
210
|
3
|
50
|
|
|
|
10
|
if ($s->{_fake_write_flag}) { |
211
|
3
|
|
|
|
|
21
|
$kb_obj->{_fake_write_flag} = 1; |
212
|
|
|
|
|
|
|
} |
213
|
3
|
|
|
|
|
15
|
my $rule = $kb_obj->add_rule($little_title); |
214
|
3
|
|
|
|
|
8
|
my $temp_manip = $rule->add_manipulator(); |
215
|
3
|
|
|
|
|
22
|
%{$temp_manip} = %{$s}; |
|
3
|
|
|
|
|
13
|
|
|
3
|
|
|
|
|
12
|
|
216
|
3
|
|
|
|
|
15
|
$kb_obj->write_file(); |
217
|
3
|
|
|
|
|
11
|
$kb_obj->{_fake_write_flag} = 0; |
218
|
|
|
|
|
|
|
{ |
219
|
18
|
|
|
18
|
|
165
|
no warnings 'once'; |
|
18
|
|
|
|
|
40
|
|
|
18
|
|
|
|
|
4636
|
|
|
3
|
|
|
|
|
8
|
|
220
|
3
|
|
|
|
|
6
|
$main::file_written = $kb_obj_args[1]; |
221
|
3
|
|
|
|
|
26
|
$main::file_title_written = $kb_obj_args[0]; |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub _fake_write_file { |
227
|
5
|
|
|
5
|
|
1792
|
my $s = $main::current_manip; |
228
|
5
|
|
|
|
|
10
|
my $title = shift; |
229
|
|
|
|
|
|
|
|
230
|
5
|
|
|
|
|
10
|
my @kb_obj_args = @{$s->{_kb_obj_args}}; |
|
5
|
|
|
|
|
18
|
|
231
|
5
|
100
|
|
|
|
20
|
if (!@kb_obj_args) { |
232
|
2
|
|
|
|
|
22
|
croak "The _fake_write method cannot be run on this manipulator."; |
233
|
|
|
|
|
|
|
} |
234
|
|
|
|
|
|
|
|
235
|
3
|
|
|
|
|
7
|
$s->{_fake_write_flag} = 1; |
236
|
3
|
|
|
|
|
12
|
$s->write_file($title); |
237
|
3
|
|
|
|
|
146
|
$s->{_fake_write_flag} = 0; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub _do_from_validity_checks { |
241
|
10
|
|
|
10
|
|
17
|
my $s = shift; |
242
|
10
|
|
|
|
|
17
|
my $from = shift; |
243
|
|
|
|
|
|
|
|
244
|
10
|
100
|
|
|
|
23
|
if (! defined $from) { |
245
|
2
|
|
|
|
|
25
|
croak "No 'from' action found in the manipulator. You must add a 'from' action.'"; |
246
|
|
|
|
|
|
|
} |
247
|
|
|
|
|
|
|
|
248
|
8
|
100
|
|
|
|
21
|
if (! %$from) { |
249
|
1
|
|
|
|
|
10
|
croak "The 'from' action is empty. Perform methods on the 'from' action to tell it how to behave."; |
250
|
|
|
|
|
|
|
} |
251
|
|
|
|
|
|
|
|
252
|
7
|
|
|
|
|
13
|
return; |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
# my @from_keys = keys %$from; |
255
|
|
|
|
|
|
|
# my $has_key_code = grep { $_ =~ /^any|consumer_key_code|key_code$/ } @from_keys; |
256
|
|
|
|
|
|
|
# print Dumper \@from_keys; |
257
|
|
|
|
|
|
|
# if (!$has_key_code && grep { $_ =~ /modifiers/ } @from_keys) { |
258
|
|
|
|
|
|
|
# print Dumper 'aksjdkajsdf'; |
259
|
|
|
|
|
|
|
# croak "You cannot have modifiers without anything to modify in a 'from' action."; |
260
|
|
|
|
|
|
|
# } |
261
|
|
|
|
|
|
|
} |
262
|
|
|
|
|
|
|
|
263
|
|
|
|
|
|
|
# ABSTRACT: manipulator object for containing and outputting its data |
264
|
|
|
|
|
|
|
|
265
|
|
|
|
|
|
|
1; |
266
|
|
|
|
|
|
|
|
267
|
|
|
|
|
|
|
__END__ |