| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 37 | 14 | my $file_abs = path($file)->absolute; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 14 | ▶ | croak "Config file `$file` does not exist.\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 60 | my $f = $files[$i]; | |||||||||||||||||||||||||||
| 51 | 60 | ▶ | next unless defined $f && -e $f; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $f and -e $f
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
| |||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 19 | ▶ | $adjective = $i ? 'default ' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 19 | ▶ | if ($f =~ /\.ya?ml$/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 65 | . "`$f`: $@\n" if $@; | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 16 | last; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 24 | ▶ | croak "Config is not a hash reference.\n" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||