File Coverage

blib/lib/App/Easer/ConfigHash.pm
Criterion Covered Total %
statement 48 48 100.0
branch 9 10 90.0
condition 2 2 100.0
subroutine 9 9 100.0
pod 5 5 100.0
total 73 74 98.6


line stmt bran cond sub pod time code
1             package App::Easer::ConfigHash;
2 2     2   129957 use v5.24;
  2         7  
3 2     2   10 use warnings;
  2         5  
  2         129  
4 2     2   8 use experimental qw< signatures >;
  2         4  
  2         14  
5             { our $VERSION = '2.014' }
6 2     2   990 use Storable ();
  2         4153  
  2         868  
7              
8 2     2 1 170607 sub new ($package, $hash, $opts = {}) {
  2         4  
  2         5  
  2         4  
  2         4  
9 2   100     17 my $self = bless { clone => ($opts->{clone} // 0) }, $package;
10 2         12 return $self->set_config_hash($hash);
11             }
12              
13 4     4 1 8 sub config ($self, @keys) {
  4         6  
  4         9  
  4         4  
14 4 50       9 return unless @keys;
15 4         10 my $hash = $self->{hash};
16 4 100       18 return $hash->{$keys[0]} if @keys == 1;
17 2         20 return $hash->@{@keys};
18             }
19              
20 6     6 1 1921 sub config_hash ($self) {
  6         8  
  6         6  
21 6         12 my $hash = $self->{hash};
22 6 100       143 $hash = Storable::dclone($hash) if $self->{clone};
23 6         38 return $hash;
24             }
25              
26 4     4 1 6 sub set_config ($self, $key, @value) {
  4         5  
  4         10  
  4         7  
  4         5  
27 4         6 my $hash = $self->{hash};
28 4         5 delete($hash->{$key});
29 4 100       10 $hash->{$key} = $value[0] if @value;
30 4         7 return $self;
31             }
32              
33 2     2 1 7 sub set_config_hash ($self, $hash) {
  2         3  
  2         3  
  2         4  
34 2 100       114 $hash = Storable::dclone($hash) if $self->{clone};
35 2         7 $self->{hash} = $hash;
36 2         8 return $self;
37             }
38              
39             1;