« 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 63 | 0 | ▶ | croak 'To add a parameter, you must provide a value' if !$value; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 84 | |||||||||||||||||||||||
| 85 | # get param full name | ||||||||||||||||||||||
| 86 | 0 | ▶ | if ($param =~ /alone/) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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
| |||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||