MLite/Config.pm

filter: Statementstmt 28.4% 23 / 81 Branchbran 0.0% 0 / 24 Conditioncond 0.0% 0 / 30 MC/DCmcdc 0.0% 0 / 18 Subroutinesub 33.3% 7 / 21 Podpod 100% 9 / 9 totaltotal 21.3% 39 / 183 CC 25 SCAR 41.3
CC
25
Cov
17%
new
156.0
_loadconfig
90.0
AUTOLOAD
20.0
CRAP 62.5
« MLite/Store/DBI.pm ↑ Summary MLite/Helper.pm »
1 package WWW::MLite::Config; # $Id: Config.pm 15 2014-06-04 06:24:25Z minus $
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3
4 =head1 NAME
5
6 WWW::MLite::Config - Configuration of WWW::MLite
7
8 =head1 VERSION
9
10 Version 1.01
11
12 =head1 SYNOPSIS
13
14 use WWW::MLite::Config;
15
16 my $config = new WWW::MLite::Config(
17 file => '/var/www/MySite/config/mysite.conf',
18 dirs => [qw/foo bar baz/]
19 );
20
21 my $foo = $config->get('foo');
22
23 =head1 DESCRIPTION
24
25 The module works with the configuration data.
26
27 =head1 METHODS
28
29 =over 8
30
31 =item B<new>
32
33 my $config = new WWW::MLite::Config(
34 file => '/var/www/MySite/config/mysite.conf',
35 dirs => [qw/foo bar baz/]
36 );
37
38 Returns configuration object
39
40 =item B<get, conf, get_conf, config, get_config>
41
42 my $value = $config->get( 'key' );
43
44 =item B<set, set_conf, set_config>
45
46 $config->set( 'key', $value );
47
48 =back
49
50 =head1 HISTORY
51
52 See C<CHANGES> file
53
54 =head1 AUTHOR
55
56 Serz Minus (Lepenkov Sergey) L<http://www.serzik.com> E<lt>minus@mail333.comE<gt>
57
58 =head1 COPYRIGHT
59
60 Copyright (C) 1998-2014 D&D Corporation. All Rights Reserved
61
62 =head1 LICENSE
63
64 This program is free software: you can redistribute it and/or modify
65 it under the terms of the GNU General Public License as published by
66 the Free Software Foundation, either version 3 of the License, or
67 (at your option) any later version.
68
69 This program is distributed in the hope that it will be useful,
70 but WITHOUT ANY WARRANTY; without even the implied warranty of
71 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
72 GNU General Public License for more details.
73
74 See C<LICENSE> file
75
76 =cut
77
78 1 ▶use CTK::Util qw/ :BASE /; # Óòèëèòàðèé
Subroutine BEGIN: called CC=1 SCAR=0.0
79 1 ▶use WWW::MLite::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
80 1 ▶use Config::General;
Subroutine BEGIN: called CC=1 SCAR=0.0
81 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
82
83 1 ▶use vars qw/$VERSION/;
Subroutine BEGIN: called CC=1 SCAR=0.0
84 1 $VERSION = '1.01';
85
86 use constant {
87 1 CONFDIR => 'conf',
88 1 ▶ };
Subroutine BEGIN: called CC=1 SCAR=0.0
89
90 sub new {
91 0 ▶ my $class = shift;
Subroutine new: not called CC=12 SCAR=50.5
Pod documented
92 0 my %args = (@_);
93
94 0 my $file = $args{file};
95 0 my $dirs = $args{dirs};
96
97 # Óñòàíîâêà äèðåêòîðèé ïî óìîë÷àíèþ, åñëè íå çàäàíû äàííûå äèðåêòîðèè
98 0 ▶ unless ($dirs && (ref($dirs) eq 'ARRAY') && @$dirs) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($dirs and ref $dirs eq "ARRAY" and @$dirs) 0 0 0
Condition0%0/6
$dirs and ref $dirs eq "ARRAY" and @$dirs
!ll&&!rl&&r
000
$dirs and ref $dirs eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/3
$dirs and ref $dirs eq "ARRAY" and @$dirs
$dirs ref $dirs eq "ARRAY" @$dirs
Truth table0%0/4
A and B and C
A= $dirsB= ref $dirs eq "ARRAY"C= @$dirs
ABCresult
0XX0
10X0
1100
1111
99 0 ▶ my $bd = $ENV{DOCUMENT_ROOT} || '.';
Condition0%0/2
$ENV{'DOCUMENT_ROOT'} || '.'
l!l
00
MC/DC0%0/1
$ENV{'DOCUMENT_ROOT'} || '.'
$ENV{'DOCUMENT_ROOT'}
Truth table0%0/2
A
A= $ENV{'DOCUMENT_ROOT'}
Aresult
11
00
100 0 $dirs = [ $bd, catdir($bd, CONFDIR) ];
101 }
102
103 0 my %cfg = _loadconfig($file, $dirs);
104
105 # ×òåíèå äàííûõ ïåðåìåííûõ îêðóæåíèÿ
106 0 $cfg{lc($_)} = $ENV{$_} for keys %ENV;
107
108 # Óñòàíîâêà äîïîëíèòåëüíûõ äàííûõ
109 0 $cfg{sid} = getSID(16,'m'); # ID Ñåññèè (SID) - Äëÿ êîíòðîëÿ ñåññèè
110 0 $cfg{hitime} = getHiTime();
111
112 # Êîððåêòèðîâêà ñèñòåìíûõ ïàðàìåòðîâ êîíôèãóðàöèè (óìîë÷àíèÿ)
113
114 # WWW::MLite::Log
115 0 ▶ $cfg{debug} = $cfg{debug} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cfg{'debug'} ? : 0 0 0
116 0 ▶ $cfg{syslog} = $cfg{syslog} ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$cfg{'syslog'} ? : 0 0 0
117 0 ▶ $cfg{loglevel} = exists($cfg{loglevel}) && defined($cfg{loglevel}) ? $cfg{loglevel} : 'emerg';
Branch: 1 branch
BranchTrueFalseTotal
exists $cfg{'loglevel'} && defined $cfg{'loglevel'} ? : 0 0 0
Condition0%0/3
exists $cfg{"loglevel"} and defined $cfg{"loglevel"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $cfg{"loglevel"} and defined $cfg{"loglevel"}
exists $cfg{"loglevel"} defined $cfg{"loglevel"}
Truth table0%0/3
A and B
A= exists $cfg{"loglevel"}B= defined $cfg{"loglevel"}
ABresult
0X0
100
111
118 0 ▶ $cfg{logfile} = exists($cfg{logfile}) && defined($cfg{logfile}) ? $cfg{logfile} : undef;
Branch: 1 branch
BranchTrueFalseTotal
exists $cfg{'logfile'} && defined $cfg{'logfile'} ? : 0 0 0
Condition0%0/3
exists $cfg{"logfile"} and defined $cfg{"logfile"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $cfg{"logfile"} and defined $cfg{"logfile"}
exists $cfg{"logfile"} defined $cfg{"logfile"}
Truth table0%0/3
A and B
A= exists $cfg{"logfile"}B= defined $cfg{"logfile"}
ABresult
0X0
100
111
119
120 0 my $self = bless { %cfg }, $class;
121 0 return $self;
122 }
123 sub get {
124 # Ïðî÷èòàòü óêàçàííûé ïàðàìåòð êîíôèãóðàöèè
125 0 ▶ my $self = shift;
Subroutine get: not called CC=2 SCAR=17.9
Pod documented
126 0 my $key = shift;
127 0 ▶ return undef unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 0 0
128 0 return $self->{$key};
129 }
130 0 ▶sub get_conf { goto &get };
Subroutine get_conf: not called CC=1 SCAR=6.9
Pod documented
131 0 ▶sub conf { goto &get };
Subroutine conf: not called CC=1 SCAR=6.9
Pod documented
132 0 ▶sub config { goto &get };
Subroutine config: not called CC=1 SCAR=6.9
Pod documented
133 0 ▶sub get_config { goto &cget };
Subroutine get_config: not called CC=1 SCAR=6.9
Pod documented
134 sub set {
135 # Óñòàíîâèòü óêàçàííûé ïàðàìåòð êîíôèãóðàöèè
136 0 ▶ my $self = shift;
Subroutine set: not called CC=2 SCAR=17.9
Pod documented
137 0 my $key = shift;
138 0 my $val = shift;
139 0 ▶ croak("Object WWW::MLite::Config not exists") unless $self;
Branch: 1 branch
BranchTrueFalseTotal
unless $self 0 0 0
140 0 $self->{$key} = $val;
141 }
142 0 ▶sub set_conf { goto &set };
Subroutine set_conf: not called CC=1 SCAR=6.9
Pod documented
143 0 ▶sub set_config { goto &set };
Subroutine set_config: not called CC=1 SCAR=6.9
Pod documented
144 sub AUTOLOAD {
145 0 ▶ my $self = shift;
Subroutine AUTOLOAD: not called CC=4 SCAR=30.0
146 0 our $AUTOLOAD;
147 0 my $AL = $AUTOLOAD;
148 0 my $ss = undef;
149 0 ▶ $ss = $1 if $AL=~/\:\:([^\:]+)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $AL =~ /\:\:([^\:]+)$/ 0 0 0
150 0 ▶ if ($ss && defined($self->{$ss})) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ss and defined $self->{$ss}) { } 0 0 0
Condition0%0/3
$ss and defined $self->{$ss}
!ll&&!rl&&r
000
MC/DC0%0/2
$ss and defined $self->{$ss}
$ss defined $self->{$ss}
Truth table0%0/3
A and B
A= $ssB= defined $self->{$ss}
ABresult
0X0
100
111
151 0 return $self->{$ss};
152 } else {
153 0 return undef;
154 }
155 0 return undef;
156 }
157 sub DESTROY {
158 0 ▶ my $self = shift;
Subroutine DESTROY: not called CC=1 SCAR=6.9
159 #print STDERR "Object WWW::MLite::Config destroyed\n";
160 0 return 1;
161 }
162
163 sub _loadconfig {
164 # ×òåíèå êîíôèãóðàöèîííîãî ôàéëà èëè ñîçäàíèå ïóñòîãî
165 0 ▶ my $cfile = shift || '';
Subroutine _loadconfig: not called CC=9 SCAR=45.0
Condition0%0/2
shift() || ''
l!l
00
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
166 0 ▶ my $cdirs = shift || [];
Condition0%0/2
shift() || []
l!l
00
MC/DC0%0/1
shift() || []
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
167
168 0 my %config = (
169 loadstatus => 0
170 );
171
172 # Ïûòàåìñÿ ïðî÷èòàòü êîíôèãóðàöèîííûå äàííûå åñëè óêàçàí ôàéë
173 0 ▶ if ($cfile && -e $cfile) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cfile and -e $cfile) 0 0 0
Condition0%0/3
$cfile and -e $cfile
!ll&&!rl&&r
000
MC/DC0%0/2
$cfile and -e $cfile
$cfile -e $cfile
Truth table0%0/3
A and B
A= $cfileB= -e $cfile
ABresult
0X0
100
111
174 0 my $conf;
175 try {
176 0 ▶ $conf = new Config::General(
Subroutine __ANON__: not called CC=1 SCAR=6.9
177 -ConfigFile => $cfile,
178 -ConfigPath => $cdirs,
179 -ApacheCompatible => 1,
180 -LowerCaseNames => 1,
181 -AutoTrue => 1,
182 );
183 } catch {
184 0 ▶ carp($_);
Subroutine __ANON__: not called CC=1 SCAR=6.9
185 0 };
186 0 ▶ if ($conf && $conf->can('getall')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($conf and $conf->can("getall")) 0 0 0
Condition0%0/3
$conf and $conf->can("getall")
!ll&&!rl&&r
000
MC/DC0%0/2
$conf and $conf->can("getall")
$conf $conf->can("getall")
Truth table0%0/3
A and B
A= $confB= $conf->can("getall")
ABresult
0X0
100
111
187 0 %config = $conf->getall;
188 0 $config{loadstatus} = 1;
189 }
190 0 $config{configfiles} = [];
191 0 $config{configdirs} = $cdirs;
192 0 ▶ $config{configfiles} = [$conf->files] if $conf && $conf->can('files');;
Branch: 1 branch
BranchTrueFalseTotal
if $conf and $conf->can("files") 0 0 0
Condition0%0/3
$conf and $conf->can("files")
!ll&&!rl&&r
000
MC/DC0%0/2
$conf and $conf->can("files")
$conf $conf->can("files")
Truth table0%0/3
A and B
A= $confB= $conf->can("files")
ABresult
0X0
100
111
193 }
194
195 0 return %config;
196 }
197
198 1 1;
« MLite/Store/DBI.pm ↑ Summary MLite/Helper.pm »