blib/lib/Kelp/Module/Config/General.pm

filter: Statementstmt 100% 27 / 27 Branchbran 83.3% 5 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 97.4% 38 / 39 CC 4 SCAR 9.2
CC
4
Cov
97%
load
4.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.5
↑ Summary Build »
1 package Kelp::Module::Config::General;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use 5.008_005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 5 ▶use Kelp::Base 'Kelp::Module::Config';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 5 ▶use Config::General;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 5 our $VERSION = '0.03';
8  
9 5 attr ext => 'conf';
10  
11 sub load {
12 9 ▶ my ( $self, $filename ) = @_;
Subroutine load: called CC=4 SCAR=13.9
Pod documented
13  
14 9 my $conf = Config::General->new(
15 -ConfigFile => $filename,
16 -ForceArray => 1,
17 -IncludeAgain => 1,
18 -InterPolateVars => 1,
19 );
20 9 my %config = $conf->getall;
21  
22 # Hack for using default Log::Dispatch
23 9 ▶ if ( exists $config{modules_init}{Logger} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $config{"modules_init"}{"Logger"}) 2 7 9
24 2 my $outputs = $config{modules_init}{Logger}{outputs};
25
26 my @outputs = map {
27 2 my ( $k, $v ) = ($_, $outputs->{$_});
28 2 my @res;
29 2 ▶ push @res, ( ref $v eq 'ARRAY' ) ? map { [ $k, %$_ ] } @$v
Branch: 2 branches
BranchTrueFalseTotal
ref $v eq 'ARRAY' ? : 1 1 2
ref $v eq 'HASH' ? : 1 0 1
30 : ( ref $v eq 'HASH' ) ? [ $k, %$v ]
31 : [];
32 2 @res;
33 } keys %$outputs;
34 2 $config{modules_init}{Logger}{outputs} = \@outputs;
35 }
36
37 9 return \%config;
38 }
39  
40 5 1;
41 __END__
42  
43 =encoding utf-8
44  
45 =head1 NAME
46  
47 Kelp::Module::Config::General - L<Config::General> as config module for your Kelp applications.
48  
49 =head1 SYNOPSIS
50  
51 # app.psgi
52 use MyApp;
53 my $app = MyApp->new( config_module => 'Config::General' );
54 $app->run;
55  
56 =head1 DESCRIPTION
57  
58 This module provides support of L<Config::General> as your C<Kelp::Module::Config> module.
59  
60 L<Config::General> module is loaded with following configuration options:
61  
62 -ForceArray => 1,
63 -IncludeAgain => 1,
64 -InterPolateVars => 1,
65  
66 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.
67  
68 Example:
69  
70 modules = [ Logger ]
71
72 <modules_init Logger>
73 <outputs Screen>
74 name debug
75 min_level debug
76 newline 1
77 binmode :encoding(UTF-8)
78 </outputs>
79 <outputs Screen>
80 name error
81 min_level error
82 newline 1
83 stderr 1
84 binmode :encoding(UTF-8)
85 </outputs>
86 </modules_init>
87  
88 becomes:
89  
90 {
91 modules => [ 'Logger' ],
92 },
93 {
94 modules_init => {
95 Logger => [
96 [
97 'Screen',
98 name => 'debug',
99 min_level => 'debug',
100 newline => 1
101 binmode => ':encoding(UTF-8)'
102 ], [
103 'Screen',
104 name => 'error',
105 min_level => 'error',
106 newline => 1,
107 stderr => 1,
108 binmode => ':encoding(UTF-8)'
109 ]
110 ],
111 }
112 }
113  
114  
115 =head1 AUTHOR
116  
117 Konstantin Yakunin E<lt>twinhooker@gmail.comE<gt>
118  
119 =head1 COPYRIGHT
120  
121 Copyright 2017- Konstantin Yakunin
122  
123 =head1 LICENSE
124  
125 This library is free software; you can redistribute it and/or modify
126 it under the same terms as Perl itself.
127  
128 =head1 SEE ALSO
129  
130 =cut
↑ Summary Build »