| 1 | package Mojolicious::Plugin::ConfigAny; | ||||||||||||||||||||||||
| 2 | 2 | ▶ | use Mojo::Base 'Mojolicious::Plugin'; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 3 | 2 | ▶ | use Config::Any; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 4 | 2 | ▶ | use File::ConfigDir qw(config_dirs); | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 5 | 2 | ▶ | use IO::All; | ||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 6 | 2 | our $VERSION = '0.1.3'; # VERSION | |||||||||||||||||||||||
| 7 | # ABSTRACT: Mojolicious Plugin for Config::Any support | ||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||
| 10 | 1 | ▶ | sub register { | ||||||||||||||||||||||
|
Subroutine
register: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||||||||||||||||
| 11 | 1 | my ($self, $app, $conf) = @_; | |||||||||||||||||||||||
| 12 | # config_dirs | ||||||||||||||||||||||||
| 13 | 1 | ▶ | my $identifier = $conf->{identifier} // $app->moniker; | ||||||||||||||||||||||
|
Condition33%1/3
$conf->{"identifier"} // $app->moniker
MC/DC0%0/2
$conf->{"identifier"} // $app->moniker
$conf->{"identifier"}
$app->moniker
Truth table33%1/3
A // B
A= $conf->{"identifier"}B= $app->moniker
| |||||||||||||||||||||||||
| 14 | 1 | ▶ | my $prefix = $conf->{prefix} // $app->moniker; | ||||||||||||||||||||||
|
Condition33%1/3
$conf->{"prefix"} // $app->moniker
MC/DC0%0/2
$conf->{"prefix"} // $app->moniker
$conf->{"prefix"}
$app->moniker
Truth table33%1/3
A // B
A= $conf->{"prefix"}B= $app->moniker
| |||||||||||||||||||||||||
| 15 | 1 | ▶ | my $mode = $conf->{mode} // $app->mode // 'production'; | ||||||||||||||||||||||
|
Condition40%2/5
($conf->{"mode"} // $app->mode) // "production"
$conf->{"mode"} // $app->mode
MC/DC0%0/2
($conf->{"mode"} // $app->mode) // "production"
$conf->{"mode"}
$app->mode
Truth table33%1/3
A // B
A= $conf->{"mode"}B= $app->mode
| |||||||||||||||||||||||||
| 16 | 1 | my @config_dirs = config_dirs($identifier); | |||||||||||||||||||||||
| 17 | # TODO: extensions might need checking. | ||||||||||||||||||||||||
| 18 | 0 | ▶ | my @config_extentions = $conf->{extensions} ? @{$conf->{extensions}} : Config::Any->extensions(); | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 19 | 1 | my $ext_pattern = join '|', @config_extentions; | |||||||||||||||||||||||
| 20 | 1 | my $config_files_pattern = qr/^$prefix(\.$mode)?\.($ext_pattern)$/; | |||||||||||||||||||||||
| 21 | my @config_files = map { | ||||||||||||||||||||||||
| 22 | 1 | my $dir = $_; | |||||||||||||||||||||||
| 23 | 4 | ▶ | map { $_->pathname } io->dir($dir)->filter(sub { | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 24 | 5 | $_->filename =~ $config_files_pattern; | |||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||
| 26 | 2 | )->All_Files(); | |||||||||||||||||||||||
| 27 | } @config_dirs; | ||||||||||||||||||||||||
| 28 | 1 | ▶ | $app->helper(config_dirs => sub { @config_dirs }); | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 29 | 1 | ▶ | $app->helper(config_files => sub { @config_files }); | ||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||
| 31 | 1 | ▶ | if (@config_files) { | ||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||
| 32 | 1 | my $configs = Config::Any->load_files( | |||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||
| 34 | files => \@config_files, | ||||||||||||||||||||||||
| 35 | use_ext => 1 | ||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||
| 38 | 1 | my %configs = map { %$_ } map { values %$_ } @$configs; | |||||||||||||||||||||||
| 39 | 1 | $app->defaults(config => $app->config)->config(%configs)->config; | |||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||
| 44 | 2 | 1; | |||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||
| 46 | __END__ | ||||||||||||||||||||||||