blib/lib/Mojolicious/Plugin/ConfigAny.pm

filter: Statementstmt 97.3% 37 / 38 Branchbran 50.0% 2 / 4 Conditioncond 36.3% 4 / 11 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 76.4% 52 / 68 CC 7 SCAR 14.8
CC
7
Cov
81%
register
7.8
BEGIN
1.0
BEGIN
1.0
CRAP 4.4
↑ Summary
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
l!l&&r!l&&!r
010
MC/DC0%0/2
$conf->{"identifier"} // $app->moniker
$conf->{"identifier"} $app->moniker
Truth table33%1/3
A // B
A= $conf->{"identifier"}B= $app->moniker
ABresult
1X1
011
000
14 1 ▶ my $prefix = $conf->{prefix} // $app->moniker;
Condition33%1/3
$conf->{"prefix"} // $app->moniker
l!l&&r!l&&!r
010
MC/DC0%0/2
$conf->{"prefix"} // $app->moniker
$conf->{"prefix"} $app->moniker
Truth table33%1/3
A // B
A= $conf->{"prefix"}B= $app->moniker
ABresult
1X1
011
000
15 1 ▶ my $mode = $conf->{mode} // $app->mode // 'production';
Condition40%2/5
($conf->{"mode"} // $app->mode) // "production"
l!l
10
$conf->{"mode"} // $app->mode
l!l&&r!l&&!r
010
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
ABresult
1X1
011
000
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
BranchTrueFalseTotal
$conf->{'extensions'} ? : 0 1 1
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
BranchTrueFalseTotal
if (@config_files) 1 0 1
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__
↑ Summary