line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Kelp::Module::Config::General; |
2
|
5
|
|
|
5
|
|
2541
|
use strict; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
116
|
|
3
|
5
|
|
|
5
|
|
102
|
use 5.008_005; |
|
5
|
|
|
|
|
11
|
|
4
|
5
|
|
|
5
|
|
15
|
use Kelp::Base 'Kelp::Module::Config'; |
|
5
|
|
|
|
|
5
|
|
|
5
|
|
|
|
|
26
|
|
5
|
5
|
|
|
5
|
|
51139
|
use Config::General; |
|
5
|
|
|
|
|
60328
|
|
|
5
|
|
|
|
|
1234
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
attr ext => 'conf'; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub load { |
12
|
9
|
|
|
9
|
1
|
1912
|
my ( $self, $filename ) = @_; |
13
|
|
|
|
|
|
|
|
14
|
9
|
|
|
|
|
46
|
my $conf = Config::General->new( |
15
|
|
|
|
|
|
|
-ConfigFile => $filename, |
16
|
|
|
|
|
|
|
-ForceArray => 1, |
17
|
|
|
|
|
|
|
-IncludeAgain => 1, |
18
|
|
|
|
|
|
|
-InterPolateVars => 1, |
19
|
|
|
|
|
|
|
-IncludeRelative => 1, |
20
|
|
|
|
|
|
|
); |
21
|
9
|
|
|
|
|
13912
|
my %config = $conf->getall; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Hack for using default Log::Dispatch |
24
|
9
|
100
|
|
|
|
73
|
if ( exists $config{modules_init}{Logger} ) { |
25
|
2
|
|
|
|
|
2
|
my $outputs = $config{modules_init}{Logger}{outputs}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my @outputs = map { |
28
|
2
|
|
|
|
|
4
|
my ( $k, $v ) = ($_, $outputs->{$_}); |
|
2
|
|
|
|
|
3
|
|
29
|
2
|
|
|
|
|
3
|
my @res; |
30
|
2
|
50
|
|
|
|
12
|
push @res, ( ref $v eq 'ARRAY' ) ? map { [ $k, %$_ ] } @$v |
|
2
|
100
|
|
|
|
7
|
|
31
|
|
|
|
|
|
|
: ( ref $v eq 'HASH' ) ? [ $k, %$v ] |
32
|
|
|
|
|
|
|
: []; |
33
|
2
|
|
|
|
|
6
|
@res; |
34
|
|
|
|
|
|
|
} keys %$outputs; |
35
|
2
|
|
|
|
|
7
|
$config{modules_init}{Logger}{outputs} = \@outputs; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
9
|
|
|
|
|
108
|
return \%config; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=encoding utf-8 |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 NAME |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
Kelp::Module::Config::General - L<Config::General> as config module for your Kelp applications. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 SYNOPSIS |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# app.psgi |
53
|
|
|
|
|
|
|
use MyApp; |
54
|
|
|
|
|
|
|
my $app = MyApp->new( config_module => 'Config::General' ); |
55
|
|
|
|
|
|
|
$app->run; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
This module provides support of L<Config::General> as your C<Kelp::Module::Config> module. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
L<Config::General> module is loaded with following configuration options: |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
-ForceArray => 1, |
64
|
|
|
|
|
|
|
-IncludeAgain => 1, |
65
|
|
|
|
|
|
|
-InterPolateVars => 1, |
66
|
|
|
|
|
|
|
-IncludeRelative => 1, |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Because L<Config::General> provides key/value interface you are not able to create array of arrays for your default L<Kelp::Module::Logger> configuration. This module does it for you but only in this situation. |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Example: |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
modules = [ Logger ] |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
<modules_init Logger> |
75
|
|
|
|
|
|
|
<outputs Screen> |
76
|
|
|
|
|
|
|
name debug |
77
|
|
|
|
|
|
|
min_level debug |
78
|
|
|
|
|
|
|
newline 1 |
79
|
|
|
|
|
|
|
binmode :encoding(UTF-8) |
80
|
|
|
|
|
|
|
</outputs> |
81
|
|
|
|
|
|
|
<outputs Screen> |
82
|
|
|
|
|
|
|
name error |
83
|
|
|
|
|
|
|
min_level error |
84
|
|
|
|
|
|
|
newline 1 |
85
|
|
|
|
|
|
|
stderr 1 |
86
|
|
|
|
|
|
|
binmode :encoding(UTF-8) |
87
|
|
|
|
|
|
|
</outputs> |
88
|
|
|
|
|
|
|
</modules_init> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
becomes: |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
{ |
93
|
|
|
|
|
|
|
modules => [ 'Logger' ], |
94
|
|
|
|
|
|
|
}, |
95
|
|
|
|
|
|
|
{ |
96
|
|
|
|
|
|
|
modules_init => { |
97
|
|
|
|
|
|
|
Logger => [ |
98
|
|
|
|
|
|
|
[ |
99
|
|
|
|
|
|
|
'Screen', |
100
|
|
|
|
|
|
|
name => 'debug', |
101
|
|
|
|
|
|
|
min_level => 'debug', |
102
|
|
|
|
|
|
|
newline => 1 |
103
|
|
|
|
|
|
|
binmode => ':encoding(UTF-8)' |
104
|
|
|
|
|
|
|
], [ |
105
|
|
|
|
|
|
|
'Screen', |
106
|
|
|
|
|
|
|
name => 'error', |
107
|
|
|
|
|
|
|
min_level => 'error', |
108
|
|
|
|
|
|
|
newline => 1, |
109
|
|
|
|
|
|
|
stderr => 1, |
110
|
|
|
|
|
|
|
binmode => ':encoding(UTF-8)' |
111
|
|
|
|
|
|
|
] |
112
|
|
|
|
|
|
|
], |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
=head1 AUTHOR |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
Konstantin Yakunin E<lt>twinhooker@gmail.comE<gt> |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 COPYRIGHT |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Copyright 2017- Konstantin Yakunin |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 LICENSE |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
128
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SEE ALSO |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |