blib/lib/Minima/Setup.pm

filter: Statementstmt 100% 54 / 54 Branchbran 100% 20 / 20 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 100% 92 / 92 CC 13 SCAR 19.6
CC
13
Cov
100%
prepare
12.0
import
2.0
BEGIN
1.0
CRAP 7.1
↑ Summary blib/lib/Minima/Controller.pm »
1 5 ▶use v5.40;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Minima::Setup;
4  
5 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use Minima::App;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use Plack::Test;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use YAML::XS 'LoadFile';
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 5 our $config = {};
12 5 our $app;
13 5 our $base;
14  
15 sub import
16 27 ▶{
Subroutine import: called CC=2 SCAR=6.9
17 27 shift; # discard package name
18  
19 # If we were called from a .psgi, save
20 # its parent as the base directory
21 27 my $caller = path( (caller)[1] );
22 27 ▶ if ($caller->basename =~ /\.psgi$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($caller->basename =~ /\.psgi$/u) { } 1 26 27
23 1 $base = $caller->absolute->parent;
24 } else {
25 26 $base = path('.')->absolute;
26 }
27  
28 27 prepare(@_);
29 }
30  
31 28 ▶sub prepare ($file = undef)
Subroutine prepare: called CC=12 SCAR=24.8
Pod documented
32 28 {
33 28 my $default_prefix = $base->child('etc/config');
34 28 my @files = map { "$default_prefix.$_" } qw/ yaml yml pl /;
35  
36 28 ▶ if ($file) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file) 14 14 28
37 14 my $file_abs = path($file)->absolute;
38  
39 14 ▶ croak "Config file `$file` does not exist.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless -e $file_abs 1 13 14
40 unless -e $file_abs;
41  
42 13 $file = $file_abs;
43 }
44 27 unshift @files, $file;
45  
46 27 my $adjective;
47  
48 27 ▶ for (my $i = 0; $i < @files; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @files) 60 8 68
49  
50 60 my $f = $files[$i];
51 60 ▶ next unless defined $f && -e $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $f and -e $f 41 19 60
Condition100%3/3
defined $f and -e $f
!ll&&!rl&&r
142719
MC/DC100%2/2
defined $f and -e $f
defined $f -e $f
Truth table100%3/3
A and B
A= defined $fB= -e $f
ABresult
0X0
100
111
52  
53 19 ▶ $adjective = $i ? 'default ' : '';
Branch: 1 branch
BranchTrueFalseTotal
$i ? : 6 13 19
54  
55 19 ▶ if ($f =~ /\.ya?ml$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /\.ya?ml$/u) { } 10 9 19
56 10 try {
57 10 $config = LoadFile $f;
58 } catch ($e) {
59 2 croak "Failed to parse ${adjective}config file "
60 . "`$f`:\n$e\n";
61 }
62 } else {
63 9 $config = do $f;
64 9 ▶ croak "Failed to parse ${adjective}config file "
Branch: 1 branch
BranchTrueFalseTotal
if $@ 1 8 9
65 . "`$f`: $@\n" if $@;
66 }
67  
68 16 last;
69 }
70  
71 24 ▶ croak "Config is not a hash reference.\n"
Branch: 1 branch
BranchTrueFalseTotal
unless ref $Minima::Setup::config eq ref {} 6 18 24
72 unless ref $config eq ref {};
73  
74 # If the loaded config does not set base_dir,
75 # set it to the saved .psgi directory
76 $config->{base_dir} = $base->stringify
77 18 ▶ unless defined $config->{base_dir};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $Minima::Setup::config->{"base_dir"} 14 4 18
78  
79 # Initialize app
80 18 $app = Minima::App->new(
81 configuration => $config,
82 );
83 }
84  
85 5 ▶sub init ($env)
Subroutine init: called CC=1 SCAR=0.0
Pod documented
86 {
87 5 $app->set_env($env);
88 5 $app->run;
89 }
90  
91 sub test
92 1 ▶{
Subroutine test: called CC=1 SCAR=0.0
Pod documented
93 1 Plack::Test->create(\&init);
94 }
95  
96 5 1;
97  
98 __END__
↑ Summary blib/lib/Minima/Controller.pm »