blib/lib/Clustericious/Command/start.pm

filter: Statementstmt 55.2% 37 / 67 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 91.6% 11 / 12 Podpod 100% 1 / 1 totaltotal 47.5% 49 / 103 CC 14 SCAR 47.7
CC
14
Cov
42%
run
210.0
BEGIN
1.0
BEGIN
1.0
CRAP 118.0
« blib/lib/Clustericious/Client.pm ↑ Summary blib/lib/Clustericious/Command/configure.pm »
1 package Clustericious::Command::start;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Clustericious::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Path qw( mkpath );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Basename qw( dirname );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Clustericious::App;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Clustericious::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Mojo::Base 'Clustericious::Command';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Text::ParseWords qw( shellwords );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Env qw( @PERL5LIB );
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # ABSTRACT: Clustericious command to start a Clustericious application
16 1 our $VERSION = '1.29'; # VERSION
17  
18  
19 1 has description => <<EOT;
20 Start a daemon using the config file.
21 EOT
22  
23 1 has usage => <<EOT;
24 usage $0: start
25 Start a daemon using the start_mode in the config file.
26 See Clustericious::Config for the format of the config file.
27 See Clustericious::Command::Start for examples.
28 EOT
29  
30 0 ▶sub run {
Subroutine run: not called CC=14 SCAR=53.5
Pod documented
31 0 my($self, @args) = @_;
32 0 ▶ exit 2 unless $self->app->sanity_check;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->app->sanity_check 0 0 0
33 0 my $app = $ENV{MOJO_APP};
34 0 my $conf = $self->app->config;
35  
36 0 eval "use $app;";
37 0 ▶ die $@ if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
38  
39 0 $self->app->init_logging;
40  
41 0 for my $mode ($self->app->config->start_mode)
42 {
43 0 INFO "Starting $mode";
44 0 my %conf = $conf->$mode;
45 0 ▶ if(my $autogen = delete $conf{autogen})
Branch: 1 branch
BranchTrueFalseTotal
if (my $autogen = delete $conf{"autogen"}) 0 0 0
46 {
47 0 ▶ $autogen = [ $autogen ] if ref $autogen eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $autogen eq "HASH" 0 0 0
48 0 for my $i (@$autogen)
49 {
50 0 DEBUG "autowriting ".$i->{filename};
51 0 mkpath(dirname($i->{filename}), 0, 0700);
52 0 ▶ open my $fp, ">$i->{filename}" or LOGDIE "cannot write to $i->{filename} : $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fp, qq[>$i->{"filename"}] or LOGDIE(qq[cannot write to $i->{"filename"} : $!]) 0 0 0
53 0 print $fp $i->{content};
54 0 ▶ close $fp or LOGDIE $!;
Branch: 1 branch
BranchTrueFalseTotal
close $fp or LOGDIE($!) 0 0 0
55 }
56 }
57  
58 # env hash goes to the environment
59 0 ▶ my $env = delete $conf{env} || {};
Condition0%0/2
delete $conf{'env'} || {}
l!l
00
MC/DC0%0/1
delete $conf{'env'} || {}
delete $conf{'env'}
Truth table0%0/2
A
A= delete $conf{'env'}
Aresult
11
00
60 0 @ENV{ keys %$env } = values %$env;
61 0 ▶ if($env->{PERL5LIB})
Branch: 1 branch
BranchTrueFalseTotal
if ($env->{"PERL5LIB"}) 0 0 0
62 {
63 # Do it now, in case we are not spawning a new process.
64 0 push @INC, @PERL5LIB;
65 }
66 0 TRACE "Setting env vars : ".join ',', keys %$env;
67  
68 0 my @args;
69  
70 0 ▶ if(my $args = delete $conf{args})
Branch: 2 branches
BranchTrueFalseTotal
if (my $args = delete $conf{'args'}) { } 0 0 0
elsif (%conf) { } 0 0 0
71 {
72 0 ▶ @args = ref $args ne 'ARRAY' ? (shellwords $args) : @$args;
Branch: 1 branch
BranchTrueFalseTotal
ref $args ne 'ARRAY' ? : 0 0 0
73 }
74 elsif(%conf)
75 {
76 0 die "arguments specified withouth 'args' option\n";
77 }
78  
79 0 DEBUG "Sending args for $mode : @args";
80 0 $ENV{MOJO_COMMANDS_DONE} = 0;
81 0 Clustericious::Commands->start($mode,@args);
82 }
83 }
84  
85 1 1;
86  
87 __END__
« blib/lib/Clustericious/Client.pm ↑ Summary blib/lib/Clustericious/Command/configure.pm »