| 1 | package Kelp::Module::Config::ConfigGeneral; | ||||||||||||||
| 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.01'; | |||||||||||||
| 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
| |||||||||||||||
| 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
| |||||||||||||||
| 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::ConfigGeneral - Config::General in your Kelp application | ||||||||||||||
| 48 | |||||||||||||||
| 49 | =head1 SYNOPSIS | ||||||||||||||
| 50 | |||||||||||||||
| 51 | # app.psgi | ||||||||||||||
| 52 | use MyApp; | ||||||||||||||
| 53 | my $app = MyApp->new( config_module => 'Config::ConfigGeneral' ); | ||||||||||||||
| 54 | $app->run; | ||||||||||||||
| 55 | |||||||||||||||
| 56 | =head1 DESCRIPTION | ||||||||||||||
| 57 | |||||||||||||||
| 58 | This module provides support of L<Config::General> in your L<Kelp> applications. | ||||||||||||||
| 59 | |||||||||||||||
| 60 | Because L<Config::General> provides key/value interface you are not able to create array of arrays for your L<Kelp::Module::Logger> configuration. This module does it for you. | ||||||||||||||
| 61 | |||||||||||||||
| 62 | Example: | ||||||||||||||
| 63 | modules = [ Logger ] | ||||||||||||||
| 64 | |||||||||||||||
| 65 | <modules_init Logger> | ||||||||||||||
| 66 | <outputs Screen> | ||||||||||||||
| 67 | name debug | ||||||||||||||
| 68 | min_level debug | ||||||||||||||
| 69 | newline 1 | ||||||||||||||
| 70 | binmode :encoding(UTF-8) | ||||||||||||||
| 71 | </outputs> | ||||||||||||||
| 72 | <outputs Screen> | ||||||||||||||
| 73 | name error | ||||||||||||||
| 74 | min_level error | ||||||||||||||
| 75 | newline 1 | ||||||||||||||
| 76 | stderr 1 | ||||||||||||||
| 77 | binmode :encoding(UTF-8) | ||||||||||||||
| 78 | </outputs> | ||||||||||||||
| 79 | </modules_init> | ||||||||||||||
| 80 | |||||||||||||||
| 81 | =head1 AUTHOR | ||||||||||||||
| 82 | |||||||||||||||
| 83 | Konstantin Yakunin E<lt>twinhooker@gmail.comE<gt> | ||||||||||||||
| 84 | |||||||||||||||
| 85 | =head1 COPYRIGHT | ||||||||||||||
| 86 | |||||||||||||||
| 87 | Copyright 2017- Konstantin Yakunin | ||||||||||||||
| 88 | |||||||||||||||
| 89 | =head1 LICENSE | ||||||||||||||
| 90 | |||||||||||||||
| 91 | This library is free software; you can redistribute it and/or modify | ||||||||||||||
| 92 | it under the same terms as Perl itself. | ||||||||||||||
| 93 | |||||||||||||||
| 94 | =head1 SEE ALSO | ||||||||||||||
| 95 | |||||||||||||||
| 96 | =cut | ||||||||||||||