File Coverage

blib/lib/Auth/Kokolores/Config.pm
Criterion Covered Total %
statement 14 30 46.6
branch 1 4 25.0
condition n/a
subroutine 4 5 80.0
pod 0 2 0.0
total 19 41 46.3


line stmt bran cond sub pod time code
1             package Auth::Kokolores::Config;
2              
3 2     2   16220 use Moose;
  2         596535  
  2         10  
4              
5             # ABSTRACT: configuration for Auth::Kokolores
6             our $VERSION = '1.01'; # VERSION
7              
8 2     2   9959 use Tie::IxHash;
  2         5127  
  2         50  
9 2     2   1245 use Config::General qw(ParseConfig);
  2         30822  
  2         906  
10              
11             has 'log_level' => ( is => 'rw', isa => 'Int', default => '2' );
12             has 'log_file' => ( is => 'rw', isa => 'Str', default => 'Sys::Syslog' );
13              
14             has 'syslog_ident' => ( is => 'rw', isa => 'Str', default => 'kokolores' );
15             has 'syslog_facility' => ( is => 'rw', isa => 'Str', default => 'auth' );
16              
17             has 'socket_path' => ( is => 'rw', isa => 'Str', default => '/var/run/saslauthd/mux' );
18             has 'socket_mode' => ( is => 'rw', isa => 'Maybe[Str]' );
19              
20             has 'pid_file' => ( is => 'rw', isa => 'Maybe[Str]' );
21              
22             has 'user' => ( is => 'rw', isa => 'Maybe[Str]' );
23             has 'group' => ( is => 'rw', isa => 'Maybe[Str]' );
24              
25             has 'protocol' => ( is => 'rw', isa => 'Str', default => 'CyrusSaslauthd' );
26              
27             # prefork engine options
28             has 'min_servers' => ( is => 'rw', isa => 'Int', default => '4' );
29             has 'min_spare_servers' => ( is => 'rw', isa => 'Int', default => '4' );
30             has 'max_spare_servers' => ( is => 'rw', isa => 'Int', default => '12' );
31             has 'max_servers' => ( is => 'rw', isa => 'Int', default => '25' );
32             has 'max_requests' => ( is => 'rw', isa => 'Int', default => '1000' );
33              
34             has 'satisfy' => ( is => 'rw', isa => 'Str', default => 'all' );
35              
36             has 'overwrittable_attributes' => (
37             is => 'ro', isa => 'ArrayRef[Str]', default => sub { [
38             'log_level', 'log_file'
39             ] },
40             );
41             has 'net_server_attributes' => (
42             is => 'ro', isa => 'ArrayRef[Str]', default => sub { [
43             'syslog_ident', 'syslog_facility', 'user', 'group',
44             'min_servers', 'min_spare_servers', 'max_spare_servers', 'max_servers',
45             'max_requests', 'pid_file',
46             ] },
47             );
48             has 'kokolores_attributes' => (
49             is => 'ro', isa => 'ArrayRef[Str]', default => sub { [
50             'socket_path', 'socket_mode', 'satisfy', 'protocol',
51             ] },
52             );
53              
54             has 'Plugin' => ( is => 'rw', isa => 'HashRef', default => sub { {} } );
55              
56             sub new_from_file {
57 1     1 0 19 my ( $class, $file ) = @_;
58              
59 1 50       16 if( ! -f $file ) {
60 0         0 print(STDERR 'configuration file '.$file." does not exist!\n");
61 0         0 exit 1;
62             }
63              
64 1         7 tie my %config_hash, "Tie::IxHash";
65 1         15 %config_hash = ParseConfig(
66             -AllowMultiOptions => 'no',
67             -ConfigFile => $file,
68             -Tie => "Tie::IxHash"
69             );
70            
71 1         2479 return $class->new( %config_hash );
72             }
73              
74             sub apply_config {
75 0     0 0   my ( $self, $main ) = @_;
76 0           my $server = $main->{'server'};
77              
78 0           foreach my $attr ( @{$self->overwrittable_attributes}) {
  0            
79 0 0         if( ! defined $server->{$attr} ) {
80 0           $server->{$attr} = $self->$attr;
81             }
82             }
83 0           foreach my $attr ( @{$self->net_server_attributes}) {
  0            
84 0           $server->{$attr} = $self->$attr;
85             }
86 0           foreach my $attr ( @{$self->kokolores_attributes}) {
  0            
87 0           $main->{$attr} = $self->$attr;
88             }
89 0           $main->{'kokolores_config'} = $self;
90              
91 0           return;
92             }
93              
94             1;
95              
96             __END__
97              
98             =pod
99              
100             =encoding UTF-8
101              
102             =head1 NAME
103              
104             Auth::Kokolores::Config - configuration for Auth::Kokolores
105              
106             =head1 VERSION
107              
108             version 1.01
109              
110             =head1 AUTHOR
111              
112             Markus Benning <ich@markusbenning.de>
113              
114             =head1 COPYRIGHT AND LICENSE
115              
116             This software is Copyright (c) 2016 by Markus Benning <ich@markusbenning.de>.
117              
118             This is free software, licensed under:
119              
120             The GNU General Public License, Version 2, June 1991
121              
122             =cut