VTide/Command/Run.pm

filter: Statementstmt 15.3% 44 / 286 Branchbran 0.0% 0 / 130 Conditioncond 0.0% 0 / 77 MC/DCmcdc 0.0% 0 / 44 Subroutinesub 34.2% 12 / 35 Podpod 92.3% 12 / 13 totaltotal 11.6% 68 / 585 CC 99 SCAR 52.3
CC
99
Cov
9%
run
506.0
restart
380.0
command
156.0
CRAP 187.5
« VTide/Command/Start.pm ↑ Summary VTide/Command/Conf.pm »
1 package App::VTide::Command::Run;
2  
3 # Created on: 2016-01-30 15:06:40
4 # Create by: Ivan Wills
5 # $Id$
6 # $Revision$, $HeadURL$, $Date$
7 # $Revision$, $Source$, $Date$
8  
9 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 4 ▶use Carp qw/carp longmess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 4 ▶use English qw/ -no_match_vars /;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 4 ▶use Hash::Merge::Simple qw/ merge /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 4 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 4 ▶use File::stat;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 4 ▶use File::chdir;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 4 ▶use IO::Prompt qw/prompt/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 4 ▶use Algorithm::Cron;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 4 ▶use List::MoreUtils qw/uniq/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 4 extends 'App::VTide::Command';
23  
24 4 our $VERSION = version->new('1.0.6');
25 4 our $NAME = 'run';
26 4 our $OPTIONS = [ 'name|n=s', 'test|T!', 'save|s=s', 'verbose|v+', ];
27 4 our $LOCAL = 1;
28 0 ▶sub details_sub { return ( $NAME, $OPTIONS, $LOCAL ) }
Subroutine details_sub: not called CC=1 SCAR=6.9
Pod documented
29  
30 4 has first => (
31 is => 'rw',
32 default => 1,
33 );
34  
35 4 has base => ( is => 'rw', default => $CWD );
36  
37 0 ▶sub run {
Subroutine run: not called CC=22 SCAR=62.3
Pod documented
38 0 my ($self) = @_;
39  
40 0 my ($name) = $self->session_dir( $self->defaults->{name} );
41 0 ▶ my $cmd = $self->options->files->[0] || '';
Condition0%0/2
$self->options->files->[0] || ''
l!l
00
MC/DC0%0/1
$self->options->files->[0] || ''
$self->options->files->[0]
Truth table0%0/2
A
A= $self->options->files->[0]
Aresult
11
00
42 0 $ENV{VTIDE_TERM} = $cmd;
43  
44 0 my $params = $self->params($cmd);
45 0 my @cmd = $self->command($params);
46 0 $self->log( 'START', @cmd );
47  
48 0 @ARGV = ();
49 0 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->first and $params->{"watch"} || $params->{"cron"} and $params->{"wait"}) 0 0 0
Condition0%0/9
$self->first and $params->{"watch"} || $params->{"cron"} and $params->{"wait"}
!ll&&!rl&&r
000
$self->first and $params->{"watch"} || $params->{"cron"}
!ll&&!rl&&r
000
$params->{"watch"} or $params->{"cron"}
l!l&&r!l&&!r
000
MC/DC0%0/4
$self->first and $params->{"watch"} || $params->{"cron"} and $params->{"wait"}
$self->first $params->{"watch"} $params->{"cron"} $params->{"wait"}
Truth table0%0/6
A and B or C and D
A= $self->firstB= $params->{"watch"}C= $params->{"cron"}D= $params->{"wait"}
ABCDresult
0XXX0
100X0
11X00
10100
11X11
10111
50 !(
51 $self->first
52 && ( $params->{watch} || $params->{cron} )
53 && $params->{wait}
54 )
55 )
56 {
57  
58 0 ▶ if ( $params->{clear} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"clear"}) 0 0 0
59 0 system 'clear';
60 }
61 0 ▶ if ( $self->first ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->first) 0 0 0
62 0 print "Running $name - $cmd\n";
63 }
64  
65 0 ▶ if ( $params->{heading} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"heading"}) 0 0 0
66  
67 # show terminal heading if desired
68 0 print $params->{heading}, "\n";
69 }
70  
71 0 ▶ if ( !$self->defaults->{test} && $params->{wait} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->defaults->{"test"} and $params->{"wait"}) 0 0 0
Condition0%0/3
not $self->defaults->{"test"} and $params->{"wait"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->defaults->{"test"} and $params->{"wait"}
not $self->defaults->{"test"} $params->{"wait"}
Truth table0%0/3
not(A) and B
A= not $self->defaults->{"test"}B= $params->{"wait"}
ABresult
0X0
100
111
72 0 print join ' ', @cmd, "\n";
73 0 print "Press enter to start : ";
74 0 my $ans = <ARGV>;
75 0 ▶ if ( !$ans || !ord $ans ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ans and ord $ans) 0 0 0
Condition0%0/3
$ans and ord $ans
!ll&&!rl&&r
000
MC/DC0%0/2
$ans and ord $ans
$ans ord $ans
Truth table0%0/3
A and B
A= $ansB= ord $ans
ABresult
0X0
100
111
76 0 print "\n";
77 0 return;
78 }
79 }
80  
81 0 $self->load_env( $params->{env} );
82 0 local $CWD = $CWD;
83 0 $self->base($CWD);
84 0 ▶ if ( $params->{dir} && -d $params->{dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"dir"} and -d $params->{"dir"}) 0 0 0
Condition0%0/3
$params->{"dir"} and -d $params->{"dir"}
!ll&&!rl&&r
000
MC/DC0%0/2
$params->{"dir"} and -d $params->{"dir"}
$params->{"dir"} -d $params->{"dir"}
Truth table0%0/3
A and B
A= $params->{"dir"}B= -d $params->{"dir"}
ABresult
0X0
100
111
85 0 $CWD = $params->{dir};
86 }
87  
88 0 ▶ if ( $self->defaults->{verbose} || $self->defaults->{test} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->defaults->{"verbose"} or $self->defaults->{"test"}) 0 0 0
Condition0%0/3
$self->defaults->{"verbose"} or $self->defaults->{"test"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->defaults->{"verbose"} or $self->defaults->{"test"}
$self->defaults->{"verbose"} $self->defaults->{"test"}
Truth table0%0/3
A or B
A= $self->defaults->{"verbose"}B= $self->defaults->{"test"}
ABresult
1X1
011
000
89 0 ▶ warn "Will wait before starting\n" if $params->{wait};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"wait"} 0 0 0
90 0 ▶ warn "Will restart on exit\n" if $params->{restart};
Branch: 1 branch
BranchTrueFalseTotal
if $params->{"restart"} 0 0 0
91 }
92  
93 # run any hooks for run_running
94 0 $self->hooks->run( 'run_running', \@cmd );
95  
96 # start the terminal
97 eval {
98 0 $self->runit(@cmd);
99 0 1;
100 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $self->runit(@cmd); 1 } } or do { $self->log("RUN ERROR", @cmd, $@) } 0 0 0
101 0 $self->log( "RUN ERROR", @cmd, $@ );
102 }
103 }
104  
105 # flag this is no longer the first run
106 0 $self->first(0);
107  
108 0 ▶ if ( !$self->defaults->{test} && $self->restart($cmd) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->defaults->{"test"} and $self->restart($cmd)) 0 0 0
Condition0%0/3
not $self->defaults->{"test"} and $self->restart($cmd)
!ll&&!rl&&r
000
MC/DC0%0/2
not $self->defaults->{"test"} and $self->restart($cmd)
not $self->defaults->{"test"} $self->restart($cmd)
Truth table0%0/3
not(A) and B
A= not $self->defaults->{"test"}B= $self->restart($cmd)
ABresult
0X0
100
111
109 0 return $self->run;
110 }
111  
112 0 return;
113 }
114  
115 0 ▶sub restart {
Subroutine restart: not called CC=19 SCAR=59.4
Pod documented
116 0 my ( $self, $cmd, $no_watch, $default ) = @_;
117  
118 0 my $params = $self->params($cmd);
119  
120 0 ▶ return $self->watch($cmd) if !$no_watch && $params->{watch};
Branch: 1 branch
BranchTrueFalseTotal
if not $no_watch and $params->{"watch"} 0 0 0
Condition0%0/3
not $no_watch and $params->{"watch"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $no_watch and $params->{"watch"}
not $no_watch $params->{"watch"}
Truth table0%0/3
not(A) and B
A= not $no_watchB= $params->{"watch"}
ABresult
0X0
100
111
121 0 ▶ return $self->cron($cmd) if !$no_watch && $params->{cron};
Branch: 1 branch
BranchTrueFalseTotal
if not $no_watch and $params->{"cron"} 0 0 0
Condition0%0/3
not $no_watch and $params->{"cron"}
!ll&&!rl&&r
000
MC/DC0%0/2
not $no_watch and $params->{"cron"}
not $no_watch $params->{"cron"}
Truth table0%0/3
not(A) and B
A= not $no_watchB= $params->{"cron"}
ABresult
0X0
100
111
122  
123 0 ▶ return if !$params->{restart};
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{"restart"} 0 0 0
124  
125 my %action = (
126 q => {
127 msg => 'quit',
128 0 ▶ exec => sub { 0; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
129 },
130 c => {
131 msg => 'clear screen',
132 0 ▶ exec => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
133 0 system "clear";
134 0 $self->restart( $cmd, $no_watch );
135 },
136 },
137 s => {
138 msg => 'Show command',
139 0 ▶ exec => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
140 0 my $params = $self->params($cmd);
141 0 print "\nThis terminals command:\n";
142 0 print join ' ', $self->command($params), "\n\n";
143 0 $self->restart( $cmd, $no_watch );
144 },
145 },
146 r => {
147 msg => 'restart',
148 0 ▶ exec => sub { 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
149 },
150 0 );
151  
152 0 ▶ if ( $params->{restart} ne 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"restart"} ne 1) 0 0 0
153 0 my ($letter) = $params->{restart} =~ /^(.)/xms;
154 $action{$letter} = {
155 msg => $params->{restart},
156 0 ▶ exec => sub { exec $params->{restart}; },
Subroutine __ANON__: not called CC=1 SCAR=6.9
157 0 };
158 }
159  
160 # show restart menu
161 0 my $menu = "Options:\n";
162 0 for my $letter ( sort keys %action ) {
163 0 $menu .= "$letter - $action{$letter}{msg}\n";
164 }
165 0 print $menu;
166  
167 0 ▶ local $SIG{ALRM} = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
168 0 warn "Re-running...\n";
169 0 $self->run;
170 0 };
171 0 ▶ if ( $params->{timeout} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"timeout"}) 0 0 0
172 0 my ($time) = localtime( time + $params->{timeout} ) =~ /(\d+:\d+:\d+)/;
173 0 warn "Will run default in $params->{timeout} ($time)\n";
174 0 alarm $params->{timeout};
175 }
176  
177 # get answer
178 0 ▶ my $answer = $default || <ARGV> || '';
Condition0%0/5
$default || readline ARGV || ''
l!l
00
$default or readline ARGV
l!l&&r!l&&!r
000
MC/DC0%0/2
$default || readline ARGV || ''
$default readline ARGV
Truth table0%0/3
A or B
A= $defaultB= readline ARGV
ABresult
1X1
011
000
179  
180 0 delete $SIG{ALARM};
181 0 ▶ return if !$answer;
Branch: 1 branch
BranchTrueFalseTotal
unless $answer 0 0 0
182  
183 0 ▶ chomp $answer if $answer;
Branch: 1 branch
BranchTrueFalseTotal
if $answer 0 0 0
184 0 ▶ $answer ||= $params->{default} || '';
Condition0%0/5
$answer ||= $params->{"default"} || ""
l!l&&r!l&&!r
000
$params->{'default'} || ''
l!l
00
MC/DC0%0/2
$answer ||= $params->{"default"} || ""
$answer $params->{'default'}
Truth table0%0/3
A ||= B
A= $answerB= $params->{'default'}
ABresult
1X1
011
000
185  
186 # ask the question
187 0 ▶ while ( !$action{$answer} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($action{$answer}) 0 0 0
188 0 print $menu;
189 0 print "Please choose one of " . ( join ', ', sort keys %action ) . "\n";
190 0 $answer = <ARGV>;
191 0 ▶ chomp $answer if $answer;
Branch: 1 branch
BranchTrueFalseTotal
if $answer 0 0 0
192 0 ▶ $answer ||= $params->{default} || '';
Condition0%0/5
$answer ||= $params->{"default"} || ""
l!l&&r!l&&!r
000
$params->{'default'} || ''
l!l
00
MC/DC0%0/2
$answer ||= $params->{"default"} || ""
$answer $params->{'default'}
Truth table0%0/3
A ||= B
A= $answerB= $params->{'default'}
ABresult
1X1
011
000
193 }
194  
195 0 return $action{$answer}{exec}->();
196 }
197  
198 0 ▶sub watch {
Subroutine watch: not called CC=10 SCAR=47.0
Pod documented
199 0 my ( $self, $cmd ) = @_;
200  
201 0 my $params = $self->params($cmd);
202 my @files = $self->command(
203 {
204 editor => { command => undef },
205 edit => $params->{watch},
206 },
207 0 );
208  
209 0 my %stats;
210 0 for my $file (@files) {
211 0 ▶ next if !$file || !-f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file and -f $file 0 0 0
Condition0%0/3
$file and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -f $file
$file -f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
212 0 $stats{$file} = stat $file;
213 }
214  
215 0 while (1) {
216 0 my $done = 0;
217 local $SIG{INT} =
218 0 ▶ sub { $done = $self->restart( $cmd, 1 ) ? 1 : undef; };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$self->restart($cmd, 1) ? : 0 0 0
219  
220 0 sleep 1;
221  
222 0 for my $file (@files) {
223  
224 # return if interrupted
225 0 ▶ return 1 if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
226  
227 # return if asked to quit
228 0 ▶ return if !defined $done;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $done 0 0 0
229  
230 0 ▶ next if !$file || !-f $file;
Branch: 1 branch
BranchTrueFalseTotal
unless $file and -f $file 0 0 0
Condition0%0/3
$file and -f $file
!ll&&!rl&&r
000
MC/DC0%0/2
$file and -f $file
$file -f $file
Truth table0%0/3
A and B
A= $fileB= -f $file
ABresult
0X0
100
111
231 0 my $stat = stat $file;
232 0 ▶ return 1 if $stats{$file}->mtime ne $stat->mtime;
Branch: 1 branch
BranchTrueFalseTotal
if $stats{$file}->mtime ne $stat->mtime 0 0 0
233 }
234 }
235  
236 0 return;
237 }
238  
239 0 ▶sub cron {
Subroutine cron: not called CC=6 SCAR=37.4
Pod documented
240 0 my ( $self, $cmd ) = @_;
241  
242 0 my $params = $self->params($cmd);
243 my $cron = Algorithm::Cron->new(
244 base => 'local',
245 crontab => $params->{cron},
246 0 );
247  
248 0 while (1) {
249 0 my $done = 0;
250 local $SIG{INT} =
251 0 ▶ sub { $done = $self->restart( $cmd, 1 ) ? 1 : undef; };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$self->restart($cmd, 1) ? : 0 0 0
252  
253 0 my $next_time = $cron->next_time(time);
254  
255 #sleep $next_time - time;
256 0 sleep 1;
257  
258 # return if interrupted
259 0 ▶ return 1 if $done;
Branch: 1 branch
BranchTrueFalseTotal
if $done 0 0 0
260  
261 # return if asked to quit
262 0 ▶ return if !defined $done;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $done 0 0 0
263  
264 0 ▶ if ( $params->{cron_verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"cron_verbose"}) 0 0 0
265 0 print {*STDERR} "\33[2K\r" . pretty_time( $next_time - time );
266 }
267 0 ▶ if ( $next_time <= time ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($next_time <= time) 0 0 0
268 0 ▶ if ( $params->{cron_verbose} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params->{"cron_verbose"}) 0 0 0
269 0 print {*STDERR} "\33[2K\r";
270 }
271 0 return 1;
272 }
273 }
274  
275 0 return;
276 }
277  
278 0 ▶sub pretty_time {
Subroutine pretty_time: not called CC=1 SCAR=6.9
Pod documented
279 0 my ($time) = @_;
280  
281 0 my $pretty = '';
282 0 my $days = int $time / ( 24 * 60 * 60 );
283 0 my $hours = int $time / ( 60 * 60 ) - $days * 24;
284 0 my $minutes = int $time / 60 - $days * 24 * 60 - $hours * 60;
285 0 my $seconds = $time % 60;
286  
287 0 return "$days days $hours hours $minutes minutes $seconds seconds";
288 }
289  
290 0 ▶sub params {
Subroutine params: not called CC=8 SCAR=42.8
Pod documented
291 0 my ( $self, $cmd ) = @_;
292  
293 0 ▶ if ( !$cmd ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cmd) 0 0 0
294 0 warn "No \$cmd passed to params()\n", longmess();
295 }
296  
297 0 my $config = $self->config->get;
298 0 ▶ my $params = $config->{terminals}{$cmd} || {};
Condition0%0/2
$config->{'terminals'}{$cmd} || {}
l!l
00
MC/DC0%0/1
$config->{'terminals'}{$cmd} || {}
$config->{'terminals'}{$cmd}
Truth table0%0/2
A
A= $config->{'terminals'}{$cmd}
Aresult
11
00
299  
300 0 ▶ if ( ref $params eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $params eq "ARRAY") 0 0 0
301 0 ▶ $params = { command => @{$params} ? $params : '' };
Branch: 1 branch
BranchTrueFalseTotal
@{$params;} ? : 0 0 0
302 }
303  
304 0 ▶ if ( !$params->{command} && !$params->{edit} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->{"command"} or $params->{"edit"}) 0 0 0
Condition0%0/3
$params->{"command"} or $params->{"edit"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{"command"} or $params->{"edit"}
$params->{"command"} $params->{"edit"}
Truth table0%0/3
A or B
A= $params->{"command"}B= $params->{"edit"}
ABresult
1X1
011
000
305 0 $params->{command} = 'bash';
306 0 $params->{wait} = 0;
307 }
308  
309 0 ▶ return merge $config->{default} || {}, $params;
Condition0%0/2
$config->{'default'} || {}
l!l
00
MC/DC0%0/1
$config->{'default'} || {}
$config->{'default'}
Truth table0%0/2
A
A= $config->{'default'}
Aresult
11
00
310 }
311  
312 0 ▶sub command_param {
Subroutine command_param: not called CC=2 SCAR=17.9
Pod documented
313 0 my ( $self, $param ) = @_;
314  
315 0 my ($user_param) = $param =~ /^[{]:(\w+):[}]$/;
316  
317 0 ▶ return $param if !$user_param;
Branch: 1 branch
BranchTrueFalseTotal
unless $user_param 0 0 0
318  
319 0 my $value = prompt "$user_param : ";
320 0 chomp $value;
321  
322 0 return $value;
323 }
324  
325 0 ▶sub command {
Subroutine command: not called CC=12 SCAR=50.5
Pod documented
326 0 my ( $self, $params, $recurse ) = @_;
327  
328 0 ▶ if ( !$params->{edit} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params->{"edit"}) 0 0 0
329 return
330 ref $params->{command}
331 0 ? map { $self->command_param($_) } @{ $params->{command} }
332 0 ▶ : ( $params->{command} );
Branch: 1 branch
BranchTrueFalseTotal
ref $params->{'command'} ? : 0 0 0
333 }
334  
335 my $editor =
336 ref $params->{editor}{command}
337 ? $params->{editor}{command}
338 0 ▶ : $self->config->get->{editor}{command};
Branch: 1 branch
BranchTrueFalseTotal
ref $params->{'editor'}{'command'} ? : 0 0 0
339  
340 my @globs =
341 0 ▶ ref $params->{edit} ? @{ $params->{edit} } : ( $params->{edit} );
Branch: 1 branch
BranchTrueFalseTotal
ref $params->{'edit'} ? : 0 0 0
342  
343 0 ▶ my $title = $params->{title} || $globs[0];
Condition0%0/3
$params->{'title'} || $globs[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$params->{'title'} || $globs[0]
$params->{'title'} $globs[0]
Truth table0%0/3
A || B
A= $params->{'title'}B= $globs[0]
ABresult
1X1
011
000
344 0 my $max = 15;
345 0 ▶ if ( length $title > $max ) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $title > $max) 0 0 0
346 0 $title = substr $title, ( length $title ) - $max, $max + 1;
347 }
348  
349 0 ▶ eval { require Term::Title; }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Term::Title } } and Term::Title::set_titlebar($title) 0 0 0
350 and Term::Title::set_titlebar($title);
351 0 system 'tmux', 'rename-window', $title;
352  
353 0 my $helper_text = $self->config->get->{editor}{helper};
354 0 my $helper;
355 eval {
356 0 ▶ if ($helper_text) {
Branch: 2 branches
BranchTrueFalseTotal
if ($helper_text) { } 0 0 0
elsif ($self->defaults->{'verbose'}) { } 0 0 0
357 0 $helper = eval $helper_text; ## no critic
358 0 ▶ die "No helper generated!" if !$helper;
Branch: 1 branch
BranchTrueFalseTotal
unless $helper 0 0 0
359 }
360 elsif ( $self->defaults->{verbose} ) {
361 0 warn "No helper text";
362 }
363 0 1;
364 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { if ($helper_text) { $helper = eval $helper_text; die "No helper generated!" unless $helper; } elsif ($self->defaults->{"verbose"}) { warn "No helper text"; } ; 1 } } or do { warn $@; warn $helper_text } 0 0 0
365 0 warn $@;
366 0 warn $helper_text;
367 };
368  
369 0 my $groups = $self->config->get->{editor}{files};
370 0 my @files = $self->_globs2files( $groups, $helper, $recurse, @globs );
371  
372 0 return ( @$editor, @files );
373 }
374  
375 0 ▶sub _globs2files {
Subroutine _globs2files: not called CC=11 SCAR=48.8
376 0 my ( $self, $groups, $helper, $recurse, @globs ) = @_;
377 0 my @files;
378 0 my $count = 0;
379  
380 GLOB:
381 0 ▶ while ( my $glob = shift @globs ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $glob = shift @globs) 0 0 0
382 0 ▶ last if $count++ > 30;
Branch: 1 branch
BranchTrueFalseTotal
if $count++ > 30 0 0 0
383 0 my ($not_glob) = $glob =~ /^[!](.*)$/;
384  
385 0 ▶ if ($not_glob) {
Branch: 3 branches
BranchTrueFalseTotal
if ($not_glob) { } 0 0 0
elsif ($groups->{$glob}) { } 0 0 0
elsif ($helper) { } 0 0 0
386 0 my %not_files = map { $_ => 1 }
387 $self->_globs2files( $groups, $helper, $recurse, $not_glob );
388 0 @files = grep { !$not_files{$_} } @files;
389 0 next GLOB;
390 }
391 elsif ( $groups->{$glob} ) {
392 0 unshift @globs, @{ $groups->{$glob} };
393 0 next GLOB;
394 }
395 elsif ($helper) {
396 0 my @g;
397 eval {
398 0 @g = $helper->( $self, $glob );
399 0 1;
400 0 ▶ } or do { warn $@ };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { @g = &$helper($self, $glob); 1 } } or do { warn $@ } 0 0 0
401  
402 0 ▶ if (@g) {
Branch: 1 branch
BranchTrueFalseTotal
if (@g) 0 0 0
403 0 push @files, grep { -f $_ } @g;
404 0 unshift @globs, grep { !-f $_ } @g;
405 0 next GLOB;
406 }
407 }
408 0 ▶ if ( $recurse && -d $glob ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($recurse and -d $glob) 0 0 0
Condition0%0/3
$recurse and -d $glob
!ll&&!rl&&r
000
MC/DC0%0/2
$recurse and -d $glob
$recurse -d $glob
Truth table0%0/3
A and B
A= $recurseB= -d $glob
ABresult
0X0
100
111
409 push @files, map {
410 0 ▶ -d $_
Branch: 1 branch
BranchTrueFalseTotal
-d $_ ? : 0 0 0
411 ? $self->_globs2files( $groups, $helper, $recurse, $_ )
412 : $_
413 } $self->_globs2files( $groups, $helper, $recurse, "$glob/*" );
414 0 next GLOB;
415 }
416  
417 0 push @files, $self->_dglob($glob);
418 }
419  
420 0 return uniq @files;
421 }
422  
423 0 ▶sub _shell_quote {
Subroutine _shell_quote: not called CC=1 SCAR=6.9
424 0 my ($file) = @_;
425 0 $file =~ s/([\s&;*'"])/\\$1/gxms;
426 0 return $file;
427 }
428  
429 0 ▶sub load_env {
Subroutine load_env: not called CC=5 SCAR=34.0
Pod documented
430 0 my ( $self, $env_extra ) = @_;
431 0 ▶ if ( $env_extra && ref $env_extra eq 'HASH' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($env_extra and ref $env_extra eq "HASH") 0 0 0
Condition0%0/3
$env_extra and ref $env_extra eq "HASH"
!ll&&!rl&&r
000
MC/DC0%0/2
$env_extra and ref $env_extra eq "HASH"
$env_extra ref $env_extra eq "HASH"
Truth table0%0/3
A and B
A= $env_extraB= ref $env_extra eq "HASH"
ABresult
0X0
100
111
432 0 for my $env ( keys %{$env_extra} ) {
433 0 ▶ my $orig = $ENV{$env} // '';
Condition0%0/2
$ENV{$env} // ""
l!l
00
MC/DC0%0/1
$ENV{$env} // ""
$ENV{$env}
Truth table0%0/2
A
A= $ENV{$env}
Aresult
11
00
434 0 $ENV{$env} = $env_extra->{$env};
435 0 $ENV{$env} =~ s/[\$]$env/$orig/xms;
436 }
437 }
438  
439 0 return;
440 }
441  
442 0 ▶sub runit {
Subroutine runit: not called CC=10 SCAR=47.0
Pod documented
443 0 my ( $self, @cmd ) = @_;
444  
445 print +( join " \\\n ", @cmd ), "\n"
446 0 ▶ if $self->defaults->{test} || $self->defaults->{verbose};
Branch: 1 branch
BranchTrueFalseTotal
if $self->defaults->{"test"} or $self->defaults->{"verbose"} 0 0 0
Condition0%0/3
$self->defaults->{"test"} or $self->defaults->{"verbose"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$self->defaults->{"test"} or $self->defaults->{"verbose"}
$self->defaults->{"test"} $self->defaults->{"verbose"}
Truth table0%0/3
A or B
A= $self->defaults->{"test"}B= $self->defaults->{"verbose"}
ABresult
1X1
011
000
447  
448 0 ▶ return if $self->defaults->{test};
Branch: 1 branch
BranchTrueFalseTotal
if $self->defaults->{"test"} 0 0 0
449  
450 0 ▶ if ( @cmd > 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cmd > 1) 0 0 0
451 0 my $found = 0;
452 0 for my $dir ( split /:/xms, $ENV{PATH} ) {
453 0 ▶ if ( -d $dir && -x path $dir, $cmd[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dir and -x path($dir, $cmd[0])) 0 0 0
Condition0%0/3
-d $dir and -x path($dir, $cmd[0])
!ll&&!rl&&r
000
MC/DC0%0/2
-d $dir and -x path($dir, $cmd[0])
-d $dir -x path($dir, $cmd[0])
Truth table0%0/3
A and B
A= -d $dirB= -x path($dir, $cmd[0])
ABresult
0X0
100
111
454 0 $found = 1;
455 0 last;
456 }
457 }
458  
459 0 ▶ if ( !$found ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($found) 0 0 0
460 0 @cmd = ( join ' ', @cmd );
461 }
462 }
463  
464 0 $self->log( 'SYSTEM', @cmd );
465 0 my $err = system @cmd;
466 0 ▶ if ($err) {
Branch: 1 branch
BranchTrueFalseTotal
if ($err) 0 0 0
467 0 $self->log( "ERRORED", @cmd );
468 }
469 }
470  
471 0 ▶sub log {
Subroutine log: not called CC=1 SCAR=6.9
Pod undocumented
472 0 my ( $self, @msg ) = @_;
473  
474 0 my $fh = path( $self->base, '.vtide', 'run.log' )->opena;
475 0 print {$fh} '['
476 . localtime
477 . "] RUN $ENV{VTIDE_TERM} "
478 . ( join ' ', @msg ) . "\n";
479 }
480  
481 0 ▶sub auto_complete {
Subroutine auto_complete: not called CC=2 SCAR=17.9
Pod documented
482 0 my ($self) = @_;
483  
484 0 my $env = $self->options->files->[-1];
485 0 my @files = sort keys %{ $self->config->get->{terminals} };
486  
487 0 ▶ print join ' ', grep { $env ne 'run' ? /^$env/xms : 1 } @files;
Branch: 1 branch
BranchTrueFalseTotal
$env ne 'run' ? : 0 0 0
488  
489 0 return;
490 }
491  
492 4 1;
493  
494 __END__
« VTide/Command/Start.pm ↑ Summary VTide/Command/Conf.pm »