line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Config::SL; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
19307
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
73
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Config::SL - Configuration file abstraction for Silver Lining applications |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 ABSTRACT |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use Config::SL; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
$cfg = Config::SL->new; |
15
|
|
|
|
|
|
|
$val = $cfg->key; |
16
|
|
|
|
|
|
|
@vals = $cfg->key; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 DESCRIPTION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
This package is responsible for handling Silver Lining configuration data. |
21
|
|
|
|
|
|
|
It should make our lives less complex. |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
It is an abstraction of Config::ApacheFormat, and looks for the configuration |
24
|
|
|
|
|
|
|
file sl.conf in various locations. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $VERSION = 0.01; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our ( $config, $conf_dir ); |
31
|
|
|
|
|
|
|
our $file = 'sl.conf'; |
32
|
|
|
|
|
|
|
|
33
|
1
|
|
|
1
|
|
6
|
use base 'Config::ApacheFormat'; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
1355
|
|
34
|
1
|
|
|
1
|
|
96828
|
use FindBin; |
|
1
|
|
|
|
|
1159
|
|
|
1
|
|
|
|
|
416
|
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub new { |
37
|
1
|
|
|
1
|
1
|
12
|
my $class = shift; |
38
|
|
|
|
|
|
|
|
39
|
1
|
50
|
|
|
|
3
|
return $config if $config; |
40
|
|
|
|
|
|
|
|
41
|
1
|
|
|
|
|
2
|
my @config_files; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# check the local conf dir first |
44
|
1
|
50
|
33
|
|
|
33
|
if ( -d "./conf" && ( -e "./conf/$file" ) ) { |
|
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
$conf_dir = "./conf"; |
47
|
1
|
|
|
|
|
4
|
@config_files = ("$conf_dir/$file"); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
elsif ( -d "$FindBin::Bin/../conf" && ( -e "$FindBin::Bin/../conf/$file" ) ) |
51
|
|
|
|
|
|
|
{ |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# development |
54
|
0
|
|
|
|
|
0
|
$conf_dir = "$FindBin::Bin/../conf"; |
55
|
0
|
|
|
|
|
0
|
@config_files = ( "$conf_dir/$file", "$conf_dir/../$file" ); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# then check for a global conf file |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
elsif ( -e "/etc/sl/$file" ) { |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# global sl dir |
62
|
0
|
|
|
|
|
0
|
$conf_dir = "/etc/sl"; |
63
|
0
|
|
|
|
|
0
|
@config_files = ("$conf_dir/$file"); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
elsif ( -e "/etc/$file" ) { |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# global etc |
68
|
0
|
|
|
|
|
0
|
$conf_dir = "/etc"; |
69
|
0
|
|
|
|
|
0
|
@config_files = ("$conf_dir/$file"); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
else { |
72
|
0
|
|
|
|
|
0
|
die "\nNo file $file found in " |
73
|
|
|
|
|
|
|
. "$FindBin::Bin/../conf/ or /etc/sl/!\n"; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# we have a configuration file to work with, so get to work |
77
|
1
|
|
|
|
|
44
|
$config = $class->SUPER::new(); |
78
|
1
|
|
|
|
|
1264
|
my $read; |
79
|
1
|
|
|
|
|
3
|
foreach my $config_file (@config_files) { |
80
|
1
|
50
|
|
|
|
14
|
next unless ( -e $config_file ); |
81
|
1
|
|
|
|
|
7
|
$config->read($config_file); |
82
|
1
|
|
|
|
|
1587
|
$read++; |
83
|
|
|
|
|
|
|
} |
84
|
1
|
50
|
|
|
|
4
|
die "\nNo config files read! conf_dir $conf_dir\n" unless $read; |
85
|
|
|
|
|
|
|
|
86
|
1
|
|
|
|
|
29
|
$config->autoload_support(1); |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
10
|
return $config; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub sl_debug { |
92
|
0
|
|
|
0
|
0
|
|
my $config = shift; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
|
return $ENV{SL_DEBUG}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub conf_dir { |
98
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
99
|
0
|
|
|
|
|
|
return $conf_dir; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
Copyright 2010 Silver Lining Networks - All Rights Reserved. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
1; |