blib/lib/Lemonldap/NG/Common/Conf/Backends/Overlay.pm

filter: Statementstmt 89.8% 71 / 79 Branchbran 57.8% 22 / 38 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 76.3% 100 / 131 CC 24 SCAR 20.4
CC
24
Cov
78%
overList
11.2
load
8.0
store
6.2
CRAP 7.7
« blib/lib/Lemonldap/NG/Common/Conf/Backends/DBI.pm ↑ Summary blib/lib/Lemonldap/NG/Common/Apache/Session.pm »
1 package Lemonldap::NG::Common::Conf::Backends::Overlay;
2  
3 1 ▶use Lemonldap::NG::Common::Conf::Constants qw($hashParameters );
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '2.19.0';
7  
8 3 ▶sub load {
Subroutine load: called CC=7 SCAR=20.8
Pod undocumented
9 3 my ( $self, $cfgNum, $fields ) = @_;
10 3 my @files = eval { overList($self) };
11 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 3 3
12 0 $Lemonldap::NG::Common::Conf::msg .= $@;
13 0 return undef;
14 }
15 my $conf =
16 3 &{"Lemonldap::NG::Common::Conf::Backends::$self->{overlayRealtype}::load"}
17 (@_);
18 3 my @errors;
19 3 foreach my $file (@files) {
20 6 ▶ if ( open my $f, '<', "$self->{overlayDirectory}/$file" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $f, '<', "$self->{'overlayDirectory'}/$file") { } 6 0 6
21 6 local $/ = undef;
22 6 my $content = <$f>;
23 6 close $f;
24 6 ▶ if ( $file =~ $hashParameters ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /$hashParameters/) { } 3 3 6
25 3 eval { $content = JSON::from_json($content) };
26 3 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 3 3
27 0 push @errors, "Bad over file $file: $@";
28 }
29 else {
30 3 $conf->{$file} = $content;
31 }
32 }
33 else {
34 3 $content =~ s/^\s*(.*?)\s*$/$1/;
35 3 $conf->{$file} = $content;
36 }
37 }
38 else {
39 0 push @errors, $!;
40 }
41 }
42 3 ▶ if (@errors) {
Branch: 1 branch
BranchTrueFalseTotal
if (@errors) 0 3 3
43 0 $Lemonldap::NG::Common::Conf::msg .= join "\n", @errors;
44 0 return undef;
45 }
46 3 return $conf;
47 }
48  
49 2 ▶sub store {
Subroutine store: called CC=6 SCAR=18.3
Pod undocumented
50 2 my ( $self, $fields ) = @_;
51 2 my @files = eval { overList($self) };
52  
53 2 my @errors;
54 2 foreach my $file (@files) {
55 4 my $data = delete $fields->{$file};
56 4 ▶ if ( $self->{overlayWrite} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"overlayWrite"}) 4 0 4
57 4 ▶ if ( open my $f, '>', "$self->{overlayDirectory}/$file" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $f, '>', "$self->{'overlayDirectory'}/$file") { } 4 0 4
58 4 ▶ print $f (
Branch: 1 branch
BranchTrueFalseTotal
$file =~ /$hashParameters/ ? : 2 2 4
59 $file =~ $hashParameters ? JSON::to_json($data) : $data );
60 4 close $f;
61 }
62  
63 else {
64 0 push @errors, "Unable to write over file $file: $@";
65 }
66 }
67 }
68  
69 2 ▶ die join( "\n", @errors ) if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 2 2
70  
71 return &{
72 2 "Lemonldap::NG::Common::Conf::Backends::$self->{overlayRealtype}::store"
73 }( $self, $fields );
74 }
75  
76 5 ▶sub overList {
Subroutine overList: called CC=10 SCAR=24.2
Pod undocumented
77 5 my ($self) = @_;
78  
79 5 ▶ my $overDir = $self->{overlayDirectory} or die 'Missing overlayDirectory';
Branch: 1 branch
BranchTrueFalseTotal
my $overDir = $self->{"overlayDirectory"} or die "Missing overlayDirectory" 5 0 5
80 5 ▶ die "$overDir directory doesn't exist" unless -d $overDir and -r $overDir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $overDir and -r $overDir 0 5 5
Condition33%1/3
-d $overDir and -r $overDir
!ll&&!rl&&r
005
MC/DC0%0/2
-d $overDir and -r $overDir
-d $overDir -r $overDir
Truth table33%1/3
A and B
A= -d $overDirB= -r $overDir
ABresult
0X0
100
111
81 5 ▶ opendir my $dir, $overDir or die $!;
Branch: 1 branch
BranchTrueFalseTotal
opendir my $dir, $overDir or die $! 5 0 5
82 5 my @files = grep /^[^\.]/, readdir $dir;
83 5 closedir $dir;
84 5 my @errors;
85  
86 5 foreach my $file (@files) {
87 10 ▶ if ( open my $f, '<', "$overDir/$file" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $f, "<", "$overDir/$file") 10 0 10
88 10 local $/ = undef;
89 10 my $content = <$f>;
90 10 close $f;
91 10 ▶ if ( $file =~ $hashParameters ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ /$hashParameters/) { } 5 5 10
92 5 eval { $content = JSON::from_json($content) };
93 5 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) { } 0 5 5
94 0 push @errors, "Bad over file $file: $@";
95 }
96 else {
97 5 $conf->{$file} = $content;
98 }
99 }
100 else {
101 5 $content =~ s/^\s*(.*?)\s*$/$1/;
102 5 $conf->{$file} = $content;
103 }
104 }
105 }
106 5 ▶ die join "\n", @errors if @errors;
Branch: 1 branch
BranchTrueFalseTotal
if @errors 0 5 5
107 5 return @files;
108 }
109  
110 1 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=14.2
111 1 my ($self) = @_;
112 die 'Missing overlayRealtype'
113 1 ▶ unless $self->{overlayRealtype};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"overlayRealtype"} 0 1 1
114 eval
115 1 "require Lemonldap::NG::Common::Conf::Backends::$self->{overlayRealtype}";
116 1 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
117 1 $AUTOLOAD =~ s/::Overlay::/::$self->{overlayRealtype}::/;
118 1 my @res = &{$AUTOLOAD}(@_);
119 1 ▶ return wantarray ? (@res) : $res;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 0 1
120 }
121  
122 1 1;
« blib/lib/Lemonldap/NG/Common/Conf/Backends/DBI.pm ↑ Summary blib/lib/Lemonldap/NG/Common/Apache/Session.pm »