blib/lib/Jedi/Launcher.pm

filter: Statementstmt 85.7% 60 / 70 Branchbran 50.0% 5 / 10 Conditioncond 50.0% 2 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 92.8% 13 / 14 Podpod 100% 4 / 4 totaltotal 80.7% 84 / 104 SCAR 25.8
CC
12
Cov
80%
run
6.0
parse_config
5.2
plack_initialize
4.1
CRAP 13.2
« blib/lib/Jedi/Role/App.pm ↑ Summary Build »
1 #
2 # This file is part of Jedi
3 #
4 # This software is copyright (c) 2013 by celogeek <me@celogeek.com>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 package Jedi::Launcher;
10  
11 # ABSTRACT: Launcher for Jedi App
12  
13 2 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 our $VERSION = '1.006'; # VERSION
15 use MooX::Options
16 2 authors => ['Celogeek <me@celogeek.com>'],
17 synopsis => <<'__EOF__'
18  
19 jedi -c myApp.yml -c myAppProd.yml
20  
21 In myApp.yml:
22  
23 Jedi:
24 Roads:
25 t::lib::configs::myConfigRoot: /
26 t::lib::configs::myConfigAdmin: /admin
27  
28 In myAppProd.yml:
29  
30 Plack:
31 server: Starman
32 env: production
33 Starman:
34 workers: 2
35 port: 9999
36  
37 __EOF__
38 2 ▶ ;
Subroutine BEGIN: called CC=1 SCAR=0.0
39 2 ▶use feature 'say';
Subroutine BEGIN: called CC=1 SCAR=0.0
40 2 ▶use Config::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 2 ▶use Jedi;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 2 ▶use Plack::Runner;
Subroutine BEGIN: called CC=1 SCAR=0.0
44 2 ▶use lib ();
Subroutine BEGIN: called CC=1 SCAR=0.0
45  
46 option 'config' => (
47 is => 'ro',
48 format => 's@',
49 required => 1,
50 short => 'c',
51 doc => 'config files to load',
52 isa => sub {
53 1 ▶ my $files = shift;
Subroutine __ANON__: called CC=3 SCAR=11.4
54 1 for my $file ( @{$files} ) {
55 1 ▶ next if -f $file;
Branch: 1 branch
BranchTrueFalseTotal
if -f $file 1 0 1
56 0 __PACKAGE__->options_usage( 1, "'$file' doesn't exist !\n" );
57 }
58 1 return;
59 }
60 2 );
61  
62 option 'lib' => (
63 is => 'ro',
64 format => 's@',
65 short => 'I',
66 doc => 'library to include',
67 1 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
68 2 );
69  
70 sub run {
71 0 ▶ my ($self) = @_;
Subroutine run: not called CC=2 SCAR=17.9
Pod documented
72  
73 0 for my $lib ( @{ $self->lib } ) {
74 0 lib->import($lib);
75 }
76  
77 0 my $config = $self->parse_config;
78 0 my $jedi = $self->jedi_initialize($config);
79 0 my ( $runner, $options ) = $self->plack_initialize($config);
80  
81 0 say "Loading : plackup ", join( " ", @$options );
82  
83 0 return $runner->run( $jedi->start );
84 }
85  
86 sub parse_config {
87 1 ▶ my ($self) = @_;
Subroutine parse_config: called CC=5 SCAR=16.4
Pod documented
88  
89 1 my $config
90 = Config::Any->load_files( { files => $self->config, use_ext => 1 } );
91 1 my $config_merged = {};
92 1 for my $c ( map { values %$_ } @$config ) {
93 1 %$config_merged = ( %$config_merged, %$c );
94 }
95  
96 1 ▶ croak "Jedi section is missing" if !defined $config_merged->{Jedi};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config_merged->{"Jedi"} 0 1 1
97 croak "Jedi/Roads section is missing"
98 1 ▶ if !defined $config_merged->{Jedi}{Roads};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $config_merged->{"Jedi"}{"Roads"} 0 1 1
99 croak "Jedi/Roads shoud be 'module: path'"
100 1 ▶ if ref $config_merged->{Jedi}{Roads} ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $config_merged->{"Jedi"}{"Roads"} ne "HASH" 0 1 1
101  
102 1 return $config_merged;
103 }
104  
105 sub jedi_initialize {
106 1 ▶ my ( $self, $config ) = @_;
Subroutine jedi_initialize: called CC=2 SCAR=6.9
Pod documented
107  
108 1 my $jedi = Jedi->new( config => $config );
109 1 my %roads = %{ $config->{Jedi}{Roads} };
110 1 for my $module ( keys %roads ) {
111 2 $jedi->road( $roads{$module}, $module );
112 }
113  
114 1 return $jedi;
115 }
116  
117 sub plack_initialize {
118 1 ▶ my ( $self, $config ) = @_;
Subroutine plack_initialize: called CC=4 SCAR=14.2
Pod documented
119  
120 1 ▶ my $plack_config = $config->{Plack} // {};
Condition50%1/2
$config->{"Plack"} // {}
l!l
10
MC/DC0%0/1
$config->{"Plack"} // {}
$config->{"Plack"}
Truth table50%1/2
A
A= $config->{"Plack"}
Aresult
11
00
121 my $server_config
122 = $plack_config->{server}
123 ? $config->{ $plack_config->{server} } // {}
124 1 ▶ : {};
Branch: 1 branch
BranchTrueFalseTotal
$plack_config->{'server'} ? : 1 0 1
Condition50%1/2
$$config{$plack_config->{"server"}} // {}
l!l
10
MC/DC0%0/1
$$config{$plack_config->{"server"}} // {}
$$config{$plack_config->{"server"}}
Truth table50%1/2
A
A= $$config{$plack_config->{"server"}}
Aresult
11
00
125 my @options = (
126 2 ( map { "--" . $_ => $plack_config->{$_} } sort keys %$plack_config ),
127 1 ( map { "--" . $_ => $server_config->{$_} }
128 sort keys %$server_config
129 ),
130 );
131  
132 1 my $runner = Plack::Runner->new;
133  
134 1 $runner->parse_options( @options );
135  
136 1 return $runner, \@options;
137 }
138  
139 2 1;
140  
141 __END__
« blib/lib/Jedi/Role/App.pm ↑ Summary Build »