line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::ConfigAny; |
2
|
2
|
|
|
2
|
|
5334
|
use Mojo::Base 'Mojolicious::Plugin'; |
|
2
|
|
|
|
|
2989
|
|
|
2
|
|
|
|
|
13
|
|
3
|
2
|
|
|
2
|
|
2951
|
use Config::Any; |
|
2
|
|
|
|
|
24578
|
|
|
2
|
|
|
|
|
72
|
|
4
|
2
|
|
|
2
|
|
1746
|
use File::ConfigDir qw(config_dirs); |
|
2
|
|
|
|
|
137518
|
|
|
2
|
|
|
|
|
184
|
|
5
|
2
|
|
|
2
|
|
1760
|
use IO::All; |
|
2
|
|
|
|
|
23474
|
|
|
2
|
|
|
|
|
19
|
|
6
|
|
|
|
|
|
|
our $VERSION = '0.1.2'; # VERSION |
7
|
|
|
|
|
|
|
# ABSTRACT: Mojolicious Plugin for Config::Any support |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
sub register { |
11
|
1
|
|
|
1
|
1
|
991
|
my ($self, $app, $conf) = @_; |
12
|
|
|
|
|
|
|
# config_dirs |
13
|
1
|
|
33
|
|
|
13
|
my $identifier = $conf->{identifier} // $app->moniker; |
14
|
1
|
|
33
|
|
|
15
|
my $prefix = $conf->{prefix} // $app->moniker; |
15
|
1
|
|
33
|
|
|
19
|
my $mode = $conf->{mode} // $app->mode // 'production'; |
|
|
|
50
|
|
|
|
|
16
|
1
|
|
|
|
|
12
|
my @config_dirs = config_dirs($identifier); |
17
|
|
|
|
|
|
|
# TODO: extensions might need checking. |
18
|
1
|
50
|
|
|
|
63776
|
my @config_extentions = $conf->{extensions} ? @{$conf->{extensions}} : Config::Any->extensions(); |
|
0
|
|
|
|
|
0
|
|
19
|
1
|
|
|
|
|
16155
|
my $ext_pattern = join '|', @config_extentions; |
20
|
1
|
|
|
|
|
68
|
my $config_files_pattern = qr/^$prefix(\.$mode)?\.($ext_pattern)$/; |
21
|
|
|
|
|
|
|
my @config_files = map { |
22
|
1
|
|
|
|
|
4
|
my $dir = $_; |
|
1
|
|
|
|
|
4
|
|
23
|
2
|
|
|
|
|
146
|
map { $_->pathname } io->dir($dir)->filter(sub { |
24
|
3
|
|
|
3
|
|
70281
|
$_->filename =~ $config_files_pattern; |
25
|
|
|
|
|
|
|
} |
26
|
1
|
|
|
|
|
9
|
)->All_Files(); |
27
|
|
|
|
|
|
|
} @config_dirs; |
28
|
1
|
|
|
0
|
|
80
|
$app->helper(config_dirs => sub { @config_dirs }); |
|
0
|
|
|
|
|
0
|
|
29
|
1
|
|
|
0
|
|
57
|
$app->helper(config_files => sub { @config_files }); |
|
0
|
|
|
|
|
0
|
|
30
|
|
|
|
|
|
|
|
31
|
1
|
50
|
|
|
|
36
|
if (@config_files) { |
32
|
1
|
|
|
|
|
15
|
my $configs = Config::Any->load_files( |
33
|
|
|
|
|
|
|
{ |
34
|
|
|
|
|
|
|
files => \@config_files, |
35
|
|
|
|
|
|
|
use_ext => 1 |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
); |
38
|
0
|
|
|
|
|
|
my %configs = map { %$_ } map { values %$_ } @$configs; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
$app->defaults(config => $app->config)->config(%configs)->config; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
1; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
__END__ |