| 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
| |||||||||||
| 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
| |||||||||||
| 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
| |||||||||||
| 40 | |||||||||||
| 41 | 15 | my ($key, $value) = split /\s+/, $line; | |||||||||
| 42 | 15 | ▶ | $self->{$key} = ( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 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 | ||||||||||