line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#=============================================================================== |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# FILE: Conf.pm |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION: Configuration handling via command line and Config::General |
6
|
|
|
|
|
|
|
# |
7
|
|
|
|
|
|
|
# AUTHOR: Michael Bochkaryov (Rattler), |
8
|
|
|
|
|
|
|
# COMPANY: Net.Style |
9
|
|
|
|
|
|
|
# CREATED: 16.05.2008 12:24:55 EEST |
10
|
|
|
|
|
|
|
#=============================================================================== |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
NetSDS::Conf - API to configuration files |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
use NetSDS::Conf; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
my $cf = NetSDS::Conf->getconf($conf_file); |
21
|
|
|
|
|
|
|
my $val = $cf->{'parameter'}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
B module is a wrapper to B handler for |
26
|
|
|
|
|
|
|
NetSDS configuration files. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
This package is for internal usage and is called from B |
29
|
|
|
|
|
|
|
or inherited modules and should be never used directly from applications. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=cut |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
package NetSDS::Conf; |
34
|
|
|
|
|
|
|
|
35
|
2
|
|
|
2
|
|
12352
|
use 5.8.0; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
108
|
|
36
|
2
|
|
|
2
|
|
14
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
128
|
|
37
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
62
|
|
38
|
|
|
|
|
|
|
|
39
|
2
|
|
|
2
|
|
4351
|
use Config::General; |
|
2
|
|
|
|
|
63116
|
|
|
2
|
|
|
|
|
155
|
|
40
|
|
|
|
|
|
|
|
41
|
2
|
|
|
2
|
|
34
|
use version; our $VERSION = '1.301'; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
20
|
|
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
#*********************************************************************** |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=over |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=item B - read parameters from configuration file |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Paramters: configuration file name |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Returns: cofiguration as hash reference |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This method tries to read configuration file and fill object properties |
54
|
|
|
|
|
|
|
with read values. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
NOTE: Parameters set from command line will not be overriden. |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=cut |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#----------------------------------------------------------------------- |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
sub getconf { |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
1
|
|
my ( $proto, $cf ) = @_; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# Check if configuration file available for reading and read data |
67
|
0
|
0
|
0
|
|
|
|
if ( $cf and ( -f $cf ) and ( -r $cf ) ) { |
|
|
|
0
|
|
|
|
|
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
my $conf = Config::General->new( |
70
|
|
|
|
|
|
|
-ConfigFile => $cf, |
71
|
|
|
|
|
|
|
-AllowMultiOptions => 'yes', |
72
|
|
|
|
|
|
|
-UseApacheInclude => 'yes', |
73
|
|
|
|
|
|
|
-InterPolateVars => 'yes', |
74
|
|
|
|
|
|
|
-ConfigPath => [ $ENV{NETSDS_CONF_DIR}, '/etc/NetSDS' ], |
75
|
|
|
|
|
|
|
-IncludeRelative => 'yes', |
76
|
|
|
|
|
|
|
-IncludeGlob => 'yes', |
77
|
|
|
|
|
|
|
-UTF8 => 'yes', |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Parse configuration file |
81
|
0
|
|
|
|
|
|
my %cf_hash = $conf->getall; |
82
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
return \%cf_hash; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} else { |
86
|
0
|
|
|
|
|
|
return undef; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
} ## end sub getconf |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
__END__ |