« 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 21 | 6 | local $/ = undef; | |||||||||||||||||||||||||||
| 22 | 6 | my $content = <$f>; | |||||||||||||||||||||||||||
| 23 | 6 | close $f; | |||||||||||||||||||||||||||
| 24 | 6 | ▶ | if ( $file =~ $hashParameters ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 3 | eval { $content = JSON::from_json($content) }; | |||||||||||||||||||||||||||
| 26 | 3 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 57 | 4 | ▶ | if ( open my $f, '>', "$self->{overlayDirectory}/$file" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 4 | ▶ | print $f ( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 80 | 5 | ▶ | die "$overDir directory doesn't exist" unless -d $overDir and -r $overDir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-d $overDir and -r $overDir
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
| |||||||||||||||||||||||||||||
| 81 | 5 | ▶ | opendir my $dir, $overDir or die $!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 88 | 10 | local $/ = undef; | |||||||||||||||||||||||||||
| 89 | 10 | my $content = <$f>; | |||||||||||||||||||||||||||
| 90 | 10 | close $f; | |||||||||||||||||||||||||||
| 91 | 10 | ▶ | if ( $file =~ $hashParameters ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 92 | 5 | eval { $content = JSON::from_json($content) }; | |||||||||||||||||||||||||||
| 93 | 5 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 114 | eval | ||||||||||||||||||||||||||||
| 115 | 1 | "require Lemonldap::NG::Common::Conf::Backends::$self->{overlayRealtype}"; | |||||||||||||||||||||||||||
| 116 | 1 | ▶ | die $@ if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 1 | $AUTOLOAD =~ s/::Overlay::/::$self->{overlayRealtype}::/; | |||||||||||||||||||||||||||
| 118 | 1 | my @res = &{$AUTOLOAD}(@_); | |||||||||||||||||||||||||||
| 119 | 1 | ▶ | return wantarray ? (@res) : $res; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | 1 | 1; | |||||||||||||||||||||||||||