blib/lib/MojoX/Linda.pm

filter: Statementstmt 85.0% 51 / 60 Branchbran 50.0% 12 / 24 Conditioncond 17.6% 3 / 17 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 90.0% 9 / 10 Podpod 0.0% 0 / 2 totaltotal 61.4% 75 / 122 CC 24 SCAR 29.5
CC
24
Cov
65%
__ANON__
42.0
conf
20.8
run
13.1
CRAP 19.0
↑ Summary
1 package MojoX::Linda;
2 # ABSTRACT: Plausibly helpful (and probably drunk) wrapper around morbo
3  
4 2 ▶use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use exact;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Class::Method::Modifiers 'install_modifier';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Config::App ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use File::Find 'find';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Mojo::Server::Morbo;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Mojo::File 'path';
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 our $VERSION = '1.05'; # VERSION
14  
15 1 ▶sub conf ($conf) {
Subroutine conf: called CC=14 SCAR=30.3
Pod undocumented
16 1 my $conf_app = Config::App->find;
17 1 ▶ my $mojo_linda = ($conf_app) ? $conf_app->get( qw( mojolicious linda ) ) : {};
Branch: 1 branch
BranchTrueFalseTotal
$conf_app ? : 0 1 1
18  
19 1 ▶ $conf->{$_} //= $mojo_linda->{$_} for ( qw( silent app production backend ) );
Condition33%1/3
$conf->{$_} //= $mojo_linda->{$_}
l!l&&r!l&&!r
004
MC/DC0%0/2
$conf->{$_} //= $mojo_linda->{$_}
$conf->{$_} $mojo_linda->{$_}
Truth table33%1/3
A //= B
A= $conf->{$_}B= $mojo_linda->{$_}
ABresult
1X1
011
000
20 1 ▶ $conf->{app} //= $ARGV[0] || do {
Condition33%2/6
$conf->{"app"} //= $ARGV[0] || do { my $match; foreach my $file (@{path(".")->list_tree->to_array}) { next unless -x $file; if ($file->slurp =~ /\b( Mojolicious::Commands\s*\-\s*>\s*start_app| MojoX::ConfigAppStart\s*\-\s*>\s*start )\b/ux) { $match = $file->to_string; last; } ; } ; $match }
l!l&&r!l&&!r
001
$ARGV[0] || do { my $match; foreach my $file (@{path('.')->list_tree->to_array}) { next unless -x $file; if ($file->slurp =~ /\b( Mojolicious::Commands\s*\-\s*>\s*start_app| MojoX::ConfigAppStart\s*\-\s*>\s*start )\b/ux) { $match = $file->to_string; last; } ; } ; $match }
l!l&&r!l&&!r
001
MC/DC0%0/3
$conf->{"app"} //= $ARGV[0] || do { my $match; foreach my $file (@{path(".")->list_tree->to_array}) { next unless -x $file; if ($file->slurp =~ /\b( Mojolicious::Commands\s*\-\s*>\s*start_app| MojoX::ConfigAppStart\s*\-\s*>\s*start )\b/ux) { $match = $file->to_string; last; } ; } ; $match }
$conf->{"app"} $ARGV[0] do { my $match; foreach my $file (@{path('.')->list_tree->to_array}) { next unless -x $file; if ($file->slurp =~ /\b( Mojolicious::Commands\s*\-\s*>\s*start_app| MojoX::ConfigAppStart\s*\-\s*>\s*start )\b/ux) { $match = $file->to_string; last; } ; } ; $match }
Truth table0%0/4
A //= B || C
A= $conf->{"app"}B= $ARGV[0]C= do { my $match; foreach my $file (@{path('.')->list_tree->to_array}) { next unless -x $file; if ($file->slurp =~ /\b( Mojolicious::Commands\s*\-\s*>\s*start_app| MojoX::ConfigAppStart\s*\-\s*>\s*start )\b/ux) { $match = $file->to_string; last; } ; } ; $match }
ABCresult
1XX1
01X1
0011
0000
21 1 my $match;
22 1 for my $file ( path('.')->list_tree->to_array->@* ) {
23 50 ▶ next unless -x $file;
Branch: 1 branch
BranchTrueFalseTotal
unless -x $file 48 2 50
24 2 ▶ if ( $file->slurp =~ /\b(
Branch: 1 branch
BranchTrueFalseTotal
if ($file->slurp =~ /\b( Mojolicious::Commands\s*\-\s*>\s*start_app| MojoX::ConfigAppStart\s*\-\s*>\s*start )\b/ux) 0 2 2
25 Mojolicious::Commands\s*\-\s*>\s*start_app|
26 MojoX::ConfigAppStart\s*\-\s*>\s*start
27 )\b/x ) {
28 0 $match = $file->to_string;
29 0 last;
30 }
31 }
32 1 $match;
33 };
34  
35 1 for my $name ( qw( listen watch ) ) {
36 0 my %hash = map { $_ => 1 } $conf->{$name}->@*, $mojo_linda->{$name}->@*;
37 2 $conf->{$name} = [ keys %hash ];
38 }
39  
40 1 ▶ unless ( $conf->{listen}->@* ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$conf->{"listen"}}) 1 0 1
41 1 for ( 3000 .. 3999 ) {
42 1 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ("IO::Socket::INET"->new("PeerAddr", "localhost", "Proto", "tcp", "PeerPort", $_)) 1 0 1
43 IO::Socket::INET->new(
44 PeerAddr => 'localhost',
45 Proto => 'tcp',
46 PeerPort => $_,
47 )
48 ) {
49 1 $conf->{listen} = [ 'http://*:' . $_ ];
50 1 last;
51 }
52 }
53 }
54  
55 1 ▶ $conf_app->deimport if $conf_app;
Branch: 1 branch
BranchTrueFalseTotal
if $conf_app 0 1 1
56  
57 1 return $conf;
58 }
59  
60 1 ▶sub run ($conf) {
Subroutine run: called CC=6 SCAR=25.8
Pod undocumented
61 1 ▶ $ENV{MOJO_MODE} = 'production' if $conf->{production};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"production"} 0 1 1
62 1 ▶ $ENV{MOJO_MORBO_BACKEND} = $conf->{backend} if $conf->{backend};
Branch: 1 branch
BranchTrueFalseTotal
if $conf->{"backend"} 0 1 1
63  
64 0 ▶ install_modifier( 'Mojo::Server::Morbo', 'after', '_spawn', sub {
Subroutine __ANON__: not called CC=6 SCAR=37.4
65 0 ▶ say ' Silent : ', ( ( $conf->{silent} ) ? 'Yes' : 'No' );
Branch: 1 branch
BranchTrueFalseTotal
$conf->{'silent'} ? : 0 0 0
66 0 say ' App : ', $conf->{app};
67 0 ▶ say ' Mode : ', $ENV{MOJO_MODE} // '>Undefined<';
Condition0%0/2
$ENV{"MOJO_MODE"} // ">Undefined<"
l!l
00
MC/DC0%0/1
$ENV{"MOJO_MODE"} // ">Undefined<"
$ENV{"MOJO_MODE"}
Truth table0%0/2
A
A= $ENV{"MOJO_MODE"}
Aresult
11
00
68 0 ▶ say ' Backend : ', $ENV{MOJO_MORBO_BACKEND} // '>Undefined<';
Condition0%0/2
$ENV{"MOJO_MORBO_BACKEND"} // ">Undefined<"
l!l
00
MC/DC0%0/1
$ENV{"MOJO_MORBO_BACKEND"} // ">Undefined<"
$ENV{"MOJO_MORBO_BACKEND"}
Truth table0%0/2
A
A= $ENV{"MOJO_MORBO_BACKEND"}
Aresult
11
00
69 0 ▶ say ' Listen : ', join( ', ', $conf->{listen}->@* ) || '>Unspecified<';
Condition0%0/2
join(', ', @{$conf->{'listen'}}) || '>Unspecified<'
l!l
00
MC/DC0%0/1
join(', ', @{$conf->{'listen'}}) || '>Unspecified<'
join(', ', @{$conf->{'listen'}})
Truth table0%0/2
A
A= join(', ', @{$conf->{'listen'}})
Aresult
11
00
70 0 ▶ say ' Watch : ', join( ', ', $conf->{watch}->@* ) || '>Unspecified<';
Condition0%0/2
join(', ', @{$conf->{'watch'}}) || '>Unspecified<'
l!l
00
MC/DC0%0/1
join(', ', @{$conf->{'watch'}}) || '>Unspecified<'
join(', ', @{$conf->{'watch'}})
Truth table0%0/2
A
A= join(', ', @{$conf->{'watch'}})
Aresult
11
00
71 1 ▶ } ) if ( not $conf->{silent} );
Branch: 1 branch
BranchTrueFalseTotal
unless $conf->{"silent"} 1 0 1
72  
73 1 my $morbo = Mojo::Server::Morbo->new( silent => $conf->{silent} );
74  
75 1 ▶ $morbo->daemon->listen( $conf->{listen} ) if @{ $conf->{listen} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$conf->{"listen"};} 1 0 1
76 1 ▶ $morbo->backend->watch( $conf->{watch} ) if @{ $conf->{watch} };
Branch: 1 branch
BranchTrueFalseTotal
if @{$conf->{"watch"};} 0 1 1
77  
78 1 $morbo->run( $conf->{app} );
79  
80 1 return 0;
81 }
82  
83 2 1;
84  
85 __END__
↑ Summary