File Coverage

blib/lib/JSON/Karabiner/Manipulator/Conditions/Variable_if.pm
Criterion Covered Total %
statement 31 35 88.5
branch 2 6 33.3
condition 1 2 50.0
subroutine 8 9 88.8
pod 0 4 0.0
total 42 56 75.0


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.016';
3 1     1   13 use strict;
  1         2  
  1         32  
4 1     1   6 use warnings;
  1         2  
  1         23  
5 1     1   5 use JSON;
  1         2  
  1         6  
6 1     1   96 use Carp;
  1         2  
  1         51  
7 1     1   18 use parent 'JSON::Karabiner::Manipulator::Conditions';
  1         3  
  1         5  
8              
9             sub new {
10 2     2 0 5 my $class = shift;
11 2         5 my ($type, $value) = @_;
12 2         12 my $obj = $class->SUPER::new($type, $value);
13 2   50     31 $obj->{data} = $value || {},
14             return $obj;
15             }
16              
17             sub add_variable {
18 1     1 0 348 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       5 croak 'A value for the varaible name is required' unless $value;
23             #TODO: Validates keys
24 1         2 $s->{data}{name} = $name;
25 1         6 $s->{data}{value} = $value;
26              
27             }
28              
29             sub add_description {
30 0     0 0 0 my $s = shift;
31 0         0 my $desc = shift;
32 0 0       0 croak ('No description passed.') unless $desc;
33 0         0 $s->{data}{description} = $desc;
34              
35             }
36              
37             sub TO_JSON {
38 2     2 0 5 my $obj = shift;
39 2         3 my $name = $obj->{def_name};
40 2         4 my $value = $obj->{data};
41 2         7 my %super_hash = (%$value, type => $name);
42 2         20 return { %super_hash };
43              
44             }
45             # ABSTRACT: definition for Frontmost_application_if condition
46              
47             1;
48              
49             __END__