blib/lib/Lemonldap/NG/Common/Conf/Wrapper.pm untested

filter: Statementstmt 0.0% 0 / 34 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 8 totaltotal 0.0% 0 / 68 CC 4 SCAR 15.9
CC
4
Cov
0%
TIEHASH
12.0
FETCH
6.0
STORE
2.0
CRAP 4.9
1 package Lemonldap::NG::Common::Conf::Wrapper;
2  
3 use strict;
4 use JSON;
5  
6 our $VERSION = '2.0.3';
7  
8 sub TIEHASH {
9 my ( $class, $conf, $overrides ) = @_;
10 my %h = %$overrides;
11 foreach ( keys %h ) {
12 if ( $h{$_} =~ /^[\[\{]/ ) {
13 my $tmp = eval { JSON::from_json( $h{$_} ) };
14 if ($@) {
15 print STDERR "Wrapper: unable to compile $_ key, skipping\n";
16 }
17 else {
18 $h{$_} = $tmp;
19 }
20 }
21 }
22 return bless {
23 _wrapC => $conf,
24 _wrapO => \%h,
25 }, $class;
26 }
27  
28 sub FETCH {
29 my ( $self, $key ) = @_;
30 return (
31 exists( $self->{_wrapO}->{$key} )
32 ? $self->{_wrapO}->{$key}
33 : $self->{_wrapC}->{$key}
34 );
35 }
36  
37 sub STORE {
38 my ( $self, $key, $value ) = @_;
39 return $self->{_wrapO}->{$key} = $value;
40 }
41  
42 sub DELETE {
43 my ( $self, $key ) = @_;
44 my $res = $self->{_wrapO}->{$key} // $self->{_wrapC}->{$key};
45 $self->{_wrapO}->{$key} = undef;
46 return $res;
47 }
48  
49 sub EXISTS {
50 my ( $self, $key ) = @_;
51 return (
52 exists( $self->{_wrapC}->{$key} )
53 or exists( $self->{_wrapO}->{$key} )
54 );
55 }
56  
57 sub DESTROY {
58 my $self = shift;
59 delete $self->{_wrapO};
60 delete $self->{_wrapC};
61 }
62  
63 sub FIRSTKEY {
64 return each %{ $_[0]->{_wrapC} };
65 }
66  
67 sub NEXTKEY {
68 return each %{ $_[0]->{_wrapC} };
69 }
70  
71 1;