File Coverage

blib/lib/JSON/Karabiner/Manipulator/Conditions/Variable_if.pm
Criterion Covered Total %
statement 32 37 86.4
branch 3 8 37.5
condition 1 2 50.0
subroutine 8 9 88.8
pod 0 4 0.0
total 44 60 73.3


line stmt bran cond sub pod time code
1             package JSON::Karabiner::Manipulator::Conditions::Variable_if ;
2             $JSON::Karabiner::Manipulator::Conditions::Variable_if::VERSION = '0.018';
3 1     1   7 use strict;
  1         3  
  1         31  
4 1     1   5 use warnings;
  1         2  
  1         24  
5 1     1   4 use JSON;
  1         2  
  1         6  
6 1     1   93 use Carp;
  1         3  
  1         60  
7 1     1   7 use parent 'JSON::Karabiner::Manipulator::Conditions';
  1         2  
  1         5  
8              
9             sub new {
10 2     2 0 6 my $class = shift;
11 2         5 my ($type, $value) = @_;
12 2         9 my $obj = $class->SUPER::new($type, $value);
13 2   50     22 $obj->{data} = $value || {},
14             return $obj;
15             }
16              
17             sub add_variable {
18 1     1 0 343 my $s = shift;
19 1         3 my $name = shift;
20 1         2 my $value = shift;
21 1 50       3 croak 'A variable name is required' unless $name;
22 1 50       3 croak 'A value for the varaible name is required' unless $value;
23             #TODO: Validates keys
24 1 50       5 if ($value =~ /^\d+$/) {
25 0         0 $value = $value + 0;
26             }
27 1         2 $s->{data}{name} = $name;
28 1         4 $s->{data}{value} = $value;
29              
30             }
31              
32             sub add_description {
33 0     0 0 0 my $s = shift;
34 0         0 my $desc = shift;
35 0 0       0 croak ('No description passed.') unless $desc;
36 0         0 $s->{data}{description} = $desc;
37              
38             }
39              
40             sub TO_JSON {
41 2     2 0 4 my $obj = shift;
42 2         3 my $name = $obj->{def_name};
43 2         4 my $value = $obj->{data};
44 2         7 my %super_hash = (%$value, type => $name);
45 2         18 return { %super_hash };
46              
47             }
48             # ABSTRACT: definition for Frontmost_application_if condition
49              
50             1;
51              
52             __END__