LDAP/Config.pm

filter: Statementstmt 100% 26 / 26 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 0.0% 0 / 3 totaltotal 90.7% 39 / 43 CC 5 SCAR 6.9
CC
5
Cov
97%
config_from_line
3.0
read
2.0
read_config_file
2.0
CRAP 2.0
« LDAP/Command/Version.pm ↑ Summary LDAP/Connection.pm »
1 package App::LDAP::Config;
2  
3 14 ▶use Modern::Perl;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 14 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 14 ▶use MooseX::Singleton;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 14 our @locations = qw(
8 $ENV{HOME}/.ldaprc
9 /etc/ldap.conf
10 /etc/ldap/ldap.conf
11 /usr/local/etc/ldap.conf
12 );
13  
14 14 our @has_scope = qw(
15 nss_base_passwd
16 nss_base_shadow
17 nss_base_group
18 nss_base_hosts
19 sudoers_base
20 );
21  
22 1 ▶sub read {
Subroutine read: called CC=2 SCAR=7.0
Pod undocumented
23 1 my ($class, ) = @_;
24 1 my $self = $class->new;
25 1 my @locations = grep { -f $_ } @locations;
26 1 ▶ die "no config file found" unless scalar @locations;
Branch: 1 branch
BranchTrueFalseTotal
unless scalar @locations 0 1 1
27 1 $self->read_config_file(@locations);
28 1 $self;
29 }
30  
31 1 ▶sub read_config_file {
Subroutine read_config_file: called CC=2 SCAR=6.9
Pod undocumented
32 1 my ($self, $file) = @_;
33 1 open my $config, "<", $file;
34 1 ▶ $self->config_from_line($_) while <$config>;
Branch: 1 branch
BranchTrueFalseTotal
defined($_ = readline $config) and do { $self->config_from_line($_) } 26 1 27
35 }
36  
37 26 ▶sub config_from_line {
Subroutine config_from_line: called CC=3 SCAR=11.0
Pod undocumented
38 26 my ($self, $line) = @_;
39 26 ▶ return if $line =~ /(^#|^\n)/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /(^#|^\n)/u 11 15 26
40  
41 15 my ($key, $value) = split /\s+/, $line;
42 15 ▶ $self->{$key} = (
Branch: 1 branch
BranchTrueFalseTotal
$key ~~ \@App::LDAP::Config::has_scope ? : 5 10 15
43 $key ~~ @has_scope ?
44 [split /\?/, $value] :
45 $value
46 );
47 }
48  
49 14 1;
50  
51 =pod
52  
53 =head1 NAME
54  
55 App::LDAP::Config - loader of config files
56  
57 =head1 DESCRIPTION
58  
59 This module would be called automatically in App::LDAP::run() to load the configurations.
60  
61 =cut
« LDAP/Command/Version.pm ↑ Summary LDAP/Connection.pm »