line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CGI::Lazy::Config; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
453624
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
43
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
6
|
use JSON; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
6
|
1
|
|
|
1
|
|
143
|
use Carp; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
80
|
|
7
|
1
|
|
|
1
|
|
628
|
use CGI::Lazy::Globals; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
625
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
10
|
|
|
|
|
|
|
sub AUTOLOAD { |
11
|
6
|
|
|
6
|
|
11
|
my $self = shift; |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
|
|
9
|
my $name = our $AUTOLOAD; |
14
|
6
|
50
|
|
|
|
19
|
return if $name =~ /::DESTROY$/; |
15
|
6
|
|
|
|
|
27
|
my @list = split "::", $name; |
16
|
6
|
|
|
|
|
12
|
my $value = pop @list; |
17
|
|
|
|
|
|
|
|
18
|
6
|
50
|
|
|
|
15
|
if (@_) { |
19
|
0
|
|
|
|
|
0
|
return $self->{_config}->{$value} = shift; |
20
|
|
|
|
|
|
|
} else { |
21
|
6
|
|
|
|
|
50
|
return $self->{_config}->{$value}; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
26
|
|
|
|
|
|
|
sub configfile { |
27
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
28
|
|
|
|
|
|
|
|
29
|
0
|
|
|
|
|
0
|
return $self->{_configfile}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
33
|
|
|
|
|
|
|
sub get { |
34
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
35
|
0
|
|
|
|
|
0
|
my $prop = shift; |
36
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
0
|
return $self->{_config}{$prop}; |
38
|
|
|
|
|
|
|
} |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
41
|
|
|
|
|
|
|
sub new { |
42
|
1
|
|
|
1
|
1
|
3
|
my $class = shift; |
43
|
1
|
|
|
|
|
2
|
my $q = shift; |
44
|
1
|
|
|
|
|
2
|
my $filename = shift; |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
2
|
my $json; |
47
|
|
|
|
|
|
|
my $conf; |
48
|
|
|
|
|
|
|
|
49
|
1
|
50
|
|
|
|
5
|
if (ref $filename) { |
50
|
1
|
|
|
|
|
2
|
$conf = $filename; |
51
|
|
|
|
|
|
|
} else { |
52
|
0
|
|
|
|
|
0
|
eval { |
53
|
0
|
0
|
|
|
|
0
|
open IF, "< $CONFIGROOT/$filename" or croak $!; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
0
|
while () { |
56
|
0
|
0
|
|
|
|
0
|
$json .= $_ unless ($_ =~ /^\s*#/); |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
0
|
close IF; |
59
|
|
|
|
|
|
|
}; |
60
|
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
0
|
if ($@) { |
62
|
0
|
|
|
|
|
0
|
$q->errorHandler->noConfig($filename); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
eval { |
66
|
0
|
|
|
|
|
0
|
$conf = from_json($json); |
67
|
|
|
|
|
|
|
}; |
68
|
|
|
|
|
|
|
|
69
|
0
|
0
|
|
|
|
0
|
if ($@) { |
70
|
0
|
|
|
|
|
0
|
$q->errorHandler->badConfig($filename); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
6
|
my $self = {_q => $q, _config =>$conf, _configfile => $filename}; |
75
|
|
|
|
|
|
|
|
76
|
1
|
|
|
|
|
3
|
bless $self, $class; |
77
|
|
|
|
|
|
|
|
78
|
1
|
|
|
|
|
5
|
return $self; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
#------------------------------------------------------------------------------- |
82
|
|
|
|
|
|
|
sub set { |
83
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
84
|
0
|
|
|
|
|
|
my $name = shift; |
85
|
0
|
|
|
|
|
|
my $value = shift; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
$self->{_config}{$name} = $value; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1 |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |