blib/lib/Venus/Task/Venus.pm

filter: Statementstmt 100% 37 / 37 Branchbran 70.0% 7 / 10 Conditioncond 64.7% 11 / 17 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 11 / 11 Podpod 71.4% 5 / 7 totaltotal 81.1% 73 / 90 CC 12 SCAR 12.4
CC
12
Cov
86%
handle_help
6.1
perform
5.0
file
3.0
CRAP 3.5
« blib/lib/Venus/Role/Coercible.pm ↑ Summary blib/lib/Venus/Box.pm »
1 package Venus::Task::Venus;
2  
3 6 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 6 ▶use Venus::Class 'base';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # INHERITS
13  
14 6 base 'Venus::Task';
15  
16 # REQUIRES
17  
18 6 require Venus;
19  
20 # METHODS
21  
22 5 ▶sub execute {
Subroutine execute: called CC=2 SCAR=7.1
Pod documented
23 5 my ($self) = @_;
24  
25 5 ▶ $self->fail if $self->no_input;
Branch: 1 branch
BranchTrueFalseTotal
if $self->no_input 0 5 5
26  
27 5 return $self->SUPER::execute;
28 }
29  
30 13 ▶sub file {
Subroutine file: called CC=3 SCAR=11.1
Pod undocumented
31  
32 return ($ENV{VENUS_FILE}
33 13 ▶ || (grep -f, map ".vns.$_", qw(yaml yml json js perl pl))[0]
Condition80%4/5
$ENV{'VENUS_FILE'} || (grep((-f $_), map((".vns.$_"), ('yaml', 'yml', 'json', 'js', 'perl', 'pl'))))[0] || '.vns.pl'
l!l
121
$ENV{"VENUS_FILE"} or (grep((-f $_), map((".vns.$_"), ("yaml", "yml", "json", "js", "perl", "pl"))))[0]
l!l&&r!l&&!r
1201
MC/DC50%1/2
$ENV{'VENUS_FILE'} || (grep((-f $_), map((".vns.$_"), ('yaml', 'yml', 'json', 'js', 'perl', 'pl'))))[0] || '.vns.pl'
$ENV{"VENUS_FILE"} (grep((-f $_), map((".vns.$_"), ("yaml", "yml", "json", "js", "perl", "pl"))))[0]
Truth table66%2/3
A or B
A= $ENV{"VENUS_FILE"}B= (grep((-f $_), map((".vns.$_"), ("yaml", "yml", "json", "js", "perl", "pl"))))[0]
ABresult
1X1
011
000
34 || '.vns.pl');
35 }
36  
37 15 ▶sub footer {
Subroutine footer: called CC=1 SCAR=0.0
Pod documented
38  
39 15 return <<"EOF";
40 Config:
41  
42 Here is an example configuration in YAML (e.g. in .vns.yaml).
43  
44 ---
45 exec:
46 cpan: cpanm -llocal -qn
47 deps: cpan --installdeps .
48 each: \$PERL -MVenus=log -nE
49 exec: \$PERL -MVenus=log -E
50 okay: \$PERL -c
51 repl: \$PERL -dE0
52 says: exec "map log(eval), \@ARGV"
53 test: \$PROVE
54 libs:
55 - -Ilib
56 - -Ilocal/lib/perl5
57 path:
58 - bin
59 - dev
60 - local/bin
61 perl:
62 perl: perl
63 prove: prove
64 vars:
65 PERL: perl
66 PROVE: prove
67  
68 Examples:
69  
70 Here are examples usages using the example YAML configuration.
71  
72 # Mint a new configuration file
73 vns new yaml
74  
75 # Install a distribution
76 vns run cpan \$DIST
77  
78 # Install dependencies in the CWD
79 vns run deps
80  
81 # Check that a package can be compiled
82 vns run okay \$FILE
83  
84 # Use the Perl debugger as a REPL
85 vns run repl
86  
87 # Evaluate arbitrary Perl expressions
88 vns run exec ...
89  
90 # Test the Perl project in the CWD
91 vns run test t
92  
93 Copyright 2022-2023, Vesion $Venus::VERSION, The Venus "AUTHOR" and "CONTRIBUTORS"
94  
95 More information on "vns" and/or the "Venus" standard library, visit
96 https://p3rl.org/vns.
97 EOF
98 }
99  
100 6 ▶sub handle_help {
Subroutine handle_help: called CC=5 SCAR=18.1
Pod documented
101 6 my ($self) = @_;
102  
103 my $errors = (
104 $self->input_arguments_defined_count == 0
105 && $self->input_options_defined_count == 1
106 && $self->input_options_defined->{help}
107 6 ▶ ) ? 1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->input_arguments_defined_count == 0 && $self->input_options_defined_count == 1 && $self->input_options_defined->{'help'} ? : 0 6 6
Condition50%3/6
$self->input_arguments_defined_count == 0 and $self->input_options_defined_count == 1 and $self->input_options_defined->{"help"}
!ll&&!rl&&r
600
$self->input_arguments_defined_count == 0 and $self->input_options_defined_count == 1
!ll&&!rl&&r
510
MC/DC0%0/3
$self->input_arguments_defined_count == 0 and $self->input_options_defined_count == 1 and $self->input_options_defined->{"help"}
$self->input_arguments_defined_count == 0 $self->input_options_defined_count == 1 $self->input_options_defined->{"help"}
Truth table50%2/4
A and B and C
A= $self->input_arguments_defined_count == 0B= $self->input_options_defined_count == 1C= $self->input_options_defined->{"help"}
ABCresult
0XX0
10X0
1100
1111
108  
109 6 ▶ $self->help if $errors;
Branch: 1 branch
BranchTrueFalseTotal
if $errors 0 6 6
110  
111 6 return $errors;
112 }
113  
114 7 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
115  
116 return {
117 7 exec => {
118 brew => 'perlbrew',
119 cpan => 'cpanm -llocal -qn',
120 docs => 'perldoc',
121 each => 'shim -nE',
122 edit => '$EDITOR $VENUS_FILE',
123 eval => 'shim -E',
124 exec => '$PERL',
125 info => '$PERL -V',
126 lint => 'perlcritic',
127 okay => '$PERL -c',
128 repl => '$REPL',
129 reup => 'cpanm -qn Venus',
130 says => 'eval "map log(eval), @ARGV"',
131 shim => '$PERL -MVenus=true,false,log',
132 test => '$PROVE',
133 tidy => 'perltidy',
134 },
135 libs => [
136 '-Ilib',
137 '-Ilocal/lib/perl5',
138 ],
139 path => [
140 'bin',
141 'dev',
142 'local/bin',
143 ],
144 perl => {
145 perl => 'perl',
146 prove => 'prove',
147 },
148 vars => {
149 PERL => 'perl',
150 PROVE => 'prove',
151 REPL => '$PERL -dE0',
152 },
153 };
154 }
155  
156 7 ▶sub perform {
Subroutine perform: called CC=5 SCAR=16.1
Pod documented
157 7 my ($self) = @_;
158  
159 7 my $result = $self->dispatch;
160  
161 # Fallback: treat unknown commands as 'run' subcommand
162 7 ▶ if (!$result) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($result) 2 5 7
163 2 my @data = @{$self->data};
164 2 ▶ if (@data && length($data[0]) && $data[0] !~ /^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (@data and length $data[0] and not $data[0] =~ /^-/u) 1 1 2
Condition66%4/6
@data and length $data[0] and not $data[0] =~ /^-/u
!ll&&!rl&&r
101
@data and length $data[0]
!ll&&!rl&&r
011
MC/DC33%1/3
@data and length $data[0] and not $data[0] =~ /^-/u
@data length $data[0] not $data[0] =~ /^-/u
Truth table50%2/4
A and B and not(C)
A= @dataB= length $data[0]C= not $data[0] =~ /^-/u
ABCresult
0XX0
10X0
1100
1111
165 1 require Venus::Task::Venus::Run;
166 1 Venus::Task::Venus::Run->new->handle(@data);
167 1 return $self;
168 }
169 1 $self->help;
170 }
171  
172 6 return $self;
173 }
174  
175 7 ▶sub spec_data {
Subroutine spec_data: called CC=1 SCAR=0.0
Pod documented
176 7 my ($self) = @_;
177  
178 return {
179 7 footer => $self->footer,
180 arguments => [
181 {
182 name => 'task',
183 help => 'Task sub-command.',
184 range => '0',
185 type => 'string',
186 },
187 {
188 name => 'args',
189 help => 'Task arguments.',
190 range => '1:',
191 multiples => 1,
192 type => 'string',
193 },
194 ],
195 choices => [
196 {
197 name => 'gen',
198 help => 'Generate Venus source code.',
199 argument => 'task'
200 },
201 {
202 name => 'get',
203 help => 'Get values in the Venus configuration file.',
204 argument => 'task'
205 },
206 {
207 name => 'new',
208 help => 'Initialize a new Venus configuration file.',
209 argument => 'task'
210 },
211 {
212 name => 'run',
213 help => 'Execute Venus configuration commands.',
214 argument => 'task'
215 },
216 {
217 name => 'set',
218 help => 'Set values in the Venus configuration file.',
219 argument => 'task'
220 },
221 ],
222 commands => [
223 ['task', 'gen', 'Venus::Task::Venus::Gen'],
224 ['task', 'get', 'Venus::Task::Venus::Get'],
225 ['task', 'new', 'Venus::Task::Venus::New'],
226 ['task', 'run', 'Venus::Task::Venus::Run'],
227 ['task', 'set', 'Venus::Task::Venus::Set'],
228 ],
229 };
230 }
231  
232 6 1;
233  
234  
235  
236 =head1 NAME
237  
238 Venus::Task::Venus - vns
239  
240 =cut
241  
242 =head1 ABSTRACT
243  
244 Task Class for Venus CLI
245  
246 =cut
247  
248 =head1 SYNOPSIS
249  
250 package main;
251  
252 use Venus::Task::Venus;
253  
254 my $task = Venus::Task::Venus->new;
255  
256 # bless({...}, 'Venus::Task::Venus')
257  
258 =cut
259  
260 =head1 DESCRIPTION
261  
262 This package is the task class for the C<vns> CLI.
263  
264 =cut
265  
266 =head1 INHERITS
267  
268 This package inherits behaviors from:
269  
270 L<Venus::Task>
271  
272 =cut
273  
274 =head1 METHODS
275  
276 This package provides the following methods:
277  
278 =cut
279  
280 =head2 new
281  
282 new(any @args) (Venus::Task::Venus)
283  
284 The new method constructs an instance of the package.
285  
286 I<Since C<4.15>>
287  
288 =over 4
289  
290 =item new example 1
291  
292 package main;
293  
294 use Venus::Task::Venus;
295  
296 my $task = Venus::Task::Venus->new;
297  
298 # bless({...}, 'Venus::Task::Venus')
299  
300 =back
301  
302 =cut
303  
304 =head2 perform
305  
306 perform() (Venus::Task::Venus)
307  
308 The perform method executes the CLI logic.
309  
310 I<Since C<4.15>>
311  
312 =over 4
313  
314 =item perform example 1
315  
316 # given: synopsis
317  
318 package main;
319  
320 $task->prepare;
321  
322 $task->parse('');
323  
324 my $perform = $task->perform;
325  
326 # bless({...}, 'Venus::Task::Venus')
327  
328 # ''
329  
330 =back
331  
332 =over 4
333  
334 =item perform example 2
335  
336 # given: synopsis
337  
338 package main;
339  
340 $task->prepare;
341  
342 $task->parse('die');
343  
344 my $perform = $task->perform;
345  
346 # bless({...}, 'Venus::Task::Venus')
347  
348 # ''
349  
350 =back
351  
352 =over 4
353  
354 =item perform example 3
355  
356 # given: synopsis
357  
358 package main;
359  
360 $task->prepare;
361  
362 $task->parse('gen', '--stdout', '--class');
363  
364 my $perform = $task->perform;
365  
366 # bless({...}, 'Venus::Task::Venus')
367  
368 # '...'
369  
370 =back
371  
372 =over 4
373  
374 =item perform example 4
375  
376 # given: synopsis
377  
378 package main;
379  
380 $task->prepare;
381  
382 $task->parse('get', 'perl.repl');
383  
384 my $perform = $task->perform;
385  
386 # bless({...}, 'Venus::Task::Venus')
387  
388 # '...'
389  
390 =back
391  
392 =over 4
393  
394 =item perform example 5
395  
396 # given: synopsis
397  
398 package main;
399  
400 $task->prepare;
401  
402 $task->parse('new', 'yaml');
403  
404 my $perform = $task->perform;
405  
406 # bless({...}, 'Venus::Task::Venus')
407  
408 # '...'
409  
410 =back
411  
412 =over 4
413  
414 =item perform example 6
415  
416 # given: synopsis
417  
418 package main;
419  
420 $task->prepare;
421  
422 $task->parse('run', 'okay', 't/Venus.t');
423  
424 my $perform = $task->perform;
425  
426 # bless({...}, 'Venus::Task::Venus')
427  
428 # '...'
429  
430 =back
431  
432 =over 4
433  
434 =item perform example 7
435  
436 # given: synopsis
437  
438 package main;
439  
440 $task->prepare;
441  
442 $task->parse('set', 'perl.repl', '$PERL -dE0');
443  
444 my $perform = $task->perform;
445  
446 # bless({...}, 'Venus::Task::Venus')
447  
448 # '...'
449  
450 =back
451  
452 =cut
453  
454 =head1 AUTHORS
455  
456 Awncorp, C<awncorp@cpan.org>
457  
458 =cut
459  
460 =head1 LICENSE
461  
462 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
463  
464 This program is free software, you can redistribute it and/or modify it under
465 the terms of the Apache license version 2.0.
466  
467 =cut
« blib/lib/Venus/Role/Coercible.pm ↑ Summary blib/lib/Venus/Box.pm »