blib/lib/Venus/Cli.pm

filter: Statementstmt 97.3% 1263 / 1298 Branchbran 79.4% 623 / 784 Conditioncond 65.9% 114 / 173 MC/DCmcdc 40.3% 42 / 104 Subroutinesub 98.4% 188 / 191 Podpod 96.6% 175 / 181 totaltotal 88.0% 2405 / 2731 CC 489 SCAR 24.0
CC
489
Cov
89%
spec
55.6
usage_option_label
32.6
argument_value
32.6
CRAP 11.0
« blib/lib/Venus/Schema.pm ↑ Summary blib/lib/Venus/Collect.pm »
1 package Venus::Cli;
2  
3 9 ▶use 5.018;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 # IMPORTS
9  
10 9 ▶use Venus::Class 'attr', 'base', 'with';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 9 ▶use POSIX ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # INHERITS
15  
16 9 base 'Venus::Kind::Utility';
17  
18 # INTEGRATES
19  
20 9 with 'Venus::Role::Printable';
21  
22 # ATTRIBUTES
23  
24 9 attr 'name';
25 9 attr 'version';
26 9 attr 'summary';
27 9 attr 'description';
28 9 attr 'header';
29 9 attr 'footer';
30 9 attr 'arguments';
31 9 attr 'options';
32 9 attr 'choices';
33 9 attr 'routes';
34 9 attr 'data';
35  
36 # BUILDERS
37  
38 3 ▶sub build_arg {
Subroutine build_arg: called CC=1 SCAR=0.0
Pod undocumented
39 3 my ($self, $data) = @_;
40  
41 return {
42 3 name => $data,
43 };
44 }
45  
46 530 ▶sub build_data {
Subroutine build_data: called CC=6 SCAR=19.3
Pod undocumented
47 530 my ($self, $data) = @_;
48  
49 530 ▶ $data->{data} ||= [];
Condition50%1/2
$data->{"data"} ||= []
l!l
0530
MC/DC0%0/1
$data->{"data"} ||= []
$data->{"data"}
Truth table50%1/2
A
A= $data->{"data"}
Aresult
11
00
50 530 ▶ $data->{arguments} ||= {};
Condition50%1/2
$data->{"arguments"} ||= {}
l!l
0530
MC/DC0%0/1
$data->{"arguments"} ||= {}
$data->{"arguments"}
Truth table50%1/2
A
A= $data->{"arguments"}
Aresult
11
00
51 530 ▶ $data->{options} ||= {};
Condition50%1/2
$data->{"options"} ||= {}
l!l
0530
MC/DC0%0/1
$data->{"options"} ||= {}
$data->{"options"}
Truth table50%1/2
A
A= $data->{"options"}
Aresult
11
00
52 530 ▶ $data->{choices} ||= {};
Condition50%1/2
$data->{"choices"} ||= {}
l!l
0530
MC/DC0%0/1
$data->{"choices"} ||= {}
$data->{"choices"}
Truth table50%1/2
A
A= $data->{"choices"}
Aresult
11
00
53 530 ▶ $data->{routes} ||= {};
Condition50%1/2
$data->{"routes"} ||= {}
l!l
0530
MC/DC0%0/1
$data->{"routes"} ||= {}
$data->{"routes"}
Truth table50%1/2
A
A= $data->{"routes"}
Aresult
11
00
54  
55 530 return $data;
56 }
57  
58 530 ▶sub build_self {
Subroutine build_self: called CC=5 SCAR=16.1
Pod undocumented
59 530 my ($self, $data) = @_;
60  
61 530 my $arguments = $self->arguments;
62  
63 530 $self->argument($_, $arguments->{$_}) for keys %{$arguments};
64  
65 530 my $choices = $self->choices;
66  
67 530 $self->choice($_, $choices->{$_}) for keys %{$choices};
68  
69 530 my $options = $self->options;
70  
71 530 $self->option($_, $options->{$_}) for keys %{$options};
72  
73 530 my $routes = $self->routes;
74  
75 530 $self->route($_, $routes->{$_}) for keys %{$routes};
76  
77 530 $self->reorder;
78  
79 530 return $self;
80 }
81  
82 # HOOKS
83  
84 0 ▶sub _exit {
Subroutine _exit: not called CC=1 SCAR=6.9
85 0 POSIX::_exit(shift);
86 }
87  
88 0 ▶sub _print {
Subroutine _print: not called CC=1 SCAR=6.9
89 0 do {local $| = 1; CORE::print(@_, "\n")}
90 }
91  
92 0 ▶sub _prompt {
Subroutine _prompt: not called CC=1 SCAR=6.9
93 0 do {local $\ = ''; local $_ = <STDIN>; chomp; $_}
94 }
95  
96 # METHODS
97  
98 2 ▶sub args {
Subroutine args: called CC=3 SCAR=11.0
Pod documented
99 2 my ($self) = @_;
100  
101 2 my $parsed_arguments = $self->parsed_arguments;
102  
103 2 ▶ $self->parse if !$parsed_arguments || !@{$parsed_arguments};
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed_arguments and @{$parsed_arguments;} 1 1 2
Condition66%2/3
$parsed_arguments and @{$parsed_arguments;}
!ll&&!rl&&r
011
MC/DC50%1/2
$parsed_arguments and @{$parsed_arguments;}
$parsed_arguments @{$parsed_arguments;}
Truth table66%2/3
A and B
A= $parsed_argumentsB= @{$parsed_arguments;}
ABresult
0X0
100
111
104  
105 2 $parsed_arguments = $self->parsed_arguments;
106  
107 2 require Venus::Args;
108  
109 2 return Venus::Args->new(value => $parsed_arguments);
110 }
111  
112 994 ▶sub argument {
Subroutine argument: called CC=10 SCAR=23.2
Pod documented
113 994 my ($self, $name, @data) = @_;
114  
115 994 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 992 994
116  
117 992 ▶ return $self->arguments->{$name} if !@data;
Branch: 1 branch
BranchTrueFalseTotal
unless @data 751 241 992
118  
119 241 ▶ return delete $self->arguments->{$name} if !defined $data[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data[0] 0 241 241
120  
121 my $defaults = {
122 name => $name,
123 label => undef,
124 help => undef,
125 default => undef,
126 multiples => 0,
127 prompt => undef,
128 range => undef,
129 required => false,
130 type => 'string',
131 241 index => int(keys(%{$self->arguments})),
132 wants => undef,
133 };
134  
135 241 require Venus;
136  
137 241 my $overrides = Venus::merge_take({}, @data);
138  
139 241 ▶ $overrides->{wants} //= $overrides->{type} || 'string' if !exists $overrides->{wants};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $overrides->{"wants"} 175 66 241
Condition75%3/4
$overrides->{"wants"} //= $overrides->{"type"} || "string"
l!l
0175
$overrides->{'type'} || 'string'
l!l
13837
MC/DC0%0/1
$overrides->{"wants"} //= $overrides->{"type"} || "string"
$overrides->{"wants"}
Truth table50%1/2
A
A= $overrides->{"wants"}
Aresult
11
00
140  
141 241 ▶ my $data = Venus::merge_take($self->arguments->{$name} || $defaults, $overrides);
Condition66%2/3
$self->arguments->{$name} || $defaults
l!l&&r!l&&!r
302110
MC/DC0%0/2
$self->arguments->{$name} || $defaults
$self->arguments->{$name} $defaults
Truth table66%2/3
A || B
A= $self->arguments->{$name}B= $defaults
ABresult
1X1
011
000
142  
143 241 ▶ $data->{help} ||= "Expects a $data->{type} value";
Condition100%2/2
$data->{"help"} ||= qq[Expects a $data->{"type"} value]
l!l
90151
MC/DC100%1/1
$data->{"help"} ||= qq[Expects a $data->{"type"} value]
$data->{"help"}
Truth table100%2/2
A
A= $data->{"help"}
Aresult
11
00
144  
145 241 ▶ return $self->arguments->{$data->{name} ? $data->{name} : $name} = $data;
Branch: 1 branch
BranchTrueFalseTotal
$data->{'name'} ? : 241 0 241
146 }
147  
148 4 ▶sub argument_choice {
Subroutine argument_choice: called CC=5 SCAR=16.2
Pod documented
149 4 my ($self, $name) = @_;
150  
151 4 my $output = [];
152  
153 4 ▶ return $output if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 3 4
154  
155 3 my $choices = {map +($$_{name}, $_), $self->argument_choices($name)};
156  
157 3 for my $value ($self->argument_value($name)) {
158 4 ▶ if (exists $choices->{$value}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $choices->{$value}) { } 3 1 4
159 3 push @{$output}, $value;
160 }
161 else {
162 1 $output = [];
163 1 last;
164 }
165 }
166  
167 0 ▶ return wantarray ? @{$output} : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
168 }
169  
170 6 ▶sub argument_choices {
Subroutine argument_choices: called CC=3 SCAR=11.0
Pod documented
171 6 my ($self, $name) = @_;
172  
173 6 my $output = [];
174  
175 6 ▶ $output = [grep +($$_{argument} eq $name), $self->choice_list] if $name;
Branch: 1 branch
BranchTrueFalseTotal
if $name 5 1 6
176  
177 6 ▶ return wantarray ? @{$output} : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 3 3 6
178 }
179  
180 29 ▶sub argument_count {
Subroutine argument_count: called CC=1 SCAR=0.0
Pod documented
181 29 my ($self) = @_;
182  
183 29 return int(scalar(keys(%{$self->arguments})));
184 }
185  
186 33 ▶sub argument_default {
Subroutine argument_default: called CC=3 SCAR=11.0
Pod documented
187 33 my ($self, $name) = @_;
188  
189 33 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 31 33
190  
191 31 my $argument = $self->argument($name);
192  
193 31 ▶ return '' if !defined $argument;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $argument 0 31 31
194  
195 31 my $default = $argument->{default};
196  
197 31 return $default;
198 }
199  
200 13 ▶sub argument_errors {
Subroutine argument_errors: called CC=4 SCAR=13.9
Pod documented
201 13 my ($self, $name) = @_;
202  
203 13 ▶ return [] if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 12 13
204  
205 12 my $result = $self->argument_validate($name);
206  
207 12 ▶ $result = [$result] if ref $result ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $result ne "ARRAY" 10 2 12
208  
209 12 @{$result} = grep defined, map $_->issue, @{$result};
210  
211 12 ▶ return wantarray ? (@{$result}) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 8 4 12
212 }
213  
214 31 ▶sub argument_help {
Subroutine argument_help: called CC=3 SCAR=11.0
Pod documented
215 31 my ($self, $name) = @_;
216  
217 31 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 29 31
218  
219 29 my $argument = $self->argument($name);
220  
221 29 ▶ return '' if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 29 29
222  
223 29 my $help = $argument->{help};
224  
225 29 return $help;
226 }
227  
228 2 ▶sub argument_label {
Subroutine argument_label: called CC=3 SCAR=11.0
Pod documented
229 2 my ($self, $name) = @_;
230  
231 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
232  
233 1 my $argument = $self->argument($name);
234  
235 1 ▶ return '' if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 1 1
236  
237 1 my $label = $argument->{label};
238  
239 1 return $label;
240 }
241  
242 4 ▶sub argument_list {
Subroutine argument_list: called CC=2 SCAR=6.9
Pod documented
243 4 my ($self) = @_;
244  
245 4 my $output = [];
246  
247 4 my $arguments = $self->arguments;
248  
249 4 $output = [map $arguments->{$_}, $self->argument_names];
250  
251 4 ▶ return wantarray ? @{$output} : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 2 2 4
252 }
253  
254 3 ▶sub argument_multiples {
Subroutine argument_multiples: called CC=4 SCAR=14.0
Pod documented
255 3 my ($self, $name) = @_;
256  
257 3 ▶ return false if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
258  
259 2 my $argument = $self->argument($name);
260  
261 2 ▶ return false if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 2 2
262  
263 2 my $multiples = $argument->{multiples};
264  
265 2 ▶ return $multiples ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$multiples ? : 2 0 2
266 }
267  
268 3 ▶sub argument_name {
Subroutine argument_name: called CC=3 SCAR=11.0
Pod documented
269 3 my ($self, $name) = @_;
270  
271 3 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
272  
273 2 my $argument = $self->argument($name);
274  
275 2 ▶ return '' if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 1 1 2
276  
277 1 $name = $argument->{name};
278  
279 1 return $name;
280 }
281  
282 677 ▶sub argument_names {
Subroutine argument_names: called CC=4 SCAR=14.0
Pod documented
283 677 my ($self) = @_;
284  
285 677 my $arguments = $self->arguments;
286  
287 my @names = sort {
288 (exists $arguments->{$a}->{index} ? $arguments->{$a}->{index} : $a)
289 50 ▶ <=> (exists $arguments->{$b}->{index} ? $arguments->{$b}->{index} : $b)
Branch: 2 branches
BranchTrueFalseTotal
exists $arguments->{$a}{'index'} ? : 50 0 50
exists $arguments->{$b}{'index'} ? : 50 0 50
290 677 } keys %{$arguments};
291  
292 677 ▶ return wantarray ? (@names) : [@names];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 674 3 677
293 }
294  
295 3 ▶sub argument_prompt {
Subroutine argument_prompt: called CC=3 SCAR=11.0
Pod documented
296 3 my ($self, $name) = @_;
297  
298 3 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
299  
300 2 my $argument = $self->argument($name);
301  
302 2 ▶ return '' if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 2 2
303  
304 2 my $prompt = $argument->{prompt};
305  
306 2 return $prompt;
307 }
308  
309 4 ▶sub argument_range {
Subroutine argument_range: called CC=3 SCAR=11.0
Pod documented
310 4 my ($self, $name) = @_;
311  
312 4 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 3 4
313  
314 3 my $argument = $self->argument($name);
315  
316 3 ▶ return '' if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 3 3
317  
318 3 my $range = $argument->{range};
319  
320 3 return $range;
321 }
322  
323 33 ▶sub argument_required {
Subroutine argument_required: called CC=4 SCAR=13.9
Pod documented
324 33 my ($self, $name) = @_;
325  
326 33 ▶ return false if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 31 33
327  
328 31 my $argument = $self->argument($name);
329  
330 31 ▶ return false if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 31 31
331  
332 31 my $required = $argument->{required};
333  
334 31 ▶ return $required ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$required ? : 7 24 31
335 }
336  
337 3 ▶sub argument_type {
Subroutine argument_type: called CC=3 SCAR=11.0
Pod documented
338 3 my ($self, $name) = @_;
339  
340 3 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
341  
342 2 my $argument = $self->argument($name);
343  
344 2 ▶ return '' if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 2 2
345  
346 2 my $type = $argument->{type};
347  
348 2 return $type;
349 }
350  
351 19 ▶sub argument_validate {
Subroutine argument_validate: called CC=14 SCAR=26.7
Pod documented
352 19 my ($self, $name) = @_;
353  
354 19 ▶ return [] if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 18 19
355  
356 18 my $argument = $self->argument($name);
357  
358 18 ▶ return [] if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 18 18
359  
360 18 require Venus::Validate;
361  
362 18 my $validate = Venus::Validate->new(input => [$self->argument_value($name)]);
363  
364 18 ▶ my $required = $argument->{required} ? 'required' : 'optional';
Branch: 1 branch
BranchTrueFalseTotal
$argument->{'required'} ? : 5 13 18
365  
366 18 my $value = $validate->each($required);
367  
368 18 my $type = 'string';
369  
370 18 ▶ $type = 'boolean' if $argument->{type} eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "boolean" 0 18 18
371 18 ▶ $type = 'float' if $argument->{type} eq 'float';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "float" 0 18 18
372 18 ▶ $type = 'number' if $argument->{type} eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "number" 2 16 18
373 18 ▶ $type = 'any' if $argument->{type} eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "string" 16 2 18
374 18 ▶ $type = 'yesno' if $argument->{type} eq 'yesno';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "yesno" 0 18 18
375  
376 18 for my $value (@{$value}) {
377 20 ▶ next if $required eq 'optional' && !defined $value->input->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $required eq "optional" and not defined $value->input->[0] 5 15 20
Condition100%3/3
$required eq "optional" and not defined $value->input->[0]
!ll&&!rl&&r
5105
MC/DC100%2/2
$required eq "optional" and not defined $value->input->[0]
$required eq "optional" not defined $value->input->[0]
Truth table100%3/3
A and not(B)
A= $required eq "optional"B= not defined $value->input->[0]
ABresult
0X0
100
111
378 15 $value->type($type);
379 }
380  
381 18 my $multiples = $argument->{multiples};
382  
383 0 ▶ return $multiples ? (wantarray ? (@{$value}) : $value) : $value->[0];
Branch: 2 branches
BranchTrueFalseTotal
$multiples ? : 6 12 18
wantarray ? : 0 6 6
384 }
385  
386 78 ▶sub argument_value {
Subroutine argument_value: called CC=21 SCAR=34.8
Pod documented
387 78 my ($self, $name) = @_;
388  
389 78 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 77 78
390  
391 77 my $argument = $self->argument($name);
392  
393 77 ▶ return undef if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 77 77
394  
395 77 my $parsed_arguments = $self->parsed_arguments;
396  
397 77 my $range = $argument->{range};
398  
399 77 require Venus::Array;
400  
401 77 my $value = Venus::Array->new($parsed_arguments)->range($range);
402  
403 77 @{$value} = (grep defined, @{$value});
404  
405 77 my $default = $argument->{default};
406  
407 $value = defined $default
408 ? ref $default eq 'ARRAY'
409 ? $default
410 : [$default // ()]
411 77 ▶ : [$self->argument_value_prompt($name) // ()] if !@{$value};
Branch: 3 branches
BranchTrueFalseTotal
unless @{$value;} 16 61 77
defined $default ? : 0 16 16
ref $default eq 'ARRAY' ? : 0 0 0
Condition33%2/6
$default // ()
l!l&&r!l&&!r
000
$self->argument_value_prompt($name) // ()
l!l&&r!l&&!r
0151
MC/DC0%0/2
$default // ()
$default ()
MC/DC50%1/2
$self->argument_value_prompt($name) // ()
$self->argument_value_prompt($name) ()
Truth table0%0/3
A // B
A= $defaultB= ()
ABresult
1X1
011
000
Truth table66%2/3
A // B
A= $self->argument_value_prompt($name)B= ()
ABresult
1X1
011
000
412  
413 77 my $type = 'string';
414  
415 77 ▶ $type = 'boolean' if $argument->{type} eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "boolean" 0 77 77
416 77 ▶ $type = 'float' if $argument->{type} eq 'float';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "float" 0 77 77
417 77 ▶ $type = 'number' if $argument->{type} eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "number" 2 75 77
418 77 ▶ $type = 'string' if $argument->{type} eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "string" 75 2 77
419 77 ▶ $type = 'yesno' if $argument->{type} eq 'yesno';
Branch: 1 branch
BranchTrueFalseTotal
if $argument->{"type"} eq "yesno" 0 77 77
420  
421 77 require Scalar::Util;
422  
423 77 ▶ if ($type eq 'number') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "number") 2 75 77
424 2 ▶ @{$value} = map +(Scalar::Util::looks_like_number($_) ? (0+$_) : $_), @{$value};
Branch: 1 branch
BranchTrueFalseTotal
&Scalar::Util::looks_like_number($_) ? : 0 2 2
425 }
426  
427 77 ▶ if ($type eq 'boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "boolean") 0 77 77
428 0 @{$value} = map +(Scalar::Util::looks_like_number($_) ? !!$_ ? true : false
429 0 ▶ : $_ =~ /true/i ? true : false), @{$value};
Branch: 3 branches
BranchTrueFalseTotal
&Scalar::Util::looks_like_number($_) ? : 0 0 0
!!$_ ? : 0 0 0
$_ =~ /true/iu ? : 0 0 0
430 }
431  
432 77 my $multiples = $argument->{multiples};
433  
434 77 ▶ return $multiples ? (wantarray ? (@{$value}) : $value) : $value->[0];
Branch: 2 branches
BranchTrueFalseTotal
$multiples ? : 32 45 77
wantarray ? : 7 25 32
435 }
436  
437 16 ▶sub argument_value_prompt {
Subroutine argument_value_prompt: called CC=5 SCAR=20.3
Pod undocumented
438 16 my ($self, $name) = @_;
439  
440 16 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 16 16
441  
442 16 my $argument = $self->argument($name);
443  
444 16 ▶ return undef if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 16 16
445  
446 16 my $prompt = $argument->{prompt};
447  
448 16 ▶ return undef if !$prompt;
Branch: 1 branch
BranchTrueFalseTotal
unless $prompt 16 0 16
449  
450 0 _print($prompt);
451  
452 0 my $captured = _prompt;
453  
454 0 ▶ return $captured eq '' ? undef : $captured;
Branch: 1 branch
BranchTrueFalseTotal
$captured eq '' ? : 0 0 0
455 }
456  
457 3 ▶sub argument_wants {
Subroutine argument_wants: called CC=3 SCAR=11.0
Pod documented
458 3 my ($self, $name) = @_;
459  
460 3 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
461  
462 2 my $argument = $self->argument($name);
463  
464 2 ▶ return '' if !$argument;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument 0 2 2
465  
466 2 my $wants = $argument->{wants};
467  
468 2 return $wants;
469 }
470  
471 18 ▶sub assigned_arguments {
Subroutine assigned_arguments: called CC=2 SCAR=6.9
Pod documented
472 18 my ($self) = @_;
473  
474 18 my $values = {};
475  
476 18 for my $name ($self->argument_names) {
477 16 $values->{$name} = $self->argument_value($name);
478 }
479  
480 18 return $values;
481 }
482  
483 18 ▶sub assigned_options {
Subroutine assigned_options: called CC=2 SCAR=6.9
Pod documented
484 18 my ($self) = @_;
485  
486 18 my $values = {};
487  
488 18 for my $name ($self->option_names) {
489 124 $values->{$name} = $self->option_value($name);
490 }
491  
492 18 return $values;
493 }
494  
495 4 ▶sub boolean {
Subroutine boolean: called CC=4 SCAR=13.9
Pod documented
496 4 my ($self, $next, @args) = @_;
497  
498 4 my $data = {type => 'boolean'};
499  
500 4 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 3 4
501  
502 4 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 2 4
503  
504 2 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 2 2
505  
506 2 push @args, $data;
507  
508 2 return $self->$next(@args);
509 }
510  
511 547 ▶sub choice {
Subroutine choice: called CC=11 SCAR=24.3
Pod documented
512 547 my ($self, $name, @data) = @_;
513  
514 547 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 545 547
515  
516 545 ▶ return $self->choices->{$name} if !@data;
Branch: 1 branch
BranchTrueFalseTotal
unless @data 165 380 545
517  
518 380 ▶ return delete $self->choices->{$name} if !defined $data[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data[0] 0 380 380
519  
520 my $defaults = {
521 name => $name,
522 label => undef,
523 help => undef,
524 argument => undef,
525 380 index => int(keys(%{$self->choices})),
526 wants => undef,
527 };
528  
529 380 require Venus;
530  
531 380 my $overrides = Venus::merge_take({}, @data);
532  
533 380 ▶ $overrides->{wants} //= $overrides->{type} || 'string' if !exists $overrides->{wants};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $overrides->{"wants"} 298 82 380
Condition75%3/4
$overrides->{"wants"} //= $overrides->{"type"} || "string"
l!l
0298
$overrides->{'type'} || 'string'
l!l
4294
MC/DC0%0/1
$overrides->{"wants"} //= $overrides->{"type"} || "string"
$overrides->{"wants"}
Truth table50%1/2
A
A= $overrides->{"wants"}
Aresult
11
00
534  
535 380 ▶ my $data = Venus::merge_take($self->choices->{$name} || $defaults, $overrides);
Condition66%2/3
$self->choices->{$name} || $defaults
l!l&&r!l&&!r
822980
MC/DC0%0/2
$self->choices->{$name} || $defaults
$self->choices->{$name} $defaults
Truth table66%2/3
A || B
A= $self->choices->{$name}B= $defaults
ABresult
1X1
011
000
536  
537 380 ▶ my $link = $self->argument($data->{argument}) if $data->{argument};
Branch: 1 branch
BranchTrueFalseTotal
if $data->{"argument"} 380 0 380
538  
539 380 ▶ $data->{help} ||= "Expects a $link->{type} value" if $link;
Branch: 1 branch
BranchTrueFalseTotal
if $link 380 0 380
Condition100%2/2
$data->{"help"} ||= qq[Expects a $link->{"type"} value]
l!l
30575
MC/DC100%1/1
$data->{"help"} ||= qq[Expects a $link->{"type"} value]
$data->{"help"}
Truth table100%2/2
A
A= $data->{"help"}
Aresult
11
00
540  
541 380 return $self->choices->{$name} = $data;
542 }
543  
544 1 ▶sub choice_argument {
Subroutine choice_argument: called CC=3 SCAR=11.2
Pod documented
545 1 my ($self, $name) = @_;
546  
547 1 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 1 1
548  
549 1 my $choice = $self->choice($name);
550  
551 1 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
552  
553 1 my $argument = $choice->{argument};
554  
555 1 return $self->argument($argument);
556 }
557  
558 28 ▶sub choice_count {
Subroutine choice_count: called CC=1 SCAR=0.0
Pod documented
559 28 my ($self) = @_;
560  
561 28 return int(scalar(keys(%{$self->choices})));
562 }
563  
564 1 ▶sub choice_default {
Subroutine choice_default: called CC=3 SCAR=11.2
Pod documented
565 1 my ($self, $name) = @_;
566  
567 1 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 1 1
568  
569 1 my $choice = $self->choice($name);
570  
571 1 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
572  
573 1 my $argument = $choice->{argument};
574  
575 1 return $self->argument_default($argument);
576 }
577  
578 3 ▶sub choice_errors {
Subroutine choice_errors: called CC=3 SCAR=11.0
Pod documented
579 3 my ($self, $name) = @_;
580  
581 3 ▶ return [] if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
582  
583 2 my $choice = $self->choice($name);
584  
585 2 ▶ return [] if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 2 2
586  
587 2 my $argument = $choice->{argument};
588  
589 2 return $self->argument_errors($argument);
590 }
591  
592 26 ▶sub choice_help {
Subroutine choice_help: called CC=3 SCAR=11.0
Pod documented
593 26 my ($self, $name) = @_;
594  
595 26 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 24 26
596  
597 24 my $choice = $self->choice($name);
598  
599 24 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 24 24
600  
601 24 my $help = $choice->{help};
602  
603 24 return $help;
604 }
605  
606 2 ▶sub choice_label {
Subroutine choice_label: called CC=3 SCAR=11.0
Pod documented
607 2 my ($self, $name) = @_;
608  
609 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
610  
611 1 my $choice = $self->choice($name);
612  
613 1 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
614  
615 1 my $label = $choice->{label};
616  
617 1 return $label;
618 }
619  
620 9 ▶sub choice_list {
Subroutine choice_list: called CC=2 SCAR=6.9
Pod documented
621 9 my ($self) = @_;
622  
623 9 my $output = [];
624  
625 9 my $choices = $self->choices;
626  
627 9 $output = [map $choices->{$_}, $self->choice_names];
628  
629 9 ▶ return wantarray ? @{$output} : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 7 2 9
630 }
631  
632 2 ▶sub choice_multiples {
Subroutine choice_multiples: called CC=3 SCAR=11.0
Pod documented
633 2 my ($self, $name) = @_;
634  
635 2 ▶ return false if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
636  
637 1 my $choice = $self->choice($name);
638  
639 1 ▶ return false if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
640  
641 1 my $argument = $choice->{argument};
642  
643 1 return $self->argument_multiples($argument);
644 }
645  
646 2 ▶sub choice_name {
Subroutine choice_name: called CC=3 SCAR=11.0
Pod documented
647 2 my ($self, $name) = @_;
648  
649 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
650  
651 1 my $choice = $self->choice($name);
652  
653 1 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
654  
655 1 $name = $choice->{name};
656  
657 1 return $name;
658 }
659  
660 570 ▶sub choice_names {
Subroutine choice_names: called CC=4 SCAR=14.0
Pod documented
661 570 my ($self) = @_;
662  
663 570 my $choices = $self->choices;
664  
665 my @names = sort {
666 (exists $choices->{$a}->{index} ? $choices->{$a}->{index} : $a)
667 186 ▶ <=> (exists $choices->{$b}->{index} ? $choices->{$b}->{index} : $b)
Branch: 2 branches
BranchTrueFalseTotal
exists $choices->{$a}{'index'} ? : 186 0 186
exists $choices->{$b}{'index'} ? : 186 0 186
668 570 } keys %{$choices};
669  
670 570 ▶ return wantarray ? (@names) : [@names];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 567 3 570
671 }
672  
673 2 ▶sub choice_prompt {
Subroutine choice_prompt: called CC=3 SCAR=11.0
Pod documented
674 2 my ($self, $name) = @_;
675  
676 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
677  
678 1 my $choice = $self->choice($name);
679  
680 1 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
681  
682 1 my $argument = $choice->{argument};
683  
684 1 return $self->argument_prompt($argument);
685 }
686  
687 2 ▶sub choice_range {
Subroutine choice_range: called CC=3 SCAR=11.0
Pod documented
688 2 my ($self, $name) = @_;
689  
690 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
691  
692 1 my $choice = $self->choice($name);
693  
694 1 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
695  
696 1 my $argument = $choice->{argument};
697  
698 1 return $self->argument_range($argument);
699 }
700  
701 2 ▶sub choice_required {
Subroutine choice_required: called CC=3 SCAR=11.0
Pod documented
702 2 my ($self, $name) = @_;
703  
704 2 ▶ return false if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
705  
706 1 my $choice = $self->choice($name);
707  
708 1 ▶ return false if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
709  
710 1 my $argument = $choice->{argument};
711  
712 1 return $self->argument_required($argument);
713 }
714  
715 2 ▶sub choice_type {
Subroutine choice_type: called CC=3 SCAR=11.0
Pod documented
716 2 my ($self, $name) = @_;
717  
718 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
719  
720 1 my $choice = $self->choice($name);
721  
722 1 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
723  
724 1 my $argument = $choice->{argument};
725  
726 1 return $self->argument_type($argument);
727 }
728  
729 4 ▶sub choice_validate {
Subroutine choice_validate: called CC=3 SCAR=11.0
Pod documented
730 4 my ($self, $name) = @_;
731  
732 4 ▶ return [] if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 3 4
733  
734 3 my $choice = $self->choice($name);
735  
736 3 ▶ return [] if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 3 3
737  
738 3 my $argument = $choice->{argument};
739  
740 3 return $self->argument_validate($argument);
741 }
742  
743 3 ▶sub choice_value {
Subroutine choice_value: called CC=3 SCAR=11.0
Pod documented
744 3 my ($self, $name) = @_;
745  
746 3 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
747  
748 2 my $choice = $self->choice($name);
749  
750 2 ▶ return undef if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 2 2
751  
752 2 my $argument = $choice->{argument};
753  
754 2 return $self->argument_value($argument);
755 }
756  
757 2 ▶sub choice_wants {
Subroutine choice_wants: called CC=3 SCAR=11.0
Pod documented
758 2 my ($self, $name) = @_;
759  
760 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
761  
762 1 my $choice = $self->choice($name);
763  
764 1 ▶ return '' if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 1 1
765  
766 1 my $argument = $choice->{argument};
767  
768 1 return $self->argument_wants($argument);
769 }
770  
771 56 ▶sub command {
Subroutine command: called CC=8 SCAR=20.9
Pod documented
772 56 my ($self, $argument_name, $choice_name, $handler) = @_;
773  
774 56 ▶ return undef if !$argument_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $argument_name 0 56 56
775 56 ▶ return undef if !$choice_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice_name 0 56 56
776 56 ▶ return undef if !$handler;
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 0 56 56
777  
778 56 require Venus;
779  
780 56 ▶ my $choice_parts = ref $choice_name eq 'ARRAY'
Branch: 1 branch
BranchTrueFalseTotal
ref $choice_name eq 'ARRAY' ? : 55 1 56
781 ? $choice_name
782 : [split /\s+/, $choice_name];
783  
784 56 my $route_name = join ' ', @{$choice_parts};
785  
786 56 my $range = ':' . ($#{$choice_parts});
787  
788 56 ▶ $self->argument($argument_name, {range => $range, multiples => $#{$choice_parts} > 0 ? 1 : 0})
Branch: 2 branches
BranchTrueFalseTotal
unless $self->argument($argument_name) 13 43 56
$#{$choice_parts;} > 0 ? : 10 3 13
789 if !$self->argument($argument_name);
790  
791 56 ▶ $self->choice($route_name, {argument => $argument_name})
Branch: 1 branch
BranchTrueFalseTotal
unless $self->choice($route_name) 21 35 56
792 if !$self->choice($route_name);
793  
794 56 $self->route($route_name, {
795 argument => $argument_name,
796 choice => $route_name,
797 handler => $handler,
798 range => $range,
799 });
800  
801 56 return $self->route($route_name);
802 }
803  
804 18 ▶sub dispatch {
Subroutine dispatch: called CC=22 SCAR=31.5
Pod documented
805 18 my ($self, @args) = @_;
806  
807 18 ▶ $self->parse(@args) if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 8 10 18
808  
809 18 my $parsed_arguments = $self->parsed_arguments;
810  
811 18 ▶ return undef if !$parsed_arguments || !@{$parsed_arguments};
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed_arguments and @{$parsed_arguments;} 3 15 18
Condition66%2/3
$parsed_arguments and @{$parsed_arguments;}
!ll&&!rl&&r
0315
MC/DC50%1/2
$parsed_arguments and @{$parsed_arguments;}
$parsed_arguments @{$parsed_arguments;}
Truth table66%2/3
A and B
A= $parsed_argumentsB= @{$parsed_arguments;}
ABresult
0X0
100
111
812  
813 15 my $matched_route = undef;
814 15 my $matched_length = -1;
815  
816 15 for my $route ($self->route_list) {
817 49 my $choice = $route->{choice};
818  
819 49 ▶ next if !$choice;
Branch: 1 branch
BranchTrueFalseTotal
unless $choice 0 49 49
820  
821 49 my @choice_parts = split /\s+/, $choice;
822 49 my $choice_length = scalar @choice_parts;
823  
824 49 ▶ next if $choice_length > scalar @{$parsed_arguments};
Branch: 1 branch
BranchTrueFalseTotal
if $choice_length > scalar @{$parsed_arguments;} 2 47 49
825  
826 47 my $matches = 1;
827  
828 47 for my $i (0..$#choice_parts) {
829 54 ▶ if ($parsed_arguments->[$i] ne $choice_parts[$i]) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parsed_arguments->[$i] ne $choice_parts[$i]) 33 21 54
830 33 $matches = 0;
831 33 last;
832 }
833 }
834  
835 47 ▶ if ($matches && $choice_length > $matched_length) {
Branch: 1 branch
BranchTrueFalseTotal
if ($matches and $choice_length > $matched_length) 12 35 47
Condition100%3/3
$matches and $choice_length > $matched_length
!ll&&!rl&&r
33212
MC/DC100%2/2
$matches and $choice_length > $matched_length
$matches $choice_length > $matched_length
Truth table100%3/3
A and B
A= $matchesB= $choice_length > $matched_length
ABresult
0X0
100
111
836 12 $matched_route = $route;
837 12 $matched_length = $choice_length;
838 }
839 }
840  
841 15 ▶ return undef if !$matched_route;
Branch: 1 branch
BranchTrueFalseTotal
unless $matched_route 3 12 15
842  
843 12 my $handler = $matched_route->{handler};
844  
845 12 ▶ return undef if !$handler;
Branch: 1 branch
BranchTrueFalseTotal
unless $handler 0 12 12
846  
847 12 ▶ if (ref $handler ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handler) 5 7 12
848 5 ▶ if (ref $handler eq 'CODE') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $handler eq 'CODE') { } 5 0 5
849 5 return $handler->($self, $self->assigned_arguments, $self->assigned_options);
850 }
851 else {
852 0 return undef;
853 }
854 }
855  
856 7 require Venus::Space;
857  
858 7 my $space = Venus::Space->new($handler);
859  
860 7 ▶ if ($handler !~ /\W/ && $self->can($handler)) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $handler =~ /\W/u and $self->can($handler)) 1 6 7
Condition100%3/3
not $handler =~ /\W/u and $self->can($handler)
!ll&&!rl&&r
511
MC/DC100%2/2
not $handler =~ /\W/u and $self->can($handler)
not $handler =~ /\W/u $self->can($handler)
Truth table100%3/3
not(A) and B
A= not $handler =~ /\W/uB= $self->can($handler)
ABresult
0X0
100
111
861 1 return $self->$handler($self->assigned_arguments, $self->assigned_options);
862 }
863  
864 6 ▶ if ($space->lookslike_a_package && $space->tryload) {
Branch: 1 branch
BranchTrueFalseTotal
if ($space->lookslike_a_package and $space->tryload) 5 1 6
Condition66%2/3
$space->lookslike_a_package and $space->tryload
!ll&&!rl&&r
015
MC/DC50%1/2
$space->lookslike_a_package and $space->tryload
$space->lookslike_a_package $space->tryload
Truth table66%2/3
A and B
A= $space->lookslike_a_packageB= $space->tryload
ABresult
0X0
100
111
865 5 my $remaining_args = [@{$parsed_arguments}[$matched_length..$#{$parsed_arguments}]];
866  
867 5 my $remaining_data = [grep {$_ ne '--'} @{$self->data}];
868  
869 5 splice @{$remaining_data}, 0, $matched_length
870 5 ▶ if @{$remaining_data} >= $matched_length;
Branch: 1 branch
BranchTrueFalseTotal
if @{$remaining_data;} >= $matched_length 5 0 5
871  
872 5 my $instance = $space->package->new;
873  
874 5 ▶ if ($instance->isa('Venus::Task')) {
Branch: 2 branches
BranchTrueFalseTotal
if ($instance->isa('Venus::Task')) { } 5 0 5
elsif ($instance->isa('Venus::Cli')) { } 0 0 0
875 5 return $instance->handle(@{$remaining_data});
876 }
877 elsif ($instance->isa('Venus::Cli')) {
878 0 return $instance->dispatch(@{$remaining_data});
879 }
880 else {
881 0 return $instance;
882 }
883 }
884  
885 1 return undef;
886 }
887  
888 17 ▶sub exit {
Subroutine exit: called CC=3 SCAR=11.0
Pod documented
889 17 my ($self, $code, $method, @args) = @_;
890  
891 17 ▶ $self->$method(@args) if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 8 9 17
892  
893 17 ▶ $code ||= 0;
Condition100%2/2
$code ||= 0
l!l
710
MC/DC100%1/1
$code ||= 0
$code
Truth table100%2/2
A
A= $code
Aresult
11
00
894  
895 17 _exit($code);
896 }
897  
898 4 ▶sub fail {
Subroutine fail: called CC=1 SCAR=0.0
Pod documented
899 4 my ($self, $method, @args) = @_;
900  
901 4 return $self->exit(1, $method, @args);
902 }
903  
904 3 ▶sub float {
Subroutine float: called CC=4 SCAR=13.9
Pod documented
905 3 my ($self, $next, @args) = @_;
906  
907 3 my $data = {type => 'float'};
908  
909 3 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 2 3
910  
911 3 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 1 3
912  
913 1 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
914  
915 1 push @args, $data;
916  
917 1 return $self->$next(@args);
918 }
919  
920 2 ▶sub has_input {
Subroutine has_input: called CC=2 SCAR=6.9
Pod documented
921 2 my ($self) = @_;
922  
923 2 ▶ return !$self->no_input ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_input ? : 1 1 2
924 }
925  
926 2 ▶sub has_input_arguments {
Subroutine has_input_arguments: called CC=2 SCAR=6.9
Pod documented
927 2 my ($self) = @_;
928  
929 2 ▶ return !$self->no_input_arguments ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_input_arguments ? : 1 1 2
930 }
931  
932 2 ▶sub has_input_options {
Subroutine has_input_options: called CC=2 SCAR=6.9
Pod documented
933 2 my ($self) = @_;
934  
935 2 ▶ return !$self->no_input_options ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_input_options ? : 1 1 2
936 }
937  
938 3 ▶sub has_output {
Subroutine has_output: called CC=2 SCAR=6.9
Pod documented
939 3 my ($self) = @_;
940  
941 3 ▶ return !$self->no_output ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_output ? : 2 1 3
942 }
943  
944 2 ▶sub has_output_debug_events {
Subroutine has_output_debug_events: called CC=2 SCAR=6.9
Pod documented
945 2 my ($self) = @_;
946  
947 2 ▶ return !$self->no_output_debug_events ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_output_debug_events ? : 1 1 2
948 }
949  
950 8 ▶sub has_output_error_events {
Subroutine has_output_error_events: called CC=2 SCAR=6.9
Pod documented
951 8 my ($self) = @_;
952  
953 8 ▶ return !$self->no_output_error_events ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_output_error_events ? : 1 7 8
954 }
955  
956 2 ▶sub has_output_fatal_events {
Subroutine has_output_fatal_events: called CC=2 SCAR=6.9
Pod documented
957 2 my ($self) = @_;
958  
959 2 ▶ return !$self->no_output_fatal_events ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_output_fatal_events ? : 1 1 2
960 }
961  
962 3 ▶sub has_output_info_events {
Subroutine has_output_info_events: called CC=2 SCAR=6.9
Pod documented
963 3 my ($self) = @_;
964  
965 3 ▶ return !$self->no_output_info_events ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_output_info_events ? : 2 1 3
966 }
967  
968 2 ▶sub has_output_trace_events {
Subroutine has_output_trace_events: called CC=2 SCAR=6.9
Pod documented
969 2 my ($self) = @_;
970  
971 2 ▶ return !$self->no_output_trace_events ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_output_trace_events ? : 1 1 2
972 }
973  
974 2 ▶sub has_output_warn_events {
Subroutine has_output_warn_events: called CC=2 SCAR=6.9
Pod documented
975 2 my ($self) = @_;
976  
977 2 ▶ return !$self->no_output_warn_events ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
!$self->no_output_warn_events ? : 1 1 2
978 }
979  
980 6 ▶sub help {
Subroutine help: called CC=1 SCAR=0.0
Pod documented
981 6 my ($self) = @_;
982  
983 6 $self->log_info($self->usage);
984  
985 6 return $self;
986 }
987  
988 39 ▶sub input {
Subroutine input: called CC=4 SCAR=13.9
Pod documented
989 39 my ($self) = @_;
990  
991 39 my ($arguments, $options) = ({}, {});
992  
993 39 for my $name ($self->argument_names) {
994 22 $arguments->{$self->arguments->{$name}->{name}} = $self->argument_value($name);
995 }
996  
997 39 for my $name ($self->option_names) {
998 843 $options->{$self->options->{$name}->{name}} = $self->option_value($name);
999 }
1000  
1001 39 ▶ return wantarray ? ($arguments, $options) : $arguments;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 37 2 39
1002 }
1003  
1004 18 ▶sub input_arguments {
Subroutine input_arguments: called CC=3 SCAR=12.7
Pod documented
1005 18 my ($self) = @_;
1006  
1007 0 ▶ return $self->{input_arguments} if $self->{input_arguments} && keys %{$self->{input_arguments}};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"input_arguments"} and keys %{$$self{"input_arguments"};} 0 18 18
Condition33%1/3
$self->{"input_arguments"} and keys %{$$self{"input_arguments"};}
!ll&&!rl&&r
1800
MC/DC0%0/2
$self->{"input_arguments"} and keys %{$$self{"input_arguments"};}
$self->{"input_arguments"} keys %{$$self{"input_arguments"};}
Truth table33%1/3
A and B
A= $self->{"input_arguments"}B= keys %{$$self{"input_arguments"};}
ABresult
0X0
100
111
1008  
1009 18 my ($arguments, $options) = $self->input;
1010  
1011 18 return $self->{input_arguments} = $arguments;
1012 }
1013  
1014 12 ▶sub input_arguments_defined {
Subroutine input_arguments_defined: called CC=3 SCAR=11.0
Pod documented
1015 12 my ($self) = @_;
1016  
1017 12 my $arguments = $self->input_arguments;
1018  
1019 12 %{$arguments} = (
1020 map +(
1021 ref $arguments->{$_} eq 'ARRAY'
1022 8 ? !@{$arguments->{$_}}
1023 ? ()
1024 : ($_, $arguments->{$_})
1025 : ($_, $arguments->{$_})
1026 ),
1027 grep defined $arguments->{$_},
1028 12 ▶ keys %{$arguments},
Branch: 2 branches
BranchTrueFalseTotal
ref $arguments->{$_} eq 'ARRAY' ? : 8 6 14
!@{$arguments->{$_};} ? : 4 4 8
1029 );
1030  
1031 12 return $arguments;
1032 }
1033  
1034 8 ▶sub input_arguments_defined_count {
Subroutine input_arguments_defined_count: called CC=1 SCAR=0.0
Pod documented
1035 8 my ($self) = @_;
1036  
1037 8 my $arguments = $self->input_arguments_defined;
1038  
1039 8 return 0 + (keys %{$arguments});
1040 }
1041  
1042 2 ▶sub input_arguments_defined_list {
Subroutine input_arguments_defined_list: called CC=2 SCAR=7.2
Pod documented
1043 2 my ($self) = @_;
1044  
1045 2 my $arguments = $self->input_arguments_defined;
1046  
1047 2 my $keys = [keys %{$arguments}];
1048  
1049 0 ▶ return wantarray ? (@{$keys}) : $keys;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
1050 }
1051  
1052 2 ▶sub input_argument_count {
Subroutine input_argument_count: called CC=1 SCAR=0.0
Pod documented
1053 2 my ($self) = @_;
1054  
1055 2 my $arguments = $self->input_arguments;
1056  
1057 2 return 0 + (keys %{$arguments});
1058 }
1059  
1060 2 ▶sub input_argument_list {
Subroutine input_argument_list: called CC=2 SCAR=6.9
Pod documented
1061 2 my ($self) = @_;
1062  
1063 2 my $arguments = $self->input_arguments;
1064  
1065 2 my $keys = [keys %{$arguments}];
1066  
1067 2 ▶ return wantarray ? (@{$keys}) : $keys;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 1 2
1068 }
1069  
1070 91 ▶sub input_options {
Subroutine input_options: called CC=4 SCAR=14.3
Pod documented
1071 91 my ($self) = @_;
1072  
1073 91 ▶ return $self->{input_options} if $self->{input_options} && keys %{$self->{input_options}};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"input_options"} and keys %{$$self{"input_options"};} 72 19 91
Condition66%2/3
$self->{"input_options"} and keys %{$$self{"input_options"};}
!ll&&!rl&&r
19072
MC/DC50%1/2
$self->{"input_options"} and keys %{$$self{"input_options"};}
$self->{"input_options"} keys %{$$self{"input_options"};}
Truth table66%2/3
A and B
A= $self->{"input_options"}B= keys %{$$self{"input_options"};}
ABresult
0X0
100
111
1074  
1075 19 my ($arguments, $options) = $self->input;
1076  
1077 19 ▶ return $self->{input_options} ||= $options;
Condition33%1/3
$self->{"input_options"} ||= $options
l!l&&r!l&&!r
0190
MC/DC0%0/2
$self->{"input_options"} ||= $options
$self->{"input_options"} $options
Truth table33%1/3
A ||= B
A= $self->{"input_options"}B= $options
ABresult
1X1
011
000
1078 }
1079  
1080 13 ▶sub input_options_defined {
Subroutine input_options_defined: called CC=3 SCAR=11.0
Pod documented
1081 13 my ($self) = @_;
1082  
1083 13 my $options = $self->input_options;
1084  
1085 13 %{$options} = (
1086 map +(
1087 ref $options->{$_} eq 'ARRAY'
1088 162 ? !@{$options->{$_}}
1089 ? ()
1090 : ($_, $options->{$_})
1091 : ($_, $options->{$_})
1092 ),
1093 grep defined $options->{$_},
1094 13 ▶ keys %{$options},
Branch: 2 branches
BranchTrueFalseTotal
ref $options->{$_} eq 'ARRAY' ? : 162 20 182
!@{$options->{$_};} ? : 159 3 162
1095 );
1096  
1097 13 return $options;
1098 }
1099  
1100 3 ▶sub input_options_defined_count {
Subroutine input_options_defined_count: called CC=1 SCAR=0.0
Pod documented
1101 3 my ($self) = @_;
1102  
1103 3 my $options = $self->input_options_defined;
1104  
1105 3 return 0 + (keys %{$options});
1106 }
1107  
1108 3 ▶sub input_options_defined_list {
Subroutine input_options_defined_list: called CC=2 SCAR=7.2
Pod documented
1109 3 my ($self) = @_;
1110  
1111 3 my $options = $self->input_options_defined;
1112  
1113 3 my $keys = [keys %{$options}];
1114  
1115 0 ▶ return wantarray ? (@{$keys}) : $keys;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 3 3
1116 }
1117  
1118 2 ▶sub input_option_count {
Subroutine input_option_count: called CC=1 SCAR=0.0
Pod documented
1119 2 my ($self) = @_;
1120  
1121 2 my $options = $self->input_options;
1122  
1123 2 return 0 + (keys %{$options});
1124 }
1125  
1126 2 ▶sub input_option_list {
Subroutine input_option_list: called CC=2 SCAR=7.2
Pod documented
1127 2 my ($self) = @_;
1128  
1129 2 my $options = $self->input_options;
1130  
1131 2 my $keys = [keys %{$options}];
1132  
1133 0 ▶ return wantarray ? (@{$keys}) : $keys;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
1134 }
1135  
1136 301 ▶sub lines {
Subroutine lines: called CC=1 SCAR=0.0
Pod documented
1137 301 my ($self, $text, $length, $indent) = @_;
1138  
1139 301 require Venus::String;
1140  
1141 301 my $string = Venus::String->new($text);
1142  
1143 301 return scalar $string->wrap($length, $indent);
1144 }
1145  
1146 110 ▶sub log {
Subroutine log: called CC=1 SCAR=0.0
Pod documented
1147 110 my ($self) = @_;
1148  
1149 110 require Venus::Log;
1150  
1151 110 my $log = Venus::Log->new(handler => $self->log_handler, level => $self->log_level);
1152  
1153 110 return $log;
1154 }
1155  
1156 14 ▶sub log_debug {
Subroutine log_debug: called CC=1 SCAR=0.0
Pod documented
1157 14 my ($self, @args) = @_;
1158  
1159 14 my $log = $self->log;
1160  
1161 14 return $log->debug(@args);
1162 }
1163  
1164 15 ▶sub log_error {
Subroutine log_error: called CC=1 SCAR=0.0
Pod documented
1165 15 my ($self, @args) = @_;
1166  
1167 15 my $log = $self->log;
1168  
1169 15 return $log->error(@args);
1170 }
1171  
1172 215 ▶sub log_events {
Subroutine log_events: called CC=2 SCAR=6.9
Pod documented
1173 215 my ($self) = @_;
1174  
1175 215 ▶ my $logs = $self->{logs} ||= [];
Condition100%2/2
$self->{"logs"} ||= []
l!l
104111
MC/DC100%1/1
$self->{"logs"} ||= []
$self->{"logs"}
Truth table100%2/2
A
A= $self->{"logs"}
Aresult
11
00
1176  
1177 215 return $logs;
1178 }
1179  
1180 9 ▶sub log_fatal {
Subroutine log_fatal: called CC=1 SCAR=0.0
Pod documented
1181 9 my ($self, @args) = @_;
1182  
1183 9 my $log = $self->log;
1184  
1185 9 return $log->fatal(@args);
1186 }
1187  
1188 2 ▶sub log_flush {
Subroutine log_flush: called CC=3 SCAR=11.0
Pod documented
1189 2 my ($self, $code) = @_;
1190  
1191 2 for my $event (@{$self->log_events}) {
1192 4 local $_ = $event;
1193  
1194 4 ▶ $self->$code($event) if $code;
Branch: 1 branch
BranchTrueFalseTotal
if $code 4 0 4
1195 }
1196  
1197 2 @{$self->log_events} = ();
1198  
1199 2 return $self;
1200 }
1201  
1202 111 ▶sub log_handler {
Subroutine log_handler: called CC=1 SCAR=0.0
Pod documented
1203 111 my ($self, @args) = @_;
1204  
1205 111 my $log_events = $self->log_events;
1206  
1207 109 ▶ my $handler = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
1208 109 push @{$log_events}, [@_];
1209 111 };
1210  
1211 111 return $handler;
1212 }
1213  
1214 52 ▶sub log_info {
Subroutine log_info: called CC=1 SCAR=0.0
Pod documented
1215 52 my ($self, @args) = @_;
1216  
1217 52 my $log = $self->log;
1218  
1219 52 return $log->info(@args);
1220 }
1221  
1222 111 ▶sub log_level {
Subroutine log_level: called CC=1 SCAR=0.0
Pod documented
1223  
1224 111 return 'trace';
1225 }
1226  
1227 9 ▶sub log_trace {
Subroutine log_trace: called CC=1 SCAR=0.0
Pod documented
1228 9 my ($self, @args) = @_;
1229  
1230 9 my $log = $self->log;
1231  
1232 9 return $log->trace(@args);
1233 }
1234  
1235 10 ▶sub log_warn {
Subroutine log_warn: called CC=1 SCAR=0.0
Pod documented
1236 10 my ($self, @args) = @_;
1237  
1238 10 my $log = $self->log;
1239  
1240 10 return $log->warn(@args);
1241 }
1242  
1243 3 ▶sub multiple {
Subroutine multiple: called CC=4 SCAR=13.9
Pod documented
1244 3 my ($self, $next, @args) = @_;
1245  
1246 3 my $data = {multiples => true};
1247  
1248 3 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 2 3
1249  
1250 3 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 1 3
1251  
1252 1 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
1253  
1254 1 push @args, $data;
1255  
1256 1 return $self->$next(@args);
1257 }
1258  
1259 9 ▶sub no_input {
Subroutine no_input: called CC=3 SCAR=11.0
Pod documented
1260 9 my ($self) = @_;
1261  
1262 9 my @data = $self->parsed;
1263  
1264 9 ▶ return (keys %{$data[0]}) || (@{$data[1]}) ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
keys %{$data[0];} || @{$data[1];} ? : 7 2 9
Condition100%3/3
keys %{$data[0];} or @{$data[1];}
l!l&&r!l&&!r
342
MC/DC100%2/2
keys %{$data[0];} or @{$data[1];}
keys %{$data[0];} @{$data[1];}
Truth table100%3/3
A or B
A= keys %{$data[0];}B= @{$data[1];}
ABresult
1X1
011
000
1265 }
1266  
1267 4 ▶sub no_input_arguments {
Subroutine no_input_arguments: called CC=2 SCAR=6.9
Pod documented
1268 4 my ($self) = @_;
1269  
1270 4 my @data = $self->parsed;
1271  
1272 4 ▶ return @{$data[1]} ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
@{$data[1];} ? : 2 2 4
1273 }
1274  
1275 4 ▶sub no_input_options {
Subroutine no_input_options: called CC=2 SCAR=6.9
Pod documented
1276 4 my ($self) = @_;
1277  
1278 4 my @data = $self->parsed;
1279  
1280 4 ▶ return keys %{$data[0]} ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
keys %{$data[0];} ? : 2 2 4
1281 }
1282  
1283 5 ▶sub no_output {
Subroutine no_output: called CC=2 SCAR=6.9
Pod documented
1284 5 my ($self) = @_;
1285  
1286 5 my @data = $self->output;
1287  
1288 5 ▶ return @data ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
@data ? : 3 2 5
1289 }
1290  
1291 4 ▶sub no_output_debug_events {
Subroutine no_output_debug_events: called CC=2 SCAR=6.9
Pod documented
1292 4 my ($self) = @_;
1293  
1294 4 my @data = $self->output('debug');
1295  
1296 4 ▶ return @data ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
@data ? : 2 2 4
1297 }
1298  
1299 10 ▶sub no_output_error_events {
Subroutine no_output_error_events: called CC=2 SCAR=6.9
Pod documented
1300 10 my ($self) = @_;
1301  
1302 10 my @data = $self->output('error');
1303  
1304 10 ▶ return @data ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
@data ? : 2 8 10
1305 }
1306  
1307 4 ▶sub no_output_fatal_events {
Subroutine no_output_fatal_events: called CC=2 SCAR=6.9
Pod documented
1308 4 my ($self) = @_;
1309  
1310 4 my @data = $self->output('fatal');
1311  
1312 4 ▶ return @data ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
@data ? : 2 2 4
1313 }
1314  
1315 5 ▶sub no_output_info_events {
Subroutine no_output_info_events: called CC=2 SCAR=6.9
Pod documented
1316 5 my ($self) = @_;
1317  
1318 5 my @data = $self->output('info');
1319  
1320 5 ▶ return @data ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
@data ? : 3 2 5
1321 }
1322  
1323 4 ▶sub no_output_trace_events {
Subroutine no_output_trace_events: called CC=2 SCAR=6.9
Pod documented
1324 4 my ($self) = @_;
1325  
1326 4 my @data = $self->output('trace');
1327  
1328 4 ▶ return @data ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
@data ? : 2 2 4
1329 }
1330  
1331 4 ▶sub no_output_warn_events {
Subroutine no_output_warn_events: called CC=2 SCAR=6.9
Pod documented
1332 4 my ($self) = @_;
1333  
1334 4 my @data = $self->output('warn');
1335  
1336 4 ▶ return @data ? false : true;
Branch: 1 branch
BranchTrueFalseTotal
@data ? : 2 2 4
1337 }
1338  
1339 3 ▶sub number {
Subroutine number: called CC=4 SCAR=13.9
Pod documented
1340 3 my ($self, $next, @args) = @_;
1341  
1342 3 my $data = {type => 'number'};
1343  
1344 3 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 2 3
1345  
1346 3 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 1 3
1347  
1348 1 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
1349  
1350 1 push @args, $data;
1351  
1352 1 return $self->$next(@args);
1353 }
1354  
1355 3 ▶sub okay {
Subroutine okay: called CC=1 SCAR=0.0
Pod documented
1356 3 my ($self, $method, @args) = @_;
1357  
1358 3 return $self->exit(0, $method, @args);
1359 }
1360  
1361 3606 ▶sub option {
Subroutine option: called CC=14 SCAR=26.8
Pod documented
1362 3606 my ($self, $name, @data) = @_;
1363  
1364 3606 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 3604 3606
1365  
1366 3604 ▶ return $self->options->{$name} if !@data;
Branch: 1 branch
BranchTrueFalseTotal
unless @data 2538 1066 3604
1367  
1368 1066 ▶ return delete $self->options->{$name} if !defined $data[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data[0] 0 1066 1066
1369  
1370 my $defaults = {
1371 name => $name,
1372 label => undef,
1373 help => undef,
1374 default => undef,
1375 aliases => undef,
1376 multiples => 0,
1377 prompt => undef,
1378 range => undef,
1379 required => false,
1380 type => 'string',
1381 1066 index => int(keys(%{$self->options})),
1382 wants => undef,
1383 };
1384  
1385 1066 require Venus;
1386  
1387 1066 my $overrides = Venus::merge_take({}, @data);
1388  
1389 1066 ▶ $overrides->{aliases} //= [Venus::list($overrides->{alias})] if exists $overrides->{alias};
Branch: 1 branch
BranchTrueFalseTotal
if exists $overrides->{"alias"} 10 1056 1066
Condition50%1/2
$overrides->{"aliases"} //= [&Venus::list($overrides->{"alias"})]
l!l
010
MC/DC0%0/1
$overrides->{"aliases"} //= [&Venus::list($overrides->{"alias"})]
$overrides->{"aliases"}
Truth table50%1/2
A
A= $overrides->{"aliases"}
Aresult
11
00
1390  
1391 1066 ▶ $overrides->{wants} //= $overrides->{type} || 'string' if !exists $overrides->{wants};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $overrides->{"wants"} 217 849 1066
Condition75%3/4
$overrides->{"wants"} //= $overrides->{"type"} || "string"
l!l
0217
$overrides->{'type'} || 'string'
l!l
19027
MC/DC0%0/1
$overrides->{"wants"} //= $overrides->{"type"} || "string"
$overrides->{"wants"}
Truth table50%1/2
A
A= $overrides->{"wants"}
Aresult
11
00
1392  
1393 1066 ▶ my $data = Venus::merge_take($self->options->{$name} || $defaults, $overrides);
Condition66%2/3
$self->options->{$name} || $defaults
l!l&&r!l&&!r
1339330
MC/DC0%0/2
$self->options->{$name} || $defaults
$self->options->{$name} $defaults
Truth table66%2/3
A || B
A= $self->options->{$name}B= $defaults
ABresult
1X1
011
000
1394  
1395 1066 ▶ $data->{aliases} = [$data->{aliases} // ()] if !ref $data->{aliases};
Branch: 1 branch
BranchTrueFalseTotal
unless ref $data->{"aliases"} 708 358 1066
Condition66%2/3
$data->{"aliases"} // ()
l!l&&r!l&&!r
10707
MC/DC50%1/2
$data->{"aliases"} // ()
$data->{"aliases"} ()
Truth table66%2/3
A // B
A= $data->{"aliases"}B= ()
ABresult
1X1
011
000
1396  
1397 1066 ▶ $data->{help} ||= "Expects a $data->{type} value";
Condition100%2/2
$data->{"help"} ||= qq[Expects a $data->{"type"} value]
l!l
833233
MC/DC100%1/1
$data->{"help"} ||= qq[Expects a $data->{"type"} value]
$data->{"help"}
Truth table100%2/2
A
A= $data->{"help"}
Aresult
11
00
1398  
1399 1066 ▶ return $self->options->{$data->{name} ? $data->{name} : $name} = $data;
Branch: 1 branch
BranchTrueFalseTotal
$data->{'name'} ? : 1066 0 1066
1400 }
1401  
1402 4 ▶sub option_aliases {
Subroutine option_aliases: called CC=3 SCAR=11.0
Pod documented
1403 4 my ($self, $name) = @_;
1404  
1405 4 ▶ return [] if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 3 4
1406  
1407 3 my $option = $self->option($name);
1408  
1409 3 ▶ return [] if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 3 3
1410  
1411 3 my $aliases = $option->{aliases};
1412  
1413 3 return $aliases;
1414 }
1415  
1416 44 ▶sub option_count {
Subroutine option_count: called CC=1 SCAR=0.0
Pod documented
1417 44 my ($self) = @_;
1418  
1419 44 return int(scalar(keys(%{$self->options})));
1420 }
1421  
1422 37 ▶sub option_default {
Subroutine option_default: called CC=3 SCAR=11.0
Pod documented
1423 37 my ($self, $name) = @_;
1424  
1425 37 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 35 37
1426  
1427 35 my $option = $self->option($name);
1428  
1429 35 ▶ return '' if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 35 35
1430  
1431 35 my $default = $option->{default};
1432  
1433 35 return $default;
1434 }
1435  
1436 121 ▶sub option_errors {
Subroutine option_errors: called CC=4 SCAR=13.9
Pod documented
1437 121 my ($self, $name) = @_;
1438  
1439 121 ▶ return [] if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 120 121
1440  
1441 120 my $result = $self->option_validate($name);
1442  
1443 120 ▶ $result = [$result] if ref $result ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if ref $result ne "ARRAY" 93 27 120
1444  
1445 120 $result = [grep defined, map $_->issue, @{$result}];
1446  
1447 120 ▶ return wantarray ? (@{$result}) : $result;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 118 2 120
1448 }
1449  
1450 36 ▶sub option_help {
Subroutine option_help: called CC=3 SCAR=11.0
Pod documented
1451 36 my ($self, $name) = @_;
1452  
1453 36 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 34 36
1454  
1455 34 my $option = $self->option($name);
1456  
1457 34 ▶ return '' if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 34 34
1458  
1459 34 my $help = $option->{help};
1460  
1461 34 return $help;
1462 }
1463  
1464 2 ▶sub option_label {
Subroutine option_label: called CC=3 SCAR=11.0
Pod documented
1465 2 my ($self, $name) = @_;
1466  
1467 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
1468  
1469 1 my $option = $self->option($name);
1470  
1471 1 ▶ return '' if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 1 1
1472  
1473 1 my $label = $option->{label};
1474  
1475 1 return $label;
1476 }
1477  
1478 140 ▶sub option_list {
Subroutine option_list: called CC=2 SCAR=6.9
Pod documented
1479 140 my ($self) = @_;
1480  
1481 140 my $output = [];
1482  
1483 140 my $options = $self->options;
1484  
1485 140 $output = [map $options->{$_}, $self->option_names];
1486  
1487 140 ▶ return wantarray ? @{$output} : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 138 2 140
1488 }
1489  
1490 2 ▶sub option_multiples {
Subroutine option_multiples: called CC=4 SCAR=14.0
Pod documented
1491 2 my ($self, $name) = @_;
1492  
1493 2 ▶ return false if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
1494  
1495 1 my $option = $self->option($name);
1496  
1497 1 ▶ return false if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 1 1
1498  
1499 1 my $multiples = $option->{multiples};
1500  
1501 1 ▶ return $multiples ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$multiples ? : 1 0 1
1502 }
1503  
1504 3 ▶sub option_name {
Subroutine option_name: called CC=3 SCAR=11.0
Pod documented
1505 3 my ($self, $name) = @_;
1506  
1507 3 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
1508  
1509 2 my $option = $self->option($name);
1510  
1511 2 ▶ return '' if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 1 1 2
1512  
1513 1 $name = $option->{name};
1514  
1515 1 return $name;
1516 }
1517  
1518 803 ▶sub option_names {
Subroutine option_names: called CC=4 SCAR=14.0
Pod documented
1519 803 my ($self) = @_;
1520  
1521 803 my $options = $self->options;
1522  
1523 my @names = sort {
1524 (exists $options->{$a}->{index} ? $options->{$a}->{index} : $a)
1525 10113 ▶ <=> (exists $options->{$b}->{index} ? $options->{$b}->{index} : $b)
Branch: 2 branches
BranchTrueFalseTotal
exists $options->{$a}{'index'} ? : 10113 0 10113
exists $options->{$b}{'index'} ? : 10113 0 10113
1526 803 } keys %{$options};
1527  
1528 803 ▶ return wantarray ? (@names) : [@names];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 800 3 803
1529 }
1530  
1531 2 ▶sub option_prompt {
Subroutine option_prompt: called CC=3 SCAR=11.0
Pod documented
1532 2 my ($self, $name) = @_;
1533  
1534 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
1535  
1536 1 my $option = $self->option($name);
1537  
1538 1 ▶ return '' if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 1 1
1539  
1540 1 my $prompt = $option->{prompt};
1541  
1542 1 return $prompt;
1543 }
1544  
1545 3 ▶sub option_range {
Subroutine option_range: called CC=3 SCAR=11.0
Pod documented
1546 3 my ($self, $name) = @_;
1547  
1548 3 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
1549  
1550 2 my $option = $self->option($name);
1551  
1552 2 ▶ return '' if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 2 2
1553  
1554 2 my $range = $option->{range};
1555  
1556 2 return $range;
1557 }
1558  
1559 37 ▶sub option_required {
Subroutine option_required: called CC=4 SCAR=13.9
Pod documented
1560 37 my ($self, $name) = @_;
1561  
1562 37 ▶ return false if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 2 35 37
1563  
1564 35 my $option = $self->option($name);
1565  
1566 35 ▶ return false if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 35 35
1567  
1568 35 my $required = $option->{required};
1569  
1570 35 ▶ return $required ? true : false;
Branch: 1 branch
BranchTrueFalseTotal
$required ? : 6 29 35
1571 }
1572  
1573 2 ▶sub option_type {
Subroutine option_type: called CC=3 SCAR=11.0
Pod documented
1574 2 my ($self, $name) = @_;
1575  
1576 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
1577  
1578 1 my $option = $self->option($name);
1579  
1580 1 ▶ return '' if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 1 1
1581  
1582 1 my $type = $option->{type};
1583  
1584 1 return $type;
1585 }
1586  
1587 124 ▶sub option_validate {
Subroutine option_validate: called CC=14 SCAR=26.9
Pod documented
1588 124 my ($self, $name) = @_;
1589  
1590 124 ▶ return [] if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 123 124
1591  
1592 123 my $option = $self->option($name);
1593  
1594 123 ▶ return [] if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 123 123
1595  
1596 123 require Venus::Validate;
1597  
1598 123 my $validate = Venus::Validate->new(input => [$self->option_value($name)]);
1599  
1600 123 ▶ my $required = $option->{required} ? 'required' : 'optional';
Branch: 1 branch
BranchTrueFalseTotal
$option->{'required'} ? : 0 123 123
1601  
1602 123 my $value = $validate->each($required);
1603  
1604 123 my $type = 'string';
1605  
1606 123 ▶ $type = 'boolean' if $option->{type} eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "boolean" 85 38 123
1607 123 ▶ $type = 'float' if $option->{type} eq 'float';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "float" 0 123 123
1608 123 ▶ $type = 'number' if $option->{type} eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "number" 1 122 123
1609 123 ▶ $type = 'any' if $option->{type} eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "string" 37 86 123
1610 123 ▶ $type = 'yesno' if $option->{type} eq 'yesno';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "yesno" 0 123 123
1611  
1612 123 for my $value (@{$value}) {
1613 124 ▶ next if $required eq 'optional' && !defined $value->input->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $required eq "optional" and not defined $value->input->[0] 119 5 124
Condition66%2/3
$required eq "optional" and not defined $value->input->[0]
!ll&&!rl&&r
05119
MC/DC50%1/2
$required eq "optional" and not defined $value->input->[0]
$required eq "optional" not defined $value->input->[0]
Truth table66%2/3
A and not(B)
A= $required eq "optional"B= not defined $value->input->[0]
ABresult
0X0
100
111
1614 5 $value->type($type);
1615 }
1616  
1617 123 my $multiples = $option->{multiples};
1618  
1619 0 ▶ return $multiples ? (wantarray ? (@{$value}) : $value) : $value->[0];
Branch: 2 branches
BranchTrueFalseTotal
$multiples ? : 29 94 123
wantarray ? : 0 29 29
1620 }
1621  
1622 1094 ▶sub option_value {
Subroutine option_value: called CC=23 SCAR=33.2
Pod documented
1623 1094 my ($self, $name) = @_;
1624  
1625 1094 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1093 1094
1626  
1627 1093 my $option = $self->option($name);
1628  
1629 1093 ▶ return undef if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 1093 1093
1630  
1631 1093 my $parsed_options = $self->parsed_options;
1632  
1633 1093 my $default = $option->{default};
1634  
1635 my $value = exists $parsed_options->{$name}
1636 ? ref $parsed_options->{$name} eq 'ARRAY'
1637 ? $parsed_options->{$name}
1638 1093 ▶ : [$parsed_options->{$name} // ()]
Branch: 4 branches
BranchTrueFalseTotal
exists $parsed_options->{$name} ? : 43 1050 1093
ref $parsed_options->{$name} eq 'ARRAY' ? : 7 36 43
$default ? : 1 1049 1050
ref $default eq 'ARRAY' ? : 0 1 1
Condition33%3/9
$parsed_options->{$name} // ()
l!l&&r!l&&!r
3600
$default // ()
l!l&&r!l&&!r
100
$self->option_value_prompt($name) // ()
l!l&&r!l&&!r
010490
MC/DC0%0/2
$parsed_options->{$name} // ()
$parsed_options->{$name} ()
MC/DC0%0/2
$default // ()
$default ()
MC/DC0%0/2
$self->option_value_prompt($name) // ()
$self->option_value_prompt($name) ()
Truth table33%1/3
A // B
A= $parsed_options->{$name}B= ()
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $defaultB= ()
ABresult
1X1
011
000
Truth table33%1/3
A // B
A= $self->option_value_prompt($name)B= ()
ABresult
1X1
011
000
1639 : $default ? ref $default eq 'ARRAY' ? $default
1640 : [$default // ()]
1641 : [$self->option_value_prompt($name) // ()];
1642  
1643 1093 my $type = 'string';
1644  
1645 1093 ▶ $type = 'boolean' if $option->{type} eq 'boolean';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "boolean" 731 362 1093
1646 1093 ▶ $type = 'float' if $option->{type} eq 'float';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "float" 0 1093 1093
1647 1093 ▶ $type = 'number' if $option->{type} eq 'number';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "number" 1 1092 1093
1648 1093 ▶ $type = 'string' if $option->{type} eq 'string';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "string" 361 732 1093
1649 1093 ▶ $type = 'yesno' if $option->{type} eq 'yesno';
Branch: 1 branch
BranchTrueFalseTotal
if $option->{"type"} eq "yesno" 0 1093 1093
1650  
1651 1093 require Scalar::Util;
1652  
1653 1093 ▶ if ($type eq 'number') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "number") 1 1092 1093
1654 1 ▶ @{$value} = map +(Scalar::Util::looks_like_number($_) ? (0+$_) : $_), @{$value};
Branch: 1 branch
BranchTrueFalseTotal
&Scalar::Util::looks_like_number($_) ? : 0 1 1
1655 }
1656  
1657 1093 ▶ if ($type eq 'boolean') {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq "boolean") 731 362 1093
1658 731 @{$value} = map +(Scalar::Util::looks_like_number($_) ? !!$_ ? true : false
1659 731 ▶ : $_ =~ /true/i ? true : false), @{$value};
Branch: 3 branches
BranchTrueFalseTotal
&Scalar::Util::looks_like_number($_) ? : 18 0 18
!!$_ ? : 18 0 18
$_ =~ /true/iu ? : 0 0 0
1660 }
1661  
1662 1093 my $multiples = $option->{multiples};
1663  
1664 1093 ▶ return $multiples ? (wantarray ? (@{$value}) : $value) : $value->[0];
Branch: 2 branches
BranchTrueFalseTotal
$multiples ? : 248 845 1093
wantarray ? : 29 219 248
1665 }
1666  
1667 1049 ▶sub option_value_prompt {
Subroutine option_value_prompt: called CC=5 SCAR=20.3
Pod undocumented
1668 1049 my ($self, $name) = @_;
1669  
1670 1049 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 1049 1049
1671  
1672 1049 my $option = $self->option($name);
1673  
1674 1049 ▶ return undef if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 1049 1049
1675  
1676 1049 my $prompt = $option->{prompt};
1677  
1678 1049 ▶ return undef if !$prompt;
Branch: 1 branch
BranchTrueFalseTotal
unless $prompt 1049 0 1049
1679  
1680 0 _print($prompt);
1681  
1682 0 my $captured = _prompt;
1683  
1684 0 ▶ return $captured eq '' ? undef : $captured;
Branch: 1 branch
BranchTrueFalseTotal
$captured eq '' ? : 0 0 0
1685 }
1686  
1687 2 ▶sub option_wants {
Subroutine option_wants: called CC=3 SCAR=11.0
Pod documented
1688 2 my ($self, $name) = @_;
1689  
1690 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
1691  
1692 1 my $option = $self->option($name);
1693  
1694 1 ▶ return '' if !$option;
Branch: 1 branch
BranchTrueFalseTotal
unless $option 0 1 1
1695  
1696 1 my $wants = $option->{wants};
1697  
1698 1 return $wants;
1699 }
1700  
1701 3 ▶sub optional {
Subroutine optional: called CC=4 SCAR=13.9
Pod documented
1702 3 my ($self, $next, @args) = @_;
1703  
1704 3 my $data = {required => false};
1705  
1706 3 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 2 3
1707  
1708 3 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 1 3
1709  
1710 1 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
1711  
1712 1 push @args, $data;
1713  
1714 1 return $self->$next(@args);
1715 }
1716  
1717 2 ▶sub opts {
Subroutine opts: called CC=3 SCAR=11.0
Pod documented
1718 2 my ($self) = @_;
1719  
1720 2 my $parsed_options = $self->parsed_options;
1721  
1722 2 ▶ $self->parse if !$parsed_options || !keys %{$parsed_options};
Branch: 1 branch
BranchTrueFalseTotal
unless $parsed_options and keys %{$parsed_options;} 1 1 2
Condition66%2/3
$parsed_options and keys %{$parsed_options;}
!ll&&!rl&&r
011
MC/DC50%1/2
$parsed_options and keys %{$parsed_options;}
$parsed_options keys %{$parsed_options;}
Truth table66%2/3
A and B
A= $parsed_optionsB= keys %{$parsed_options;}
ABresult
0X0
100
111
1723  
1724 2 $parsed_options = $self->parsed_options;
1725  
1726 2 require Venus::Opts;
1727  
1728 2 return Venus::Opts->new(value => [], parsed => $parsed_options);
1729 }
1730  
1731 81 ▶sub output {
Subroutine output: called CC=3 SCAR=11.0
Pod documented
1732 81 my ($self, $level) = @_;
1733  
1734 81 my $output = [];
1735  
1736 81 my $log_events = $self->log_events;
1737  
1738 81 ▶ push @{$output}, map {$$_[1]} ($level ? (grep {$$_[0] eq $level} @{$log_events}) : (@{$log_events}));
Branch: 1 branch
BranchTrueFalseTotal
$level ? : 63 18 81
1739  
1740 81 ▶ return wantarray ? (@{$output}) : (@{$output})[-1];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 69 12 81
1741 }
1742  
1743 4 ▶sub output_debug_events {
Subroutine output_debug_events: called CC=2 SCAR=6.9
Pod documented
1744 4 my ($self) = @_;
1745  
1746 4 my $output = [$self->output('debug')];
1747  
1748 4 ▶ return wantarray ? (@{$output}) : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
1749 }
1750  
1751 11 ▶sub output_error_events {
Subroutine output_error_events: called CC=2 SCAR=6.9
Pod documented
1752 11 my ($self) = @_;
1753  
1754 11 my $output = [$self->output('error')];
1755  
1756 11 ▶ return wantarray ? (@{$output}) : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 10 11
1757 }
1758  
1759 4 ▶sub output_fatal_events {
Subroutine output_fatal_events: called CC=2 SCAR=6.9
Pod documented
1760 4 my ($self) = @_;
1761  
1762 4 my $output = [$self->output('fatal')];
1763  
1764 4 ▶ return wantarray ? (@{$output}) : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
1765 }
1766  
1767 5 ▶sub output_info_events {
Subroutine output_info_events: called CC=2 SCAR=6.9
Pod documented
1768 5 my ($self) = @_;
1769  
1770 5 my $output = [$self->output('info')];
1771  
1772 5 ▶ return wantarray ? (@{$output}) : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 4 5
1773 }
1774  
1775 4 ▶sub output_trace_events {
Subroutine output_trace_events: called CC=2 SCAR=6.9
Pod documented
1776 4 my ($self) = @_;
1777  
1778 4 my $output = [$self->output('trace')];
1779  
1780 4 ▶ return wantarray ? (@{$output}) : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
1781 }
1782  
1783 4 ▶sub output_warn_events {
Subroutine output_warn_events: called CC=2 SCAR=6.9
Pod documented
1784 4 my ($self) = @_;
1785  
1786 4 my $output = [$self->output('warn')];
1787  
1788 4 ▶ return wantarray ? (@{$output}) : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 3 4
1789 }
1790  
1791 136 ▶sub parse {
Subroutine parse: called CC=2 SCAR=6.9
Pod documented
1792 136 my ($self, @args) = @_;
1793  
1794 136 require Venus;
1795 136 require Getopt::Long;
1796 136 require Text::ParseWords;
1797  
1798 136 ▶ my $data = [@args ? @args : @ARGV];
Branch: 1 branch
BranchTrueFalseTotal
@args ? : 90 46 136
1799  
1800 136 $self->data($data);
1801  
1802 136 my $arguments = [map $_, @{$data}];
1803  
1804 136 Getopt::Long::Configure(qw(default bundling no_auto_abbrev no_ignore_case));
1805  
1806 136 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: called CC=1 SCAR=0.0
1807  
1808 136 my $options = {};
1809  
1810 136 my $returned = Getopt::Long::GetOptionsFromArray($arguments, $options, $self->parse_specification);
1811  
1812 136 $self->parsed_arguments($arguments);
1813 136 $self->parsed_options($options);
1814  
1815 136 return $self;
1816 }
1817  
1818 136 ▶sub parse_specification {
Subroutine parse_specification: called CC=11 SCAR=24.4
Pod undocumented
1819 136 my ($self) = @_;
1820  
1821 136 my $spec = [];
1822  
1823 136 for my $option ($self->option_list) {
1824 814 my $spec_string = $option->{name};
1825  
1826 814 ▶ if ($option->{aliases}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($option->{"aliases"}) 814 0 814
1827 814 $spec_string = join '|', $spec_string, @{$option->{aliases}};
1828 }
1829  
1830 my $type
1831 = $option->{type} eq 'boolean' ? ''
1832 : $option->{type} eq 'float' ? 'f'
1833 : $option->{type} eq 'number' ? 'i'
1834 : $option->{type} eq 'yesno' ? 's'
1835 814 ▶ : $option->{type} eq 'string' ? 's'
Branch: 5 branches
BranchTrueFalseTotal
$option->{'type'} eq 'boolean' ? : 510 304 814
$option->{'type'} eq 'float' ? : 0 304 304
$option->{'type'} eq 'number' ? : 1 303 304
$option->{'type'} eq 'yesno' ? : 0 303 303
$option->{'type'} eq 'string' ? : 303 0 303
1836 : '';
1837  
1838 814 ▶ $spec_string .= $type ? "=$type" : '';
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 304 510 814
1839  
1840 814 ▶ $spec_string .= $option->{multiples} ? '@' : '';
Branch: 1 branch
BranchTrueFalseTotal
$option->{'multiples'} ? : 167 647 814
1841  
1842 814 push @{$spec}, $spec_string;
1843 }
1844  
1845 136 ▶ return wantarray ? (@{$spec}) : $spec;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 136 0 136
1846 }
1847  
1848 29 ▶sub parsed {
Subroutine parsed: called CC=2 SCAR=6.9
Pod documented
1849 29 my ($self) = @_;
1850  
1851 29 ▶ return wantarray ? ($self->parsed_options, $self->parsed_arguments) : $self->parsed_options;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 19 10 29
1852 }
1853  
1854 262 ▶sub parsed_arguments {
Subroutine parsed_arguments: called CC=3 SCAR=11.0
Pod documented
1855 262 my ($self, @args) = @_;
1856  
1857 262 ▶ $self->{parsed_arguments} = $args[0] if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 138 124 262
1858  
1859 262 ▶ $self->parse if !$self->{parsed_arguments};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parsed_arguments"} 18 244 262
1860  
1861 262 return $self->{parsed_arguments};
1862 }
1863  
1864 1270 ▶sub parsed_options {
Subroutine parsed_options: called CC=3 SCAR=11.0
Pod documented
1865 1270 my ($self, @args) = @_;
1866  
1867 1270 ▶ $self->{parsed_options} = $args[0] if @args;
Branch: 1 branch
BranchTrueFalseTotal
if @args 138 1132 1270
1868  
1869 1270 ▶ $self->parse if !$self->{parsed_options};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"parsed_options"} 24 1246 1270
1870  
1871 1270 return $self->{parsed_options};
1872 }
1873  
1874 12 ▶sub pass {
Subroutine pass: called CC=1 SCAR=0.0
Pod documented
1875 12 my ($self, $method, @args) = @_;
1876  
1877 12 return $self->exit(0, $method, @args);
1878 }
1879  
1880 551 ▶sub reorder {
Subroutine reorder: called CC=1 SCAR=0.0
Pod documented
1881 551 my ($self) = @_;
1882  
1883 551 $self->reorder_arguments;
1884 551 $self->reorder_choices;
1885 551 $self->reorder_options;
1886 551 $self->reorder_routes;
1887  
1888 551 return $self;
1889 }
1890  
1891 552 ▶sub reorder_arguments {
Subroutine reorder_arguments: called CC=2 SCAR=6.9
Pod documented
1892 552 my ($self) = @_;
1893  
1894 552 my $arguments = $self->arguments;
1895  
1896 552 my $index = 0;
1897  
1898 552 $self->argument($_, {%{$arguments->{$_}}, index => $index++}) for $self->argument_names;
1899  
1900 552 return $self;
1901 }
1902  
1903 552 ▶sub reorder_choices {
Subroutine reorder_choices: called CC=2 SCAR=6.9
Pod documented
1904 552 my ($self) = @_;
1905  
1906 552 my $choices = $self->choices;
1907  
1908 552 my $index = 0;
1909  
1910 552 $self->choice($_, {%{$choices->{$_}}, index => $index++}) for $self->choice_names;
1911  
1912 552 return $self;
1913 }
1914  
1915 552 ▶sub reorder_options {
Subroutine reorder_options: called CC=2 SCAR=6.9
Pod documented
1916 552 my ($self) = @_;
1917  
1918 552 my $options = $self->options;
1919  
1920 552 my $index = 0;
1921  
1922 552 $self->option($_, {%{$options->{$_}}, index => $index++}) for $self->option_names;
1923  
1924 552 return $self;
1925 }
1926  
1927 552 ▶sub reorder_routes {
Subroutine reorder_routes: called CC=2 SCAR=6.9
Pod documented
1928 552 my ($self) = @_;
1929  
1930 552 my $routes = $self->routes;
1931  
1932 552 my $index = 0;
1933  
1934 552 $self->route($_, {%{$routes->{$_}}, index => $index++}) for $self->route_names;
1935  
1936 552 return $self;
1937 }
1938  
1939 190 ▶sub route {
Subroutine route: called CC=5 SCAR=16.2
Pod documented
1940 190 my ($self, $name, @data) = @_;
1941  
1942 190 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 190 190
1943  
1944 190 ▶ return $self->routes->{$name} if !@data;
Branch: 1 branch
BranchTrueFalseTotal
unless @data 70 120 190
1945  
1946 120 ▶ return delete $self->routes->{$name} if !defined $data[0];
Branch: 1 branch
BranchTrueFalseTotal
unless defined $data[0] 1 119 120
1947  
1948 my $defaults = {
1949 name => $name,
1950 label => undef,
1951 help => undef,
1952 argument => undef,
1953 choice => undef,
1954 handler => undef,
1955 range => undef,
1956 119 index => int(keys(%{$self->routes})),
1957 };
1958  
1959 119 require Venus;
1960  
1961 119 my $overrides = Venus::merge_take({}, @data);
1962  
1963 119 ▶ my $data = Venus::merge_take($self->routes->{$name} || $defaults, $overrides);
Condition66%2/3
$self->routes->{$name} || $defaults
l!l&&r!l&&!r
42770
MC/DC0%0/2
$self->routes->{$name} || $defaults
$self->routes->{$name} $defaults
Truth table66%2/3
A || B
A= $self->routes->{$name}B= $defaults
ABresult
1X1
011
000
1964  
1965 119 return $self->routes->{$name} = $data;
1966 }
1967  
1968 2 ▶sub route_argument {
Subroutine route_argument: called CC=3 SCAR=11.0
Pod documented
1969 2 my ($self, $name) = @_;
1970  
1971 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
1972  
1973 1 my $route = $self->route($name);
1974  
1975 1 ▶ return '' if !$route;
Branch: 1 branch
BranchTrueFalseTotal
unless $route 0 1 1
1976  
1977 1 my $argument = $route->{argument};
1978  
1979 1 return $self->argument($argument);
1980 }
1981  
1982 2 ▶sub route_choice {
Subroutine route_choice: called CC=3 SCAR=11.0
Pod documented
1983 2 my ($self, $name) = @_;
1984  
1985 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
1986  
1987 1 my $route = $self->route($name);
1988  
1989 1 ▶ return '' if !$route;
Branch: 1 branch
BranchTrueFalseTotal
unless $route 0 1 1
1990  
1991 1 my $choice = $route->{choice};
1992  
1993 1 return $self->choice($choice);
1994 }
1995  
1996 4 ▶sub route_count {
Subroutine route_count: called CC=1 SCAR=0.0
Pod documented
1997 4 my ($self) = @_;
1998  
1999 4 return int(scalar(keys(%{$self->routes})));
2000 }
2001  
2002 3 ▶sub route_handler {
Subroutine route_handler: called CC=3 SCAR=11.0
Pod documented
2003 3 my ($self, $name) = @_;
2004  
2005 3 ▶ return undef if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 2 3
2006  
2007 2 my $route = $self->route($name);
2008  
2009 2 ▶ return undef if !$route;
Branch: 1 branch
BranchTrueFalseTotal
unless $route 0 2 2
2010  
2011 2 my $handler = $route->{handler};
2012  
2013 2 return $handler;
2014 }
2015  
2016 2 ▶sub route_help {
Subroutine route_help: called CC=3 SCAR=11.0
Pod documented
2017 2 my ($self, $name) = @_;
2018  
2019 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
2020  
2021 1 my $route = $self->route($name);
2022  
2023 1 ▶ return '' if !$route;
Branch: 1 branch
BranchTrueFalseTotal
unless $route 0 1 1
2024  
2025 1 my $help = $route->{help};
2026  
2027 1 return $help;
2028 }
2029  
2030 2 ▶sub route_label {
Subroutine route_label: called CC=3 SCAR=11.0
Pod documented
2031 2 my ($self, $name) = @_;
2032  
2033 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
2034  
2035 1 my $route = $self->route($name);
2036  
2037 1 ▶ return '' if !$route;
Branch: 1 branch
BranchTrueFalseTotal
unless $route 0 1 1
2038  
2039 1 my $label = $route->{label};
2040  
2041 1 return $label;
2042 }
2043  
2044 18 ▶sub route_list {
Subroutine route_list: called CC=2 SCAR=6.9
Pod documented
2045 18 my ($self) = @_;
2046  
2047 18 my $output = [];
2048  
2049 18 my $routes = $self->routes;
2050  
2051 18 $output = [map $routes->{$_}, $self->route_names];
2052  
2053 18 ▶ return wantarray ? @{$output} : $output;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 16 2 18
2054 }
2055  
2056 2 ▶sub route_name {
Subroutine route_name: called CC=3 SCAR=11.0
Pod documented
2057 2 my ($self, $name) = @_;
2058  
2059 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
2060  
2061 1 my $route = $self->route($name);
2062  
2063 1 ▶ return '' if !$route;
Branch: 1 branch
BranchTrueFalseTotal
unless $route 0 1 1
2064  
2065 1 $name = $route->{name};
2066  
2067 1 return $name;
2068 }
2069  
2070 572 ▶sub route_names {
Subroutine route_names: called CC=4 SCAR=14.0
Pod documented
2071 572 my ($self) = @_;
2072  
2073 572 my $routes = $self->routes;
2074  
2075 my @names = sort {
2076 (exists $routes->{$a}->{index} ? $routes->{$a}->{index} : $a)
2077 125 ▶ <=> (exists $routes->{$b}->{index} ? $routes->{$b}->{index} : $b)
Branch: 2 branches
BranchTrueFalseTotal
exists $routes->{$a}{'index'} ? : 125 0 125
exists $routes->{$b}{'index'} ? : 125 0 125
2078 572 } keys %{$routes};
2079  
2080 572 ▶ return wantarray ? (@names) : [@names];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 570 2 572
2081 }
2082  
2083 2 ▶sub route_range {
Subroutine route_range: called CC=3 SCAR=11.0
Pod documented
2084 2 my ($self, $name) = @_;
2085  
2086 2 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 1 2
2087  
2088 1 my $route = $self->route($name);
2089  
2090 1 ▶ return '' if !$route;
Branch: 1 branch
BranchTrueFalseTotal
unless $route 0 1 1
2091  
2092 1 my $range = $route->{range};
2093  
2094 1 return $range;
2095 }
2096  
2097 3 ▶sub required {
Subroutine required: called CC=4 SCAR=13.9
Pod documented
2098 3 my ($self, $next, @args) = @_;
2099  
2100 3 my $data = {required => true};
2101  
2102 3 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 2 3
2103  
2104 3 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 1 3
2105  
2106 1 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
2107  
2108 1 push @args, $data;
2109  
2110 1 return $self->$next(@args);
2111 }
2112  
2113 2 ▶sub reset {
Subroutine reset: called CC=1 SCAR=0.0
Pod documented
2114 2 my ($self) = @_;
2115  
2116 2 $self->data([]);
2117 2 $self->arguments({});
2118 2 $self->options({});
2119 2 $self->choices({});
2120 2 $self->routes({});
2121 2 $self->parsed_arguments([]);
2122 2 $self->parsed_options({});
2123  
2124 2 $self->{logs} = [];
2125  
2126 2 delete $self->{input_arguments};
2127 2 delete $self->{input_options};
2128  
2129 2 return $self;
2130 }
2131  
2132 3 ▶sub single {
Subroutine single: called CC=4 SCAR=13.9
Pod documented
2133 3 my ($self, $next, @args) = @_;
2134  
2135 3 my $data = {multiples => false};
2136  
2137 3 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 2 3
2138  
2139 3 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 1 3
2140  
2141 1 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
2142  
2143 1 push @args, $data;
2144  
2145 1 return $self->$next(@args);
2146 }
2147  
2148 14 ▶sub spec {
Subroutine spec: called CC=40 SCAR=40.2
Pod documented
2149 14 my ($self, $data) = @_;
2150  
2151 14 ▶ return $self if !$data || ref $data ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not $data or ref $data ne "HASH" 1 13 14
Condition66%2/3
not $data or ref $data ne "HASH"
l!l&&r!l&&!r
1013
MC/DC50%1/2
not $data or ref $data ne "HASH"
not $data ref $data ne "HASH"
Truth table66%2/3
not(A) or B
A= not $dataB= ref $data ne "HASH"
ABresult
1X1
011
000
2152  
2153 13 ▶ $self->name($data->{name}) if exists $data->{name};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"name"} 6 7 13
2154 13 ▶ $self->version($data->{version}) if exists $data->{version};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"version"} 2 11 13
2155 13 ▶ $self->summary($data->{summary}) if exists $data->{summary};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"summary"} 2 11 13
2156 13 ▶ $self->description($data->{description}) if exists $data->{description};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"description"} 1 12 13
2157 13 ▶ $self->header($data->{header}) if exists $data->{header};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"header"} 1 12 13
2158 13 ▶ $self->footer($data->{footer}) if exists $data->{footer};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data->{"footer"} 8 5 13
2159  
2160 13 ▶ if ($data->{arguments} && ref $data->{arguments} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"arguments"} and ref $data->{"arguments"} eq "ARRAY") 9 4 13
Condition66%2/3
$data->{"arguments"} and ref $data->{"arguments"} eq "ARRAY"
!ll&&!rl&&r
409
MC/DC50%1/2
$data->{"arguments"} and ref $data->{"arguments"} eq "ARRAY"
$data->{"arguments"} ref $data->{"arguments"} eq "ARRAY"
Truth table66%2/3
A and B
A= $data->{"arguments"}B= ref $data->{"arguments"} eq "ARRAY"
ABresult
0X0
100
111
2161 9 for my $item (@{$data->{arguments}}) {
2162 16 ▶ next if !$item || ref $item ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not $item or ref $item ne "HASH" 0 16 16
Condition33%1/3
not $item or ref $item ne "HASH"
l!l&&r!l&&!r
0016
MC/DC0%0/2
not $item or ref $item ne "HASH"
not $item ref $item ne "HASH"
Truth table33%1/3
not(A) or B
A= not $itemB= ref $item ne "HASH"
ABresult
1X1
011
000
2163 16 my $name = $item->{name};
2164 16 ▶ next if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 16 16
2165 16 $self->argument($name, $item);
2166 }
2167 }
2168  
2169 13 ▶ if ($data->{options} && ref $data->{options} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"options"} and ref $data->{"options"} eq "ARRAY") 2 11 13
Condition66%2/3
$data->{"options"} and ref $data->{"options"} eq "ARRAY"
!ll&&!rl&&r
1102
MC/DC50%1/2
$data->{"options"} and ref $data->{"options"} eq "ARRAY"
$data->{"options"} ref $data->{"options"} eq "ARRAY"
Truth table66%2/3
A and B
A= $data->{"options"}B= ref $data->{"options"} eq "ARRAY"
ABresult
0X0
100
111
2170 2 for my $item (@{$data->{options}}) {
2171 3 ▶ next if !$item || ref $item ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not $item or ref $item ne "HASH" 0 3 3
Condition33%1/3
not $item or ref $item ne "HASH"
l!l&&r!l&&!r
003
MC/DC0%0/2
not $item or ref $item ne "HASH"
not $item ref $item ne "HASH"
Truth table33%1/3
not(A) or B
A= not $itemB= ref $item ne "HASH"
ABresult
1X1
011
000
2172 3 my $name = $item->{name};
2173 3 ▶ next if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 3 3
2174 3 $self->option($name, $item);
2175 }
2176 }
2177  
2178 13 ▶ if ($data->{choices} && ref $data->{choices} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"choices"} and ref $data->{"choices"} eq "ARRAY") 8 5 13
Condition66%2/3
$data->{"choices"} and ref $data->{"choices"} eq "ARRAY"
!ll&&!rl&&r
508
MC/DC50%1/2
$data->{"choices"} and ref $data->{"choices"} eq "ARRAY"
$data->{"choices"} ref $data->{"choices"} eq "ARRAY"
Truth table66%2/3
A and B
A= $data->{"choices"}B= ref $data->{"choices"} eq "ARRAY"
ABresult
0X0
100
111
2179 8 for my $item (@{$data->{choices}}) {
2180 37 ▶ next if !$item || ref $item ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not $item or ref $item ne "HASH" 0 37 37
Condition33%1/3
not $item or ref $item ne "HASH"
l!l&&r!l&&!r
0037
MC/DC0%0/2
not $item or ref $item ne "HASH"
not $item ref $item ne "HASH"
Truth table33%1/3
not(A) or B
A= not $itemB= ref $item ne "HASH"
ABresult
1X1
011
000
2181 37 my $name = $item->{name};
2182 37 ▶ next if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 37 37
2183 37 $self->choice($name, $item);
2184 }
2185 }
2186  
2187 13 ▶ if ($data->{routes} && ref $data->{routes} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"routes"} and ref $data->{"routes"} eq "ARRAY") 1 12 13
Condition66%2/3
$data->{"routes"} and ref $data->{"routes"} eq "ARRAY"
!ll&&!rl&&r
1201
MC/DC50%1/2
$data->{"routes"} and ref $data->{"routes"} eq "ARRAY"
$data->{"routes"} ref $data->{"routes"} eq "ARRAY"
Truth table66%2/3
A and B
A= $data->{"routes"}B= ref $data->{"routes"} eq "ARRAY"
ABresult
0X0
100
111
2188 1 for my $item (@{$data->{routes}}) {
2189 2 ▶ next if !$item || ref $item ne 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if not $item or ref $item ne "HASH" 0 2 2
Condition33%1/3
not $item or ref $item ne "HASH"
l!l&&r!l&&!r
002
MC/DC0%0/2
not $item or ref $item ne "HASH"
not $item ref $item ne "HASH"
Truth table33%1/3
not(A) or B
A= not $itemB= ref $item ne "HASH"
ABresult
1X1
011
000
2190 2 my $name = $item->{name};
2191 2 ▶ next if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 0 2 2
2192 2 $self->route($name, $item);
2193 }
2194 }
2195  
2196 13 ▶ if ($data->{commands} && ref $data->{commands} eq 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if ($data->{"commands"} and ref $data->{"commands"} eq "ARRAY") 9 4 13
Condition66%2/3
$data->{"commands"} and ref $data->{"commands"} eq "ARRAY"
!ll&&!rl&&r
409
MC/DC50%1/2
$data->{"commands"} and ref $data->{"commands"} eq "ARRAY"
$data->{"commands"} ref $data->{"commands"} eq "ARRAY"
Truth table66%2/3
A and B
A= $data->{"commands"}B= ref $data->{"commands"} eq "ARRAY"
ABresult
0X0
100
111
2197 9 for my $item (@{$data->{commands}}) {
2198 38 ▶ next if !$item || ref $item ne 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
if not $item or ref $item ne "ARRAY" 0 38 38
Condition33%1/3
not $item or ref $item ne "ARRAY"
l!l&&r!l&&!r
0038
MC/DC0%0/2
not $item or ref $item ne "ARRAY"
not $item ref $item ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not $itemB= ref $item ne "ARRAY"
ABresult
1X1
011
000
2199 38 my @parts = @{$item};
2200 38 ▶ next if @parts < 3;
Branch: 1 branch
BranchTrueFalseTotal
if @parts < 3 0 38 38
2201 38 my $argument = shift @parts;
2202 38 my $handler = pop @parts;
2203 0 ▶ my $choice = [map {split /\s+/} map {ref $_ ? @{$_} : $_} @parts];
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 0 40 40
2204 38 $self->command($argument, $choice, $handler);
2205 }
2206 }
2207  
2208 13 $self->reorder;
2209  
2210 13 return $self;
2211 }
2212  
2213 3 ▶sub string {
Subroutine string: called CC=4 SCAR=13.9
Pod documented
2214 3 my ($self, $next, @args) = @_;
2215  
2216 3 my $data = {type => 'string'};
2217  
2218 3 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 2 3
2219  
2220 3 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 1 3
2221  
2222 1 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
2223  
2224 1 push @args, $data;
2225  
2226 1 return $self->$next(@args);
2227 }
2228  
2229 23 ▶sub usage {
Subroutine usage: called CC=9 SCAR=22.0
Pod documented
2230 23 my ($self) = @_;
2231  
2232 23 my @value;
2233  
2234 my @output;
2235  
2236 23 @value = grep length, $self->usage_gist;
2237  
2238 23 ▶ push @output, join " ", @value if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 8 15 23
2239  
2240 23 @value = grep length, $self->usage_line;
2241  
2242 23 ▶ push @output, join " ", @value if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 23 0 23
2243  
2244 23 @value = grep length, $self->usage_description;
2245  
2246 23 ▶ push @output, $self->lines(join " ", @value) if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 0 23 23
2247  
2248 23 @value = grep length, $self->usage_header;
2249  
2250 23 ▶ push @output, $self->lines(join " ", @value) if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 0 23 23
2251  
2252 23 @value = grep length, $self->usage_arguments;
2253  
2254 23 ▶ push @output, join " ", @value if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 15 8 23
2255  
2256 23 @value = grep length, $self->usage_options;
2257  
2258 23 ▶ push @output, join " ", @value if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 11 12 23
2259  
2260 23 @value = grep length, $self->usage_choices;
2261  
2262 23 ▶ push @output, join " ", @value if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 4 19 23
2263  
2264 23 @value = grep length, $self->usage_footer;
2265  
2266 23 ▶ push @output, $self->lines(join " ", @value) if @value;
Branch: 1 branch
BranchTrueFalseTotal
if @value 1 22 23
2267  
2268 23 return join "\n\n", @output;
2269 }
2270  
2271 30 ▶sub usage_argument_default {
Subroutine usage_argument_default: called CC=4 SCAR=13.9
Pod documented
2272 30 my ($self, $name) = @_;
2273  
2274 30 my $output = '';
2275  
2276 30 my $default = $self->argument_default($name);
2277  
2278 30 ▶ return $output if !defined $default || !length $default;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $default and length $default 24 6 30
Condition100%3/3
defined $default and length $default
!ll&&!rl&&r
2316
MC/DC100%2/2
defined $default and length $default
defined $default length $default
Truth table100%3/3
A and B
A= defined $defaultB= length $default
ABresult
0X0
100
111
2279  
2280 $output = 'Default: ' . join ', ',
2281 6 ▶ ref $default ? @{$default} : $default;
Branch: 1 branch
BranchTrueFalseTotal
ref $default ? : 1 5 6
2282  
2283 6 return $output;
2284 }
2285  
2286 29 ▶sub usage_argument_help {
Subroutine usage_argument_help: called CC=2 SCAR=6.9
Pod documented
2287 29 my ($self, $name) = @_;
2288  
2289 29 my $output = '';
2290  
2291 29 my $help = $self->argument_help($name);
2292  
2293 29 ▶ return $output if !$help;
Branch: 1 branch
BranchTrueFalseTotal
unless $help 1 28 29
2294  
2295 28 return $help;
2296 }
2297  
2298 61 ▶sub usage_argument_label {
Subroutine usage_argument_label: called CC=6 SCAR=18.0
Pod documented
2299 61 my ($self, $name) = @_;
2300  
2301 61 my $output = '';
2302  
2303 61 my $arg = $self->argument($name);
2304  
2305 61 ▶ return $output if !$arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg 1 60 61
2306  
2307 60 ▶ return $arg->{label} if $arg->{label};
Branch: 1 branch
BranchTrueFalseTotal
if $arg->{"label"} 3 57 60
2308  
2309 57 ▶ if ($arg->{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'required'}) { } 12 45 57
2310 12 ▶ if ($arg->{multiples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'multiples'}) { } 0 12 12
2311 0 $output = "<$arg->{name}> ...";
2312 }
2313 else {
2314 12 $output = "<$arg->{name}>";
2315 }
2316 }
2317 else {
2318 45 ▶ if ($arg->{multiples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'multiples'}) { } 7 38 45
2319 7 $output = "[<$arg->{name}> ...]";
2320 }
2321 else {
2322 38 $output = "[<$arg->{name}>]";
2323 }
2324 }
2325  
2326 57 return $output;
2327 }
2328  
2329 30 ▶sub usage_argument_required {
Subroutine usage_argument_required: called CC=2 SCAR=6.9
Pod documented
2330 30 my ($self, $name) = @_;
2331  
2332 30 my $required = $self->argument_required($name);
2333  
2334 30 ▶ return $required ? '(required)' : '(optional)';
Branch: 1 branch
BranchTrueFalseTotal
$required ? : 5 25 30
2335 }
2336  
2337 35 ▶sub usage_argument_token {
Subroutine usage_argument_token: called CC=5 SCAR=16.1
Pod documented
2338 35 my ($self, $name) = @_;
2339  
2340 35 my $output = '';
2341  
2342 35 my $arg = $self->argument($name);
2343  
2344 35 ▶ return $output if !$arg;
Branch: 1 branch
BranchTrueFalseTotal
unless $arg 1 34 35
2345  
2346 34 ▶ if ($arg->{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'required'}) { } 7 27 34
2347 7 ▶ if ($arg->{multiples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'multiples'}) { } 1 6 7
2348 1 $output = "<$arg->{name}> ...";
2349 }
2350 else {
2351 6 $output = "<$arg->{name}>";
2352 }
2353 }
2354 else {
2355 27 ▶ if ($arg->{multiples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg->{'multiples'}) { } 9 18 27
2356 9 $output = "[<$arg->{name}> ...]";
2357 }
2358 else {
2359 18 $output = "[<$arg->{name}>]";
2360 }
2361 }
2362  
2363 34 return $output;
2364 }
2365  
2366 25 ▶sub usage_arguments {
Subroutine usage_arguments: called CC=3 SCAR=11.0
Pod documented
2367 25 my ($self) = @_;
2368  
2369 25 my @value;
2370  
2371 25 ▶ if ($self->argument_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->argument_count > 0) 17 8 25
2372 17 push @value, "Arguments:";
2373 17 for my $name ($self->argument_names) {
2374 27 push @value, grep length,
2375 $self->lines($self->usage_argument_label($name), 80, 2);
2376 27 push @value, grep length,
2377 $self->lines($self->usage_argument_help($name), 80, 4);
2378 27 push @value, grep length,
2379 $self->lines($self->usage_argument_required($name), 80, 4);
2380 27 push @value, grep length,
2381 $self->lines($self->usage_argument_default($name), 80, 4);
2382 }
2383 }
2384  
2385 25 return join "\n", @value;
2386 }
2387  
2388 24 ▶sub usage_choice_help {
Subroutine usage_choice_help: called CC=1 SCAR=0.0
Pod documented
2389 24 my ($self, $name) = @_;
2390  
2391 24 return $self->choice_help($name);
2392 }
2393  
2394 24 ▶sub usage_choice_label {
Subroutine usage_choice_label: called CC=4 SCAR=14.1
Pod documented
2395 24 my ($self, $name) = @_;
2396  
2397 24 my $cmd = $self->choice($name);
2398  
2399 24 ▶ return '' if !$cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 1 23 24
2400  
2401 23 ▶ return $cmd->{label} || $cmd->{name} || '';
Condition60%3/5
$cmd->{'label'} || $cmd->{'name'} || ''
l!l
230
$cmd->{"label"} or $cmd->{"name"}
l!l&&r!l&&!r
1220
MC/DC0%0/2
$cmd->{'label'} || $cmd->{'name'} || ''
$cmd->{"label"} $cmd->{"name"}
Truth table66%2/3
A or B
A= $cmd->{"label"}B= $cmd->{"name"}
ABresult
1X1
011
000
2402 }
2403  
2404 24 ▶sub usage_choice_required {
Subroutine usage_choice_required: called CC=2 SCAR=6.9
Pod documented
2405 24 my ($self, $name) = @_;
2406  
2407 24 my $output = '';
2408  
2409 24 my $cmd = $self->choice($name);
2410  
2411 24 ▶ return $output if !$cmd;
Branch: 1 branch
BranchTrueFalseTotal
unless $cmd 1 23 24
2412  
2413 23 return $self->usage_argument_label($cmd->{argument});
2414 }
2415  
2416 25 ▶sub usage_choices {
Subroutine usage_choices: called CC=5 SCAR=16.1
Pod documented
2417 25 my ($self) = @_;
2418  
2419 25 my @value;
2420  
2421 25 ▶ if ($self->choice_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->choice_count > 0) 6 19 25
2422 6 my %cmd_groups;
2423 6 for my $name ($self->choice_names) {
2424 21 push @{$cmd_groups{$self->choice($name)->{argument}}}, $name;
2425 }
2426 6 for my $group (grep $cmd_groups{$_}, $self->argument_names) {
2427 9 my @group = "Choices for " . ($self->usage_argument_label($group)) . ":";
2428 9 for my $name (@{$cmd_groups{$group}}) {
2429 21 push @group, grep length,
2430 $self->lines($self->usage_choice_label($name), 80, 2);
2431 21 push @group, grep length,
2432 $self->lines($self->usage_choice_help($name), 80, 4);
2433 21 push @group, grep length,
2434 $self->lines($self->usage_choice_required($name), 80, 4);
2435 }
2436 9 push @value, join "\n", @group;
2437 }
2438 }
2439  
2440 25 return join "\n\n", @value;
2441 }
2442  
2443 24 ▶sub usage_description {
Subroutine usage_description: called CC=2 SCAR=6.9
Pod documented
2444 24 my ($self) = @_;
2445  
2446 24 ▶ my $description = $self->description // '';
Condition100%2/2
$self->description // ""
l!l
123
MC/DC100%1/1
$self->description // ""
$self->description
Truth table100%2/2
A
A= $self->description
Aresult
11
00
2447  
2448 24 return $description;
2449 }
2450  
2451 24 ▶sub usage_footer {
Subroutine usage_footer: called CC=2 SCAR=6.9
Pod documented
2452 24 my ($self) = @_;
2453  
2454 24 ▶ my $footer = $self->footer // '';
Condition100%2/2
$self->footer // ""
l!l
222
MC/DC100%1/1
$self->footer // ""
$self->footer
Truth table100%2/2
A
A= $self->footer
Aresult
11
00
2455  
2456 24 return $footer;
2457 }
2458  
2459 27 ▶sub usage_gist {
Subroutine usage_gist: called CC=8 SCAR=20.8
Pod documented
2460 27 my ($self) = @_;
2461  
2462 27 my $name = $self->usage_name;
2463  
2464 27 my $version = $self->usage_version;
2465  
2466 27 my $summary = $self->usage_summary;
2467  
2468 27 ▶ return '' if !$name;
Branch: 1 branch
BranchTrueFalseTotal
unless $name 1 26 27
2469  
2470 26 ▶ return "$name - $summary" if $summary && !$version;
Branch: 1 branch
BranchTrueFalseTotal
if $summary and not $version 2 24 26
Condition100%3/3
$summary and not $version
!ll&&!rl&&r
1682
MC/DC100%2/2
$summary and not $version
$summary not $version
Truth table100%3/3
A and not(B)
A= $summaryB= not $version
ABresult
0X0
100
111
2471  
2472 24 ▶ return "$name version $version" if !$summary && $version;
Branch: 1 branch
BranchTrueFalseTotal
if not $summary and $version 1 23 24
Condition100%3/3
not $summary and $version
!ll&&!rl&&r
8151
MC/DC100%2/2
not $summary and $version
not $summary $version
Truth table100%3/3
not(A) and B
A= not $summaryB= $version
ABresult
0X0
100
111
2473  
2474 23 ▶ return "$name version $version - $summary" if $summary && $version;
Branch: 1 branch
BranchTrueFalseTotal
if $summary and $version 8 15 23
Condition66%2/3
$summary and $version
!ll&&!rl&&r
1508
MC/DC50%1/2
$summary and $version
$summary $version
Truth table66%2/3
A and B
A= $summaryB= $version
ABresult
0X0
100
111
2475  
2476 15 return '';
2477 }
2478  
2479 24 ▶sub usage_header {
Subroutine usage_header: called CC=2 SCAR=6.9
Pod documented
2480 24 my ($self) = @_;
2481  
2482 24 ▶ my $header = $self->header // '';
Condition100%2/2
$self->header // ""
l!l
123
MC/DC100%1/1
$self->header // ""
$self->header
Truth table100%2/2
A
A= $self->header
Aresult
11
00
2483  
2484 24 return $header;
2485 }
2486  
2487 28 ▶sub usage_line {
Subroutine usage_line: called CC=6 SCAR=18.1
Pod documented
2488 28 my ($self) = @_;
2489  
2490 28 my @lines;
2491  
2492 28 my $width = 80;
2493  
2494 28 my @name = $self->usage_name;
2495  
2496 28 ▶ return '' if !@name;
Branch: 1 branch
BranchTrueFalseTotal
unless @name 0 28 28
2497  
2498 28 my $line = my $usage = join ' ', 'Usage:', @name;
2499  
2500 28 my $indent = length($usage) + 1;
2501  
2502 28 for my $name ($self->argument_names) {
2503 30 my $part = $self->usage_argument_token($name);
2504 30 ▶ if (length($line) + length($part) + 1 > $width) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($line) + length($part) + 1 > $width) { } 0 30 30
2505 0 push @lines, $line;
2506 0 $line = (" " x $indent) . $part;
2507 }
2508 else {
2509 30 $line .= " $part";
2510 }
2511 }
2512  
2513 28 for my $name ($self->option_names) {
2514 28 my $part = $self->usage_option_token($name);
2515 28 ▶ if (length($line) + length($part) + 1 > $width) {
Branch: 1 branch
BranchTrueFalseTotal
if (length($line) + length($part) + 1 > $width) { } 1 27 28
2516 1 push @lines, $line;
2517 1 $line = (" " x $indent) . $part;
2518 }
2519 else {
2520 27 $line .= " $part";
2521 }
2522 }
2523  
2524 28 return join "\n", @lines, $line;
2525 }
2526  
2527 57 ▶sub usage_name {
Subroutine usage_name: called CC=2 SCAR=6.9
Pod documented
2528 57 my ($self) = @_;
2529  
2530 57 ▶ my $name = $self->name // '';
Condition100%2/2
$self->name // ""
l!l
543
MC/DC100%1/1
$self->name // ""
$self->name
Truth table100%2/2
A
A= $self->name
Aresult
11
00
2531  
2532 57 return $name;
2533 }
2534  
2535 35 ▶sub usage_option_default {
Subroutine usage_option_default: called CC=4 SCAR=13.9
Pod documented
2536 35 my ($self, $name) = @_;
2537  
2538 35 my $output = '';
2539  
2540 35 my $default = $self->option_default($name);
2541  
2542 35 ▶ return $output if !defined $default || !length $default;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $default and length $default 31 4 35
Condition100%3/3
defined $default and length $default
!ll&&!rl&&r
3014
MC/DC100%2/2
defined $default and length $default
defined $default length $default
Truth table100%3/3
A and B
A= defined $defaultB= length $default
ABresult
0X0
100
111
2543  
2544 $output = 'Default: ' . join ', ',
2545 4 ▶ ref $default ? @{$default} : $default;
Branch: 1 branch
BranchTrueFalseTotal
ref $default ? : 1 3 4
2546  
2547 4 return $output;
2548 }
2549  
2550 34 ▶sub usage_option_help {
Subroutine usage_option_help: called CC=1 SCAR=0.0
Pod documented
2551 34 my ($self, $name) = @_;
2552  
2553 34 return $self->option_help($name);
2554 }
2555  
2556 42 ▶sub usage_option_label {
Subroutine usage_option_label: called CC=24 SCAR=34.9
Pod documented
2557 42 my ($self, $name) = @_;
2558  
2559 42 my $output = '';
2560  
2561 42 my $opt = $self->option($name);
2562  
2563 42 ▶ return $output if !$opt;
Branch: 1 branch
BranchTrueFalseTotal
unless $opt 1 41 42
2564  
2565 41 ▶ return $opt->{label} if $opt->{label};
Branch: 1 branch
BranchTrueFalseTotal
if $opt->{"label"} 0 41 41
2566  
2567 $output = join ', ', map length($_) > 1 ? "--$_" : "-$_", grep length,
2568 41 ▶ ref $opt->{aliases} ? @{$opt->{aliases}} : $opt->{aliases};
Branch: 2 branches
BranchTrueFalseTotal
length $_ > 1 ? : 2 12 14
ref $opt->{'aliases'} ? : 41 0 41
2569  
2570 41 ▶ if ($opt->{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'required'}) { } 8 33 41
2571 8 ▶ if ($opt->{multiples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'multiples'}) { } 5 3 8
2572 5 ▶ if ($opt->{wants} && ($opt->{wants} ne 'boolean')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'wants'} and $opt->{'wants'} ne 'boolean') { } 5 0 5
Condition33%1/3
$opt->{"wants"} and $opt->{"wants"} ne "boolean"
!ll&&!rl&&r
005
MC/DC0%0/2
$opt->{"wants"} and $opt->{"wants"} ne "boolean"
$opt->{"wants"} $opt->{"wants"} ne "boolean"
Truth table33%1/3
A and B
A= $opt->{"wants"}B= $opt->{"wants"} ne "boolean"
ABresult
0X0
100
111
2573 5 ▶ $output = join ', ', ($output ? $output : ()), "--$opt->{name}=<$opt->{wants}> ...";
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 2 3 5
2574 }
2575 else {
2576 0 ▶ $output = join ', ', ($output ? $output : ()), "--$opt->{name} ...";
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 0 0 0
2577 }
2578 }
2579 else {
2580 3 ▶ if ($opt->{wants} && ($opt->{wants} ne 'boolean')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'wants'} and $opt->{'wants'} ne 'boolean') { } 3 0 3
Condition33%1/3
$opt->{"wants"} and $opt->{"wants"} ne "boolean"
!ll&&!rl&&r
003
MC/DC0%0/2
$opt->{"wants"} and $opt->{"wants"} ne "boolean"
$opt->{"wants"} $opt->{"wants"} ne "boolean"
Truth table33%1/3
A and B
A= $opt->{"wants"}B= $opt->{"wants"} ne "boolean"
ABresult
0X0
100
111
2581 3 ▶ $output = join ', ', ($output ? $output : ()), "--$opt->{name}=<$opt->{wants}>";
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 0 3 3
2582 }
2583 else {
2584 0 ▶ $output = join ', ', ($output ? $output : ()), "--$opt->{name}";
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 0 0 0
2585 }
2586 }
2587 }
2588 else {
2589 33 ▶ if ($opt->{multiples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'multiples'}) { } 8 25 33
2590 8 ▶ if ($opt->{wants} && ($opt->{wants} ne 'boolean')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'wants'} and $opt->{'wants'} ne 'boolean') { } 7 1 8
Condition66%2/3
$opt->{"wants"} and $opt->{"wants"} ne "boolean"
!ll&&!rl&&r
107
MC/DC50%1/2
$opt->{"wants"} and $opt->{"wants"} ne "boolean"
$opt->{"wants"} $opt->{"wants"} ne "boolean"
Truth table66%2/3
A and B
A= $opt->{"wants"}B= $opt->{"wants"} ne "boolean"
ABresult
0X0
100
111
2591 7 ▶ $output = sprintf '[%s]',
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 2 5 7
2592 join ', ', ($output ? $output : ()), "--$opt->{name}=<$opt->{wants}> ...";
2593 }
2594 else {
2595 1 ▶ $output = sprintf '[%s]',
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 0 1 1
2596 join ', ', ($output ? $output : ()), "--$opt->{name} ...";
2597 }
2598 }
2599 else {
2600 25 ▶ if ($opt->{wants} && ($opt->{wants} ne 'boolean')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'wants'} and $opt->{'wants'} ne 'boolean') { } 11 14 25
Condition66%2/3
$opt->{"wants"} and $opt->{"wants"} ne "boolean"
!ll&&!rl&&r
01411
MC/DC50%1/2
$opt->{"wants"} and $opt->{"wants"} ne "boolean"
$opt->{"wants"} $opt->{"wants"} ne "boolean"
Truth table66%2/3
A and B
A= $opt->{"wants"}B= $opt->{"wants"} ne "boolean"
ABresult
0X0
100
111
2601 11 ▶ $output = sprintf '[%s]',
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 2 9 11
2602 join ', ', ($output ? $output : ()), "--$opt->{name}=<$opt->{wants}>";
2603 }
2604 else {
2605 14 ▶ $output = sprintf '[%s]',
Branch: 1 branch
BranchTrueFalseTotal
$output ? : 8 6 14
2606 join ', ', ($output ? $output : ()), "--$opt->{name}";
2607 }
2608 }
2609 }
2610  
2611 41 return $output;
2612 }
2613  
2614 35 ▶sub usage_option_required {
Subroutine usage_option_required: called CC=2 SCAR=6.9
Pod documented
2615 35 my ($self, $name) = @_;
2616  
2617 35 my $required = $self->option_required($name);
2618  
2619 35 ▶ return $required ? '(required)' : '(optional)';
Branch: 1 branch
BranchTrueFalseTotal
$required ? : 5 30 35
2620 }
2621  
2622 33 ▶sub usage_option_token {
Subroutine usage_option_token: called CC=5 SCAR=16.1
Pod documented
2623 33 my ($self, $name) = @_;
2624  
2625 33 my $output = '';
2626  
2627 33 my $opt = $self->option($name);
2628  
2629 33 ▶ return $output if !$opt;
Branch: 1 branch
BranchTrueFalseTotal
unless $opt 1 32 33
2630  
2631 32 ▶ if ($opt->{required}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'required'}) { } 4 28 32
2632 4 ▶ if ($opt->{multiples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'multiples'}) { } 3 1 4
2633 3 $output = "--$opt->{name} ...";
2634 }
2635 else {
2636 1 $output = "--$opt->{name}";
2637 }
2638 }
2639 else {
2640 28 ▶ if ($opt->{multiples}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'multiples'}) { } 5 23 28
2641 5 $output = "[--$opt->{name} ...]";
2642 }
2643 else {
2644 23 $output = "[--$opt->{name}]";
2645 }
2646 }
2647  
2648 32 return $output;
2649 }
2650  
2651 25 ▶sub usage_options {
Subroutine usage_options: called CC=3 SCAR=11.0
Pod documented
2652 25 my ($self) = @_;
2653  
2654 25 my @value;
2655  
2656 25 ▶ if ($self->option_count > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->option_count > 0) 13 12 25
2657 13 push @value, "Options:";
2658 13 for my $name ($self->option_names) {
2659 32 push @value, grep length,
2660 $self->lines($self->usage_option_label($name), 80, 2);
2661 32 push @value, grep length,
2662 $self->lines($self->usage_option_help($name), 80, 4);
2663 32 push @value, grep length,
2664 $self->lines($self->usage_option_required($name), 80, 4);
2665 32 push @value, grep length,
2666 $self->lines($self->usage_option_default($name), 80, 4);
2667 }
2668 }
2669  
2670 25 return join "\n", @value;
2671 }
2672  
2673 28 ▶sub usage_summary {
Subroutine usage_summary: called CC=1 SCAR=0.0
Pod documented
2674 28 my ($self) = @_;
2675  
2676 28 my $summary = $self->summary;
2677  
2678 28 return $summary;
2679 }
2680  
2681 28 ▶sub usage_version {
Subroutine usage_version: called CC=1 SCAR=0.0
Pod documented
2682 28 my ($self) = @_;
2683  
2684 28 my $version = $self->version;
2685  
2686 28 return $version;
2687 }
2688  
2689 1 ▶sub vars {
Subroutine vars: called CC=1 SCAR=0.0
Pod documented
2690 1 my ($self) = @_;
2691  
2692 1 require Venus::Vars;
2693  
2694 1 return Venus::Vars->new;
2695 }
2696  
2697 3 ▶sub yesno {
Subroutine yesno: called CC=4 SCAR=13.9
Pod documented
2698 3 my ($self, $next, @args) = @_;
2699  
2700 3 my $data = {type => 'yesno'};
2701  
2702 3 ▶ $data = {%{pop(@args)}, %{$data}} if ref $args[$#args] eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
if ref $args[$#args] eq "HASH" 1 2 3
2703  
2704 3 ▶ return $data if !$next;
Branch: 1 branch
BranchTrueFalseTotal
unless $next 2 1 3
2705  
2706 1 ▶ return $self->$next(undef, $data) if !@args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 0 1 1
2707  
2708 1 push @args, $data;
2709  
2710 1 return $self->$next(@args);
2711 }
2712  
2713 9 1;
2714  
2715  
2716  
2717 =head1 NAME
2718  
2719 Venus::Cli - Cli Class
2720  
2721 =cut
2722  
2723 =head1 ABSTRACT
2724  
2725 Cli Class for Perl 5
2726  
2727 =cut
2728  
2729 =head1 SYNOPSIS
2730  
2731 package main;
2732  
2733 use Venus::Cli;
2734  
2735 my $cli = Venus::Cli->new(name => 'mycli');
2736  
2737 # $cli->usage;
2738  
2739 # ...
2740  
2741 # $cli->parsed;
2742  
2743 # {help => 1}
2744  
2745 =cut
2746  
2747 =head1 DESCRIPTION
2748  
2749 This package provides a superclass and methods for creating simple yet robust
2750 command-line interfaces.
2751  
2752 =cut
2753  
2754 =head1 ATTRIBUTES
2755  
2756 This package has the following attributes:
2757  
2758 =cut
2759  
2760 =head2 name
2761  
2762 name(string $name) (string)
2763  
2764 The name attribute is read-write, accepts C<(string)> values, and is optional.
2765  
2766 I<Since C<4.15>>
2767  
2768 =over 4
2769  
2770 =item name example 1
2771  
2772 # given: synopsis
2773  
2774 package main;
2775  
2776 my $name = $cli->name("mycli");
2777  
2778 # "mycli"
2779  
2780 =back
2781  
2782 =over 4
2783  
2784 =item name example 2
2785  
2786 # given: synopsis
2787  
2788 # given: example-1 name
2789  
2790 package main;
2791  
2792 $name = $cli->name;
2793  
2794 # "mycli"
2795  
2796 =back
2797  
2798 =cut
2799  
2800 =head2 version
2801  
2802 version(string $version) (string)
2803  
2804 The version attribute is read-write, accepts C<(string)> values, and is
2805 optional.
2806  
2807 I<Since C<4.15>>
2808  
2809 =over 4
2810  
2811 =item version example 1
2812  
2813 # given: synopsis
2814  
2815 package main;
2816  
2817 my $version = $cli->version("0.0.1");
2818  
2819 # "0.0.1"
2820  
2821 =back
2822  
2823 =over 4
2824  
2825 =item version example 2
2826  
2827 # given: synopsis
2828  
2829 # given: example-1 version
2830  
2831 package main;
2832  
2833 $version = $cli->version;
2834  
2835 # "0.0.1"
2836  
2837 =back
2838  
2839 =cut
2840  
2841 =head2 summary
2842  
2843 summary(string $summary) (string)
2844  
2845 The summary attribute is read-write, accepts C<(string)> values, and is
2846 optional.
2847  
2848 I<Since C<4.15>>
2849  
2850 =over 4
2851  
2852 =item summary example 1
2853  
2854 # given: synopsis
2855  
2856 package main;
2857  
2858 my $summary = $cli->summary("Example summary");
2859  
2860 # "Example summary"
2861  
2862 =back
2863  
2864 =over 4
2865  
2866 =item summary example 2
2867  
2868 # given: synopsis
2869  
2870 # given: example-1 summary
2871  
2872 package main;
2873  
2874 $summary = $cli->summary;
2875  
2876 # "Example summary"
2877  
2878 =back
2879  
2880 =cut
2881  
2882 =head2 description
2883  
2884 description(string $description) (string)
2885  
2886 The description attribute is read-write, accepts C<(string)> values, and is
2887 optional.
2888  
2889 I<Since C<4.15>>
2890  
2891 =over 4
2892  
2893 =item description example 1
2894  
2895 # given: synopsis
2896  
2897 package main;
2898  
2899 my $description = $cli->description("Example description");
2900  
2901 # "Example description"
2902  
2903 =back
2904  
2905 =over 4
2906  
2907 =item description example 2
2908  
2909 # given: synopsis
2910  
2911 # given: example-1 description
2912  
2913 package main;
2914  
2915 $description = $cli->description;
2916  
2917 # "Example description"
2918  
2919 =back
2920  
2921 =cut
2922  
2923 =head2 header
2924  
2925 header(string $header) (string)
2926  
2927 The header attribute is read-write, accepts C<(string)> values, and is
2928 optional.
2929  
2930 I<Since C<4.15>>
2931  
2932 =over 4
2933  
2934 =item header example 1
2935  
2936 # given: synopsis
2937  
2938 package main;
2939  
2940 my $header = $cli->header("Example header");
2941  
2942 # "Example header"
2943  
2944 =back
2945  
2946 =over 4
2947  
2948 =item header example 2
2949  
2950 # given: synopsis
2951  
2952 # given: example-1 header
2953  
2954 package main;
2955  
2956 $header = $cli->header;
2957  
2958 # "Example header"
2959  
2960 =back
2961  
2962 =cut
2963  
2964 =head2 footer
2965  
2966 footer(string $footer) (string)
2967  
2968 The footer attribute is read-write, accepts C<(string)> values, and is
2969 optional.
2970  
2971 I<Since C<4.15>>
2972  
2973 =over 4
2974  
2975 =item footer example 1
2976  
2977 # given: synopsis
2978  
2979 package main;
2980  
2981 my $footer = $cli->footer("Example footer");
2982  
2983 # "Example footer"
2984  
2985 =back
2986  
2987 =over 4
2988  
2989 =item footer example 2
2990  
2991 # given: synopsis
2992  
2993 # given: example-1 footer
2994  
2995 package main;
2996  
2997 $footer = $cli->footer;
2998  
2999 # "Example footer"
3000  
3001 =back
3002  
3003 =cut
3004  
3005 =head2 arguments
3006  
3007 arguments(hashref $arguments) (hashref)
3008  
3009 The arguments attribute is read-write, accepts C<(hashref)> values, and is
3010 optional.
3011  
3012 I<Since C<4.15>>
3013  
3014 =over 4
3015  
3016 =item arguments example 1
3017  
3018 # given: synopsis
3019  
3020 package main;
3021  
3022 my $arguments = $cli->arguments({});
3023  
3024 # {}
3025  
3026 =back
3027  
3028 =over 4
3029  
3030 =item arguments example 2
3031  
3032 # given: synopsis
3033  
3034 # given: example-1 arguments
3035  
3036 package main;
3037  
3038 $arguments = $cli->arguments;
3039  
3040 # {}
3041  
3042 =back
3043  
3044 =cut
3045  
3046 =head2 options
3047  
3048 options(hashref $options) (hashref)
3049  
3050 The options attribute is read-write, accepts C<(hashref)> values, and is
3051 optional.
3052  
3053 I<Since C<4.15>>
3054  
3055 =over 4
3056  
3057 =item options example 1
3058  
3059 # given: synopsis
3060  
3061 package main;
3062  
3063 my $options = $cli->options({});
3064  
3065 # {}
3066  
3067 =back
3068  
3069 =over 4
3070  
3071 =item options example 2
3072  
3073 # given: synopsis
3074  
3075 # given: example-1 options
3076  
3077 package main;
3078  
3079 $options = $cli->options;
3080  
3081 # {}
3082  
3083 =back
3084  
3085 =cut
3086  
3087 =head2 choices
3088  
3089 choices(hashref $choices) (hashref)
3090  
3091 The choices attribute is read-write, accepts C<(hashref)> values, and is
3092 optional.
3093  
3094 I<Since C<4.15>>
3095  
3096 =over 4
3097  
3098 =item choices example 1
3099  
3100 # given: synopsis
3101  
3102 package main;
3103  
3104 my $choices = $cli->choices({});
3105  
3106 # {}
3107  
3108 =back
3109  
3110 =over 4
3111  
3112 =item choices example 2
3113  
3114 # given: synopsis
3115  
3116 # given: example-1 choices
3117  
3118 package main;
3119  
3120 $choices = $cli->choices;
3121  
3122 # {}
3123  
3124 =back
3125  
3126 =cut
3127  
3128 =head2 data
3129  
3130 data(hashref $data) (hashref)
3131  
3132 The data attribute is read-write, accepts C<(hashref)> values, and is
3133 optional.
3134  
3135 I<Since C<4.15>>
3136  
3137 =over 4
3138  
3139 =item data example 1
3140  
3141 # given: synopsis
3142  
3143 package main;
3144  
3145 my $data = $cli->data({});
3146  
3147 # {}
3148  
3149 =back
3150  
3151 =over 4
3152  
3153 =item data example 2
3154  
3155 # given: synopsis
3156  
3157 # given: example-1 data
3158  
3159 package main;
3160  
3161 $data = $cli->data;
3162  
3163 # {}
3164  
3165 =back
3166  
3167 =cut
3168  
3169 =head1 INHERITS
3170  
3171 This package inherits behaviors from:
3172  
3173 L<Venus::Kind::Utility>
3174  
3175 =cut
3176  
3177 =head1 INTEGRATES
3178  
3179 This package integrates behaviors from:
3180  
3181 L<Venus::Role::Printable>
3182  
3183 =cut
3184  
3185 =head1 METHODS
3186  
3187 This package provides the following methods:
3188  
3189 =cut
3190  
3191 =head2 args
3192  
3193 args() (Venus::Args)
3194  
3195 The args method returns the list of parsed command-line arguments as a
3196 L<Venus::Args> object.
3197  
3198 I<Since C<4.15>>
3199  
3200 =over 4
3201  
3202 =item args example 1
3203  
3204 # given: synopsis
3205  
3206 package main;
3207  
3208 my $args = $cli->args;
3209  
3210 # bless(..., "Venus::Args")
3211  
3212 =back
3213  
3214 =over 4
3215  
3216 =item args example 2
3217  
3218 # given: synopsis
3219  
3220 package main;
3221  
3222 $cli->parse('hello', 'world');
3223  
3224 my $args = $cli->args;
3225  
3226 # bless(..., "Venus::Args")
3227  
3228 # $args->get(0);
3229  
3230 # $args->get(1);
3231  
3232 =back
3233  
3234 =cut
3235  
3236 =head2 argument
3237  
3238 argument(string $name, hashref $data) (maybe[hashref])
3239  
3240 The argument method registers and returns the configuration for the argument
3241 specified. The method takes a name (argument name) and a hashref of
3242 configuration values. The possible configuration values are as follows:
3243  
3244 =over 4
3245  
3246 =item *
3247  
3248 The C<name> key holds the name of the argument.
3249  
3250 =item *
3251  
3252 The C<label> key holds the name of the argument as it should be displayed in
3253 the CLI help text.
3254  
3255 =item *
3256  
3257 The C<help> key holds the help text specific to this argument.
3258  
3259 =item *
3260  
3261 The C<default> key holds the default value that should used if no value for
3262 this argument is provided to the CLI.
3263  
3264 =item *
3265  
3266 The C<multiples> key denotes whether this argument can be used more than once,
3267 to collect multiple values, and holds a C<1> if multiples are allowed and a C<0>
3268 otherwise.
3269  
3270 =item *
3271  
3272 The C<prompt> key holds the question or statement that should be presented to
3273 the user of the CLI if no value has been provided for this argument and no
3274 default value has been set.
3275  
3276 =item *
3277  
3278 The C<range> key holds a two-value arrayref where the first value is the
3279 starting index and the second value is the ending index. These values are used
3280 to select values from the parsed arguments array as the value(s) for this
3281 argument. This value is ignored if the C<multiples> key is set to C<0>.
3282  
3283 =item *
3284  
3285 The C<required> key denotes whether this argument is required or not, and holds
3286 a C<1> if required and a C<0> otherwise.
3287  
3288 =item *
3289  
3290 The C<type> key holds the data type of the argument expected. Valid values are
3291 "number", "string", "float", "boolean", or "yesno". B<Note:> Valid boolean
3292 values are C<1>, C<0>, C<"true">, and C<"false">.
3293  
3294 =back
3295  
3296 I<Since C<4.15>>
3297  
3298 =over 4
3299  
3300 =item argument example 1
3301  
3302 # given: synopsis
3303  
3304 package main;
3305  
3306 my $argument = $cli->argument('name', {
3307 label => 'Name',
3308 help => 'The name of the user',
3309 default => 'Unknown',
3310 required => 1,
3311 type => 'string'
3312 });
3313  
3314 # {
3315 # name => 'name',
3316 # label => 'Name',
3317 # help => 'The name of the user',
3318 # default => 'Unknown',
3319 # multiples => 0,
3320 # prompt => undef,
3321 # range => undef,
3322 # required => 1,
3323 # type => 'string',
3324 # index => 0,
3325 # wants => 'string',
3326 # }
3327  
3328 =back
3329  
3330 =cut
3331  
3332 =head2 argument_choice
3333  
3334 argument_choice(string $name) (arrayref)
3335  
3336 The argument_choice method returns the parsed argument value only if it
3337 corresponds to a registered choice associated with the named argument. If the
3338 value (or any of the values) doesn't map to a choice, this method will return
3339 an empty arrayref. Returns a list in list context.
3340  
3341 I<Since C<4.15>>
3342  
3343 =over 4
3344  
3345 =item argument_choice example 1
3346  
3347 package main;
3348  
3349 use Venus::Cli;
3350  
3351 my $cli = Venus::Cli->new(name => 'mycli');
3352  
3353 my $argument_choice = $cli->argument_choice;
3354  
3355 # []
3356  
3357 =back
3358  
3359 =over 4
3360  
3361 =item argument_choice example 2
3362  
3363 package main;
3364  
3365 use Venus::Cli;
3366  
3367 my $cli = Venus::Cli->new(name => 'mycli');
3368  
3369 $cli->argument('input', {
3370 range => '0',
3371 type => 'string',
3372 });
3373  
3374 $cli->parse('stdin');
3375  
3376 my $argument_choice = $cli->argument_choice('input');
3377  
3378 # []
3379  
3380 =back
3381  
3382 =over 4
3383  
3384 =item argument_choice example 3
3385  
3386 package main;
3387  
3388 use Venus::Cli;
3389  
3390 my $cli = Venus::Cli->new(name => 'mycli');
3391  
3392 $cli->argument('input', {
3393 range => '0',
3394 type => 'string',
3395 });
3396  
3397 $cli->choice('stdin', {
3398 argument => 'input',
3399 });
3400  
3401 $cli->choice('stdout', {
3402 argument => 'input',
3403 });
3404  
3405 $cli->parse('stdin');
3406  
3407 my $argument_choice = $cli->argument_choice('input');
3408  
3409 # ['stdin']
3410  
3411 =back
3412  
3413 =over 4
3414  
3415 =item argument_choice example 4
3416  
3417 package main;
3418  
3419 use Venus::Cli;
3420  
3421 my $cli = Venus::Cli->new(name => 'mycli');
3422  
3423 $cli->argument('input', {
3424 multiples => true,
3425 range => '0:',
3426 type => 'string',
3427 });
3428  
3429 $cli->choice('stdin', {
3430 argument => 'input',
3431 });
3432  
3433 $cli->choice('stdout', {
3434 argument => 'input',
3435 });
3436  
3437 $cli->parse('stdin', 'stdout');
3438  
3439 my $argument_choice = $cli->argument_choice('input');
3440  
3441 # ['stdin', 'stdout']
3442  
3443 =back
3444  
3445 =cut
3446  
3447 =head2 argument_choices
3448  
3449 argument_choices(string $name) (arrayref)
3450  
3451 The argument_choices method returns all registered choices associated with
3452 the argument named. Returns a list in list context.
3453  
3454 I<Since C<4.15>>
3455  
3456 =over 4
3457  
3458 =item argument_choices example 1
3459  
3460 package main;
3461  
3462 use Venus::Cli;
3463  
3464 my $cli = Venus::Cli->new(name => 'mycli');
3465  
3466 my $argument_choices = $cli->argument_choices;
3467  
3468 # []
3469  
3470 =back
3471  
3472 =over 4
3473  
3474 =item argument_choices example 2
3475  
3476 package main;
3477  
3478 use Venus::Cli;
3479  
3480 my $cli = Venus::Cli->new(name => 'mycli');
3481  
3482 $cli->argument('input', {
3483 type => 'string',
3484 });
3485  
3486 my $argument_choices = $cli->argument_choices('input');
3487  
3488 # []
3489  
3490 =back
3491  
3492 =over 4
3493  
3494 =item argument_choices example 3
3495  
3496 package main;
3497  
3498 use Venus::Cli;
3499  
3500 my $cli = Venus::Cli->new(name => 'mycli');
3501  
3502 $cli->argument('input', {
3503 type => 'string',
3504 });
3505  
3506 $cli->choice('stdin', {
3507 argument => 'input',
3508 });
3509  
3510 my $argument_choices = $cli->argument_choices('input');
3511  
3512 # [{
3513 # name => 'stdin',
3514 # label => undef,
3515 # help => 'Expects a string value',
3516 # argument => 'input',
3517 # index => 0,
3518 # wants => 'string',
3519 # }]
3520  
3521 =back
3522  
3523 =cut
3524  
3525 =head2 argument_count
3526  
3527 argument_count() (number)
3528  
3529 The argument_count method returns the count of registered arguments.
3530  
3531 I<Since C<4.15>>
3532  
3533 =over 4
3534  
3535 =item argument_count example 1
3536  
3537 package main;
3538  
3539 use Venus::Cli;
3540  
3541 my $cli = Venus::Cli->new(name => 'mycli');
3542  
3543 my $argument_count = $cli->argument_count;
3544  
3545 # 0
3546  
3547 =back
3548  
3549 =over 4
3550  
3551 =item argument_count example 2
3552  
3553 package main;
3554  
3555 use Venus::Cli;
3556  
3557 my $cli = Venus::Cli->new(name => 'mycli');
3558  
3559 $cli->argument('input', {
3560 type => 'string',
3561 });
3562  
3563 $cli->argument('output', {
3564 type => 'string',
3565 });
3566  
3567 my $argument_count = $cli->argument_count;
3568  
3569 # 2
3570  
3571 =back
3572  
3573 =cut
3574  
3575 =head2 argument_default
3576  
3577 argument_default(string $name) (string)
3578  
3579 The argument_default method returns the C<default> configuration value for the
3580 named argument.
3581  
3582 I<Since C<4.15>>
3583  
3584 =over 4
3585  
3586 =item argument_default example 1
3587  
3588 package main;
3589  
3590 use Venus::Cli;
3591  
3592 my $cli = Venus::Cli->new(name => 'mycli');
3593  
3594 my $argument_default = $cli->argument_default;
3595  
3596 # ""
3597  
3598 =back
3599  
3600 =over 4
3601  
3602 =item argument_default example 2
3603  
3604 package main;
3605  
3606 use Venus::Cli;
3607  
3608 my $cli = Venus::Cli->new(name => 'mycli');
3609  
3610 $cli->argument('input', {
3611 default => 'stdin',
3612 });
3613  
3614 my $argument_default = $cli->argument_default('input');
3615  
3616 # "stdin"
3617  
3618 =back
3619  
3620 =cut
3621  
3622 =head2 argument_errors
3623  
3624 argument_errors(string $name) (within[arrayref, Venus::Validate])
3625  
3626 The argument_errors method returns a list of L<"issues"|Venus::Validate/issue>,
3627 if any, for each value returned by L</argument_value> for the named argument.
3628 Returns a list in list context.
3629  
3630 I<Since C<4.15>>
3631  
3632 =over 4
3633  
3634 =item argument_errors example 1
3635  
3636 package main;
3637  
3638 use Venus::Cli;
3639  
3640 my $cli = Venus::Cli->new(name => 'mycli');
3641  
3642 my $argument_errors = $cli->argument_errors;
3643  
3644 # []
3645  
3646 =back
3647  
3648 =over 4
3649  
3650 =item argument_errors example 2
3651  
3652 package main;
3653  
3654 use Venus::Cli;
3655  
3656 my $cli = Venus::Cli->new(name => 'mycli');
3657  
3658 $cli->argument('input', {
3659 range => '0',
3660 type => 'string',
3661 });
3662  
3663 $cli->parse('hello');
3664  
3665 my $argument_errors = $cli->argument_errors('input');
3666  
3667 # []
3668  
3669 =back
3670  
3671 =over 4
3672  
3673 =item argument_errors example 3
3674  
3675 package main;
3676  
3677 use Venus::Cli;
3678  
3679 my $cli = Venus::Cli->new(name => 'mycli');
3680  
3681 $cli->argument('input', {
3682 range => '0',
3683 type => 'number',
3684 });
3685  
3686 $cli->parse('hello');
3687  
3688 my $argument_errors = $cli->argument_errors('input');
3689  
3690 # [['type', ['number']]]
3691  
3692 =back
3693  
3694 =cut
3695  
3696 =head2 argument_help
3697  
3698 argument_help(string $name) (string)
3699  
3700 The argument_help method returns the C<help> configuration value for the named
3701 argument.
3702  
3703 I<Since C<4.15>>
3704  
3705 =over 4
3706  
3707 =item argument_help example 1
3708  
3709 package main;
3710  
3711 use Venus::Cli;
3712  
3713 my $cli = Venus::Cli->new(name => 'mycli');
3714  
3715 my $argument_help = $cli->argument_help;
3716  
3717 # ""
3718  
3719 =back
3720  
3721 =over 4
3722  
3723 =item argument_help example 2
3724  
3725 package main;
3726  
3727 use Venus::Cli;
3728  
3729 my $cli = Venus::Cli->new(name => 'mycli');
3730  
3731 $cli->argument('input', {
3732 help => 'Example help text',
3733 });
3734  
3735 my $argument_help = $cli->argument_help('input');
3736  
3737 # "Example help text"
3738  
3739 =back
3740  
3741 =cut
3742  
3743 =head2 argument_label
3744  
3745 argument_label(string $name) (string)
3746  
3747 The argument_label method returns the C<label> configuration value for the
3748 named argument.
3749  
3750 I<Since C<4.15>>
3751  
3752 =over 4
3753  
3754 =item argument_label example 1
3755  
3756 package main;
3757  
3758 use Venus::Cli;
3759  
3760 my $cli = Venus::Cli->new(name => 'mycli');
3761  
3762 my $argument_label = $cli->argument_label;
3763  
3764 # ""
3765  
3766 =back
3767  
3768 =over 4
3769  
3770 =item argument_label example 2
3771  
3772 package main;
3773  
3774 use Venus::Cli;
3775  
3776 my $cli = Venus::Cli->new(name => 'mycli');
3777  
3778 $cli->argument('input', {
3779 label => 'Input',
3780 });
3781  
3782 my $argument_label = $cli->argument_label('input');
3783  
3784 # "Input"
3785  
3786 =back
3787  
3788 =cut
3789  
3790 =head2 argument_list
3791  
3792 argument_list(string $name) (within[arrayref, hashref])
3793  
3794 The argument_list method returns a list of registered argument configurations.
3795 Returns a list in list context.
3796  
3797 I<Since C<4.15>>
3798  
3799 =over 4
3800  
3801 =item argument_list example 1
3802  
3803 package main;
3804  
3805 use Venus::Cli;
3806  
3807 my $cli = Venus::Cli->new(name => 'mycli');
3808  
3809 my $argument_list = $cli->argument_list;
3810  
3811 # []
3812  
3813 =back
3814  
3815 =over 4
3816  
3817 =item argument_list example 2
3818  
3819 package main;
3820  
3821 use Venus::Cli;
3822  
3823 my $cli = Venus::Cli->new(name => 'mycli');
3824  
3825 $cli->argument('input', {
3826 type => 'string',
3827 });
3828  
3829 my $argument_list = $cli->argument_list;
3830  
3831 # [{
3832 # name => 'input',
3833 # label => undef,
3834 # help => 'Expects a string value',
3835 # default => undef,
3836 # multiples => 0,
3837 # prompt => undef,
3838 # range => undef,
3839 # required => false,
3840 # type => 'string',
3841 # index => 0,
3842 # wants => 'string',
3843 # }]
3844  
3845 =back
3846  
3847 =cut
3848  
3849 =head2 argument_multiples
3850  
3851 argument_multiples(string $name) (boolean)
3852  
3853 The argument_multiples method returns the C<multiples> configuration value for
3854 the named argument.
3855  
3856 I<Since C<4.15>>
3857  
3858 =over 4
3859  
3860 =item argument_multiples example 1
3861  
3862 package main;
3863  
3864 use Venus::Cli;
3865  
3866 my $cli = Venus::Cli->new(name => 'mycli');
3867  
3868 my $argument_multiples = $cli->argument_multiples;
3869  
3870 # false
3871  
3872 =back
3873  
3874 =over 4
3875  
3876 =item argument_multiples example 2
3877  
3878 package main;
3879  
3880 use Venus::Cli;
3881  
3882 my $cli = Venus::Cli->new(name => 'mycli');
3883  
3884 $cli->argument('input', {
3885 multiples => true,
3886 });
3887  
3888 my $argument_multiples = $cli->argument_multiples('input');
3889  
3890 # true
3891  
3892 =back
3893  
3894 =cut
3895  
3896 =head2 argument_name
3897  
3898 argument_name(string $name) (string)
3899  
3900 The argument_name method returns the C<name> configuration value for the named
3901 argument.
3902  
3903 I<Since C<4.15>>
3904  
3905 =over 4
3906  
3907 =item argument_name example 1
3908  
3909 package main;
3910  
3911 use Venus::Cli;
3912  
3913 my $cli = Venus::Cli->new(name => 'mycli');
3914  
3915 my $argument_name = $cli->argument_name;
3916  
3917 # ""
3918  
3919 =back
3920  
3921 =over 4
3922  
3923 =item argument_name example 2
3924  
3925 package main;
3926  
3927 use Venus::Cli;
3928  
3929 my $cli = Venus::Cli->new(name => 'mycli');
3930  
3931 $cli->argument('input', {
3932 name => 'INPUT',
3933 });
3934  
3935 my $argument_name = $cli->argument_name('input');
3936  
3937 # ""
3938  
3939 =back
3940  
3941 =over 4
3942  
3943 =item argument_name example 3
3944  
3945 package main;
3946  
3947 use Venus::Cli;
3948  
3949 my $cli = Venus::Cli->new(name => 'mycli');
3950  
3951 $cli->argument('input', {
3952 name => 'INPUT',
3953 });
3954  
3955 my $argument_name = $cli->argument_name('INPUT');
3956  
3957 # "INPUT"
3958  
3959 =back
3960  
3961 =cut
3962  
3963 =head2 argument_names
3964  
3965 argument_names(string $name) (within[arrayref, string])
3966  
3967 The argument_names method returns the names (keys) of registered arguments in
3968 the order declared. Returns a list in list context.
3969  
3970 I<Since C<4.15>>
3971  
3972 =over 4
3973  
3974 =item argument_names example 1
3975  
3976 package main;
3977  
3978 use Venus::Cli;
3979  
3980 my $cli = Venus::Cli->new(name => 'mycli');
3981  
3982 my $argument_names = $cli->argument_names;
3983  
3984 # []
3985  
3986 =back
3987  
3988 =over 4
3989  
3990 =item argument_names example 2
3991  
3992 package main;
3993  
3994 use Venus::Cli;
3995  
3996 my $cli = Venus::Cli->new(name => 'mycli');
3997  
3998 $cli->argument('input', {
3999 type => 'string',
4000 });
4001  
4002 $cli->argument('output', {
4003 type => 'string',
4004 });
4005  
4006 my $argument_names = $cli->argument_names;
4007  
4008 # ['input', 'output']
4009  
4010 =back
4011  
4012 =over 4
4013  
4014 =item argument_names example 3
4015  
4016 package main;
4017  
4018 use Venus::Cli;
4019  
4020 my $cli = Venus::Cli->new(name => 'mycli');
4021  
4022 $cli->argument('output', {
4023 type => 'string',
4024 });
4025  
4026 $cli->argument('input', {
4027 type => 'string',
4028 });
4029  
4030 my $argument_names = $cli->argument_names;
4031  
4032 # ['output', 'input']
4033  
4034 =back
4035  
4036 =cut
4037  
4038 =head2 argument_prompt
4039  
4040 argument_prompt(string $name) (string)
4041  
4042 The argument_prompt method returns the C<prompt> configuration value for the
4043 named argument.
4044  
4045 I<Since C<4.15>>
4046  
4047 =over 4
4048  
4049 =item argument_prompt example 1
4050  
4051 package main;
4052  
4053 use Venus::Cli;
4054  
4055 my $cli = Venus::Cli->new(name => 'mycli');
4056  
4057 my $argument_prompt = $cli->argument_prompt;
4058  
4059 # ""
4060  
4061 =back
4062  
4063 =over 4
4064  
4065 =item argument_prompt example 2
4066  
4067 package main;
4068  
4069 use Venus::Cli;
4070  
4071 my $cli = Venus::Cli->new(name => 'mycli');
4072  
4073 $cli->argument('input', {
4074 prompt => 'Example prompt',
4075 });
4076  
4077 my $argument_prompt = $cli->argument_prompt('input');
4078  
4079 # "Example prompt"
4080  
4081 =back
4082  
4083 =cut
4084  
4085 =head2 argument_range
4086  
4087 argument_range(string $name) (string)
4088  
4089 The argument_range method returns the C<range> configuration value for the
4090 named argument.
4091  
4092 I<Since C<4.15>>
4093  
4094 =over 4
4095  
4096 =item argument_range example 1
4097  
4098 package main;
4099  
4100 use Venus::Cli;
4101  
4102 my $cli = Venus::Cli->new(name => 'mycli');
4103  
4104 my $argument_range = $cli->argument_range;
4105  
4106 # ""
4107  
4108 =back
4109  
4110 =over 4
4111  
4112 =item argument_range example 2
4113  
4114 package main;
4115  
4116 use Venus::Cli;
4117  
4118 my $cli = Venus::Cli->new(name => 'mycli');
4119  
4120 $cli->argument('input', {
4121 range => '0',
4122 });
4123  
4124 my $argument_range = $cli->argument_range('input');
4125  
4126 # "0"
4127  
4128 =back
4129  
4130 =over 4
4131  
4132 =item argument_range example 3
4133  
4134 package main;
4135  
4136 use Venus::Cli;
4137  
4138 my $cli = Venus::Cli->new(name => 'mycli');
4139  
4140 $cli->argument('input', {
4141 range => '0:5',
4142 });
4143  
4144 my $argument_range = $cli->argument_range('input');
4145  
4146 # "0:5"
4147  
4148 =back
4149  
4150 =cut
4151  
4152 =head2 argument_required
4153  
4154 argument_required(string $name) (boolean)
4155  
4156 The argument_required method returns the C<required> configuration value for
4157 the named argument.
4158  
4159 I<Since C<4.15>>
4160  
4161 =over 4
4162  
4163 =item argument_required example 1
4164  
4165 package main;
4166  
4167 use Venus::Cli;
4168  
4169 my $cli = Venus::Cli->new(name => 'mycli');
4170  
4171 my $argument_required = $cli->argument_required;
4172  
4173 # false
4174  
4175 =back
4176  
4177 =over 4
4178  
4179 =item argument_required example 2
4180  
4181 package main;
4182  
4183 use Venus::Cli;
4184  
4185 my $cli = Venus::Cli->new(name => 'mycli');
4186  
4187 $cli->argument('input', {
4188 required => true,
4189 });
4190  
4191 my $argument_required = $cli->argument_required('input');
4192  
4193 # true
4194  
4195 =back
4196  
4197 =cut
4198  
4199 =head2 argument_type
4200  
4201 argument_type(string $name) (string)
4202  
4203 The argument_type method returns the C<type> configuration value for the named
4204 argument. Valid values are as follows:
4205  
4206 =over 4
4207  
4208 =item *
4209  
4210 C<number>
4211  
4212 =item *
4213  
4214 C<string>
4215  
4216 =item *
4217  
4218 C<float>
4219  
4220 =item *
4221  
4222 C<boolean> - B<Note:> Valid boolean values are C<1>, C<0>, C<"true">, and C<"false">.
4223  
4224 =item *
4225  
4226 C<yesno>
4227  
4228 =back
4229  
4230 I<Since C<4.15>>
4231  
4232 =over 4
4233  
4234 =item argument_type example 1
4235  
4236 package main;
4237  
4238 use Venus::Cli;
4239  
4240 my $cli = Venus::Cli->new(name => 'mycli');
4241  
4242 my $argument_type = $cli->argument_type;
4243  
4244 # ""
4245  
4246 =back
4247  
4248 =over 4
4249  
4250 =item argument_type example 2
4251  
4252 package main;
4253  
4254 use Venus::Cli;
4255  
4256 my $cli = Venus::Cli->new(name => 'mycli');
4257  
4258 $cli->argument('input', {
4259 type => 'boolean',
4260 });
4261  
4262 my $argument_type = $cli->argument_type('input');
4263  
4264 # "boolean"
4265  
4266 =back
4267  
4268 =cut
4269  
4270 =head2 argument_validate
4271  
4272 argument_validate(string $name) (Venus::Validate | within[arrayref, Venus::Validate])
4273  
4274 The argument_validate method returns a L<Venus::Validate> object for each value
4275 returned by L</argument_value> for the named argument. Returns a list in list
4276 context.
4277  
4278 I<Since C<4.15>>
4279  
4280 =over 4
4281  
4282 =item argument_validate example 1
4283  
4284 package main;
4285  
4286 use Venus::Cli;
4287  
4288 my $cli = Venus::Cli->new(name => 'mycli');
4289  
4290 my $argument_validate = $cli->argument_validate;
4291  
4292 # []
4293  
4294 =back
4295  
4296 =over 4
4297  
4298 =item argument_validate example 2
4299  
4300 package main;
4301  
4302 use Venus::Cli;
4303  
4304 my $cli = Venus::Cli->new(name => 'mycli');
4305  
4306 $cli->argument('input', {
4307 multiples => true,
4308 range => '0',
4309 type => 'string',
4310 });
4311  
4312 my $argument_validate = $cli->argument_validate('input');
4313  
4314 # [bless(..., "Venus::Validate")]
4315  
4316 =back
4317  
4318 =over 4
4319  
4320 =item argument_validate example 3
4321  
4322 package main;
4323  
4324 use Venus::Cli;
4325  
4326 my $cli = Venus::Cli->new(name => 'mycli');
4327  
4328 $cli->argument('input', {
4329 multiples => false,
4330 range => '0',
4331 type => 'string',
4332 });
4333  
4334 my $argument_validate = $cli->argument_validate('input');
4335  
4336 # bless(..., "Venus::Validate")
4337  
4338 =back
4339  
4340 =over 4
4341  
4342 =item argument_validate example 4
4343  
4344 package main;
4345  
4346 use Venus::Cli;
4347  
4348 my $cli = Venus::Cli->new(name => 'mycli');
4349  
4350 $cli->argument('input', {
4351 multiples => true,
4352 range => '0:',
4353 type => 'string',
4354 });
4355  
4356 $cli->parse('hello', 'world');
4357  
4358 my $argument_validate = $cli->argument_validate('input');
4359  
4360 # [bless(..., "Venus::Validate"), bless(..., "Venus::Validate")]
4361  
4362 =back
4363  
4364 =cut
4365  
4366 =head2 argument_value
4367  
4368 argument_value(string $name) (any)
4369  
4370 The argument_value method returns the parsed argument value for the named
4371 argument.
4372  
4373 I<Since C<4.15>>
4374  
4375 =over 4
4376  
4377 =item argument_value example 1
4378  
4379 package main;
4380  
4381 use Venus::Cli;
4382  
4383 my $cli = Venus::Cli->new(name => 'mycli');
4384  
4385 my $argument_value = $cli->argument_value;
4386  
4387 # undef
4388  
4389 =back
4390  
4391 =over 4
4392  
4393 =item argument_value example 2
4394  
4395 package main;
4396  
4397 use Venus::Cli;
4398  
4399 my $cli = Venus::Cli->new(name => 'mycli');
4400  
4401 $cli->argument('input', {
4402 multiples => false,
4403 range => '0:',
4404 type => 'string',
4405 });
4406  
4407 $cli->parse('hello', 'world');
4408  
4409 my $argument_value = $cli->argument_value('input');
4410  
4411 # "hello"
4412  
4413 =back
4414  
4415 =over 4
4416  
4417 =item argument_value example 3
4418  
4419 package main;
4420  
4421 use Venus::Cli;
4422  
4423 my $cli = Venus::Cli->new(name => 'mycli');
4424  
4425 $cli->argument('input', {
4426 multiples => true,
4427 range => '0:',
4428 type => 'string',
4429 });
4430  
4431 $cli->parse('hello', 'world');
4432  
4433 my $argument_value = $cli->argument_value('input');
4434  
4435 # ["hello", "world"]
4436  
4437 =back
4438  
4439 =cut
4440  
4441 =head2 argument_wants
4442  
4443 argument_wants(string $name) (string)
4444  
4445 The argument_wants method returns the C<wants> configuration value for the
4446 named argument.
4447  
4448 I<Since C<4.15>>
4449  
4450 =over 4
4451  
4452 =item argument_wants example 1
4453  
4454 package main;
4455  
4456 use Venus::Cli;
4457  
4458 my $cli = Venus::Cli->new(name => 'mycli');
4459  
4460 my $argument_wants = $cli->argument_wants;
4461  
4462 # ""
4463  
4464 =back
4465  
4466 =over 4
4467  
4468 =item argument_wants example 2
4469  
4470 package main;
4471  
4472 use Venus::Cli;
4473  
4474 my $cli = Venus::Cli->new(name => 'mycli');
4475  
4476 $cli->argument('input', {
4477 wants => 'string',
4478 });
4479  
4480 my $argument_wants = $cli->argument_wants('input');
4481  
4482 # "string"
4483  
4484 =back
4485  
4486 =cut
4487  
4488 =head2 assigned_arguments
4489  
4490 assigned_arguments() (hashref)
4491  
4492 The assigned_arguments method gets the values for the registered arguments.
4493  
4494 I<Since C<4.15>>
4495  
4496 =over 4
4497  
4498 =item assigned_arguments example 1
4499  
4500 package main;
4501  
4502 use Venus::Cli;
4503  
4504 my $cli = Venus::Cli->new(name => 'mycli');
4505  
4506 $cli->option('input', {
4507 type => 'string',
4508 });
4509  
4510 $cli->option('output', {
4511 type => 'string',
4512 });
4513  
4514 $cli->argument('extra', {
4515 range => '0:',
4516 type => 'string',
4517 });
4518  
4519 local @ARGV = qw(--input stdin --output stdout hello world);
4520  
4521 my $assigned_arguments = $cli->assigned_arguments;
4522  
4523 # {extra => 'hello'}
4524  
4525 =back
4526  
4527 =over 4
4528  
4529 =item assigned_arguments example 2
4530  
4531 package main;
4532  
4533 use Venus::Cli;
4534  
4535 my $cli = Venus::Cli->new(name => 'mycli');
4536  
4537 $cli->option('input', {
4538 type => 'string',
4539 });
4540  
4541 $cli->option('output', {
4542 type => 'string',
4543 });
4544  
4545 $cli->argument('extra', {
4546 multiples => true,
4547 range => '0:',
4548 type => 'string',
4549 });
4550  
4551 local @ARGV = qw(--input stdin --output stdout hello world);
4552  
4553 my $assigned_arguments = $cli->assigned_arguments;
4554  
4555 # {extra => ['hello', 'world']}
4556  
4557 =back
4558  
4559 =cut
4560  
4561 =head2 assigned_options
4562  
4563 assigned_options() (hashref)
4564  
4565 The assigned_options method gets the values for the registered options.
4566  
4567 I<Since C<4.15>>
4568  
4569 =over 4
4570  
4571 =item assigned_options example 1
4572  
4573 package main;
4574  
4575 use Venus::Cli;
4576  
4577 my $cli = Venus::Cli->new(name => 'mycli');
4578  
4579 $cli->option('input', {
4580 type => 'string',
4581 });
4582  
4583 $cli->option('output', {
4584 type => 'string',
4585 });
4586  
4587 $cli->argument('extra', {
4588 range => '0:',
4589 type => 'string',
4590 });
4591  
4592 local @ARGV = qw(--input stdin --output stdout hello world);
4593  
4594 my $assigned_options = $cli->assigned_options;
4595  
4596 # {input => 'stdin', output => 'stdout'}
4597  
4598 =back
4599  
4600 =over 4
4601  
4602 =item assigned_options example 2
4603  
4604 package main;
4605  
4606 use Venus::Cli;
4607  
4608 my $cli = Venus::Cli->new(name => 'mycli');
4609  
4610 $cli->option('input', {
4611 multiples => true,
4612 type => 'string',
4613 });
4614  
4615 $cli->option('output', {
4616 multiples => true,
4617 type => 'string',
4618 });
4619  
4620 $cli->argument('extra', {
4621 range => '0:',
4622 type => 'string',
4623 });
4624  
4625 local @ARGV = qw(--input stdin --output stdout hello world);
4626  
4627 my $assigned_options = $cli->assigned_options;
4628  
4629 # {input => ['stdin'], output => ['stdout']}
4630  
4631 =back
4632  
4633 =cut
4634  
4635 =head2 boolean
4636  
4637 boolean(string $method, any @args) (any)
4638  
4639 The boolean method is a configuration dispatcher and shorthand for C<{'type',
4640 'boolean'}>. It returns the data or dispatches to the next configuration
4641 dispatcher based on the name provided and merges the configurations produced.
4642  
4643 I<Since C<4.15>>
4644  
4645 =over 4
4646  
4647 =item boolean example 1
4648  
4649 # given: synopsis
4650  
4651 package main;
4652  
4653 my $boolean = $cli->boolean;
4654  
4655 # {type => 'boolean'}
4656  
4657 =back
4658  
4659 =over 4
4660  
4661 =item boolean example 2
4662  
4663 # given: synopsis
4664  
4665 package main;
4666  
4667 my $boolean = $cli->boolean(undef, {required => true});
4668  
4669 # {type => 'boolean', required => true}
4670  
4671 =back
4672  
4673 =over 4
4674  
4675 =item boolean example 3
4676  
4677 # given: synopsis
4678  
4679 package main;
4680  
4681 my $boolean = $cli->boolean('option', 'example');
4682  
4683 # {
4684 # name => 'example',
4685 # label => undef,
4686 # help => 'Expects a boolean value',
4687 # default => undef,
4688 # aliases => [],
4689 # multiples => 0,
4690 # prompt => undef,
4691 # range => undef,
4692 # required => 1,
4693 # type => 'boolean',
4694 # index => 0,
4695 # wants => 'boolean',
4696 # }
4697  
4698 =back
4699  
4700 =cut
4701  
4702 =head2 choice
4703  
4704 choice(string $name, hashref $data) (maybe[hashref])
4705  
4706 The choice method registers and returns the configuration for the choice
4707 specified. The method takes a name (choice name) and a hashref of
4708 configuration values. The possible configuration values are as follows:
4709  
4710 =over 4
4711  
4712 =item *
4713  
4714 The C<name> key holds the name of the argument.
4715  
4716 =item *
4717  
4718 The C<label> key holds the name of the argument as it should be displayed in
4719 the CLI help text.
4720  
4721 =item *
4722  
4723 The C<help> key holds the help text specific to this argument.
4724  
4725 =item *
4726  
4727 The C<argument> key holds the name of the argument that this choice is a
4728 value for.
4729  
4730 =item *
4731  
4732 The C<wants> key holdd the text to be used as a value placeholder in the CLI
4733 help text.
4734  
4735 =back
4736  
4737 I<Since C<4.15>>
4738  
4739 =over 4
4740  
4741 =item choice example 1
4742  
4743 package main;
4744  
4745 use Venus::Cli;
4746  
4747 my $cli = Venus::Cli->new(name => 'mycli');
4748  
4749 $cli->argument('input', {
4750 range => '0',
4751 type => 'string',
4752 });
4753  
4754 my $choice = $cli->choice('stdin', {
4755 argument => 'input',
4756 });
4757  
4758 # {
4759 # name => 'stdin',
4760 # label => undef,
4761 # help => undef,
4762 # argument => 'input',
4763 # index => 0,
4764 # wants => 'string',
4765 # }
4766  
4767 =back
4768  
4769 =cut
4770  
4771 =head2 choice_argument
4772  
4773 choice_argument(string $name) (hashref)
4774  
4775 The choice_argument method returns the argument configuration corresponding
4776 with the C<argument> value of the named choice.
4777  
4778 I<Since C<4.15>>
4779  
4780 =over 4
4781  
4782 =item choice_argument example 1
4783  
4784 package main;
4785  
4786 use Venus::Cli;
4787  
4788 my $cli = Venus::Cli->new(name => 'mycli');
4789  
4790 $cli->argument('input', {
4791 type => 'string',
4792 });
4793  
4794 $cli->choice('stdin', {
4795 argument => 'input',
4796 });
4797  
4798 my $choice_argument = $cli->choice_argument('stdin');
4799  
4800 # {
4801 # name => 'input',
4802 # label => undef,
4803 # help => 'Expects a string value',
4804 # default => undef,
4805 # multiples => 0,
4806 # prompt => undef,
4807 # range => undef,
4808 # required => 0,
4809 # type => 'string',
4810 # index => 0,
4811 # wants => 'string',
4812 # }
4813  
4814 =back
4815  
4816 =cut
4817  
4818 =head2 choice_count
4819  
4820 choice_count() (number)
4821  
4822 The choice_count method returns the count of registered choices.
4823  
4824 I<Since C<4.15>>
4825  
4826 =over 4
4827  
4828 =item choice_count example 1
4829  
4830 package main;
4831  
4832 use Venus::Cli;
4833  
4834 my $cli = Venus::Cli->new(name => 'mycli');
4835  
4836 my $choice_count = $cli->choice_count;
4837  
4838 # 0
4839  
4840 =back
4841  
4842 =over 4
4843  
4844 =item choice_count example 2
4845  
4846 package main;
4847  
4848 use Venus::Cli;
4849  
4850 my $cli = Venus::Cli->new(name => 'mycli');
4851  
4852 $cli->argument('input', {
4853 range => '0:',
4854 type => 'string',
4855 });
4856  
4857 $cli->choice('file', {
4858 argument => 'input',
4859 });
4860  
4861 $cli->choice('stdin', {
4862 argument => 'input',
4863 });
4864  
4865 my $choice_count = $cli->choice_count;
4866  
4867 # 2
4868  
4869 =back
4870  
4871 =cut
4872  
4873 =head2 choice_default
4874  
4875 choice_default(string $name) (string)
4876  
4877 The choice_default method returns the C<default> configuration value for the
4878 argument corresponding to the named choice.
4879  
4880 I<Since C<4.15>>
4881  
4882 =over 4
4883  
4884 =item choice_default example 1
4885  
4886 package main;
4887  
4888 use Venus::Cli;
4889  
4890 my $cli = Venus::Cli->new(name => 'mycli');
4891  
4892 $cli->argument('input', {
4893 default => 'file',
4894 type => 'string',
4895 });
4896  
4897 $cli->choice('stdin', {
4898 argument => 'input',
4899 });
4900  
4901 my $choice_default = $cli->choice_default('stdin');
4902  
4903 # "file"
4904  
4905 =back
4906  
4907 =cut
4908  
4909 =head2 choice_errors
4910  
4911 choice_errors(string $name) (within[arrayref, Venus::Validate])
4912  
4913 The choice_errors method returns a list of L<"issues"|Venus::Validate/issue>,
4914 if any, for each value returned by L</choice_value> for the named choice.
4915 Returns a list in list context.
4916  
4917 I<Since C<4.15>>
4918  
4919 =over 4
4920  
4921 =item choice_errors example 1
4922  
4923 package main;
4924  
4925 use Venus::Cli;
4926  
4927 my $cli = Venus::Cli->new(name => 'mycli');
4928  
4929 my $choice_errors = $cli->choice_errors;
4930  
4931 # []
4932  
4933 =back
4934  
4935 =over 4
4936  
4937 =item choice_errors example 2
4938  
4939 package main;
4940  
4941 use Venus::Cli;
4942  
4943 my $cli = Venus::Cli->new(name => 'mycli');
4944  
4945 $cli->argument('input', {
4946 range => '0',
4947 type => 'string',
4948 });
4949  
4950 $cli->choice('stdin', {
4951 argument => 'input',
4952 });
4953  
4954 $cli->parse('hello');
4955  
4956 my $choice_errors = $cli->choice_errors('stdin');
4957  
4958 # []
4959  
4960 =back
4961  
4962 =over 4
4963  
4964 =item choice_errors example 3
4965  
4966 package main;
4967  
4968 use Venus::Cli;
4969  
4970 my $cli = Venus::Cli->new(name => 'mycli');
4971  
4972 $cli->argument('input', {
4973 range => '0',
4974 type => 'number',
4975 });
4976  
4977 $cli->choice('stdin', {
4978 argument => 'input',
4979 });
4980  
4981 $cli->parse('hello');
4982  
4983 my $choice_errors = $cli->choice_errors('stdin');
4984  
4985 # [['type', ['number']]]
4986  
4987 =back
4988  
4989 =cut
4990  
4991 =head2 choice_help
4992  
4993 choice_help(string $name) (string)
4994  
4995 The choice_help method returns the C<help> configuration value the named
4996 choice.
4997  
4998 I<Since C<4.15>>
4999  
5000 =over 4
5001  
5002 =item choice_help example 1
5003  
5004 package main;
5005  
5006 use Venus::Cli;
5007  
5008 my $cli = Venus::Cli->new(name => 'mycli');
5009  
5010 my $choice_help = $cli->choice_help;
5011  
5012 # ""
5013  
5014 =back
5015  
5016 =over 4
5017  
5018 =item choice_help example 2
5019  
5020 package main;
5021  
5022 use Venus::Cli;
5023  
5024 my $cli = Venus::Cli->new(name => 'mycli');
5025  
5026 $cli->argument('input', {
5027 type => 'string',
5028 });
5029  
5030 $cli->choice('stdin', {
5031 argument => 'input',
5032 help => 'Example help',
5033 });
5034  
5035 my $choice_help = $cli->choice_help('stdin');
5036  
5037 # "Example help"
5038  
5039 =back
5040  
5041 =cut
5042  
5043 =head2 choice_label
5044  
5045 choice_label(string $name) (string)
5046  
5047 The choice_label method returns the C<label> configuration value for the named
5048 choice.
5049  
5050 I<Since C<4.15>>
5051  
5052 =over 4
5053  
5054 =item choice_label example 1
5055  
5056 package main;
5057  
5058 use Venus::Cli;
5059  
5060 my $cli = Venus::Cli->new(name => 'mycli');
5061  
5062 my $choice_label = $cli->choice_label;
5063  
5064 # ""
5065  
5066 =back
5067  
5068 =over 4
5069  
5070 =item choice_label example 2
5071  
5072 package main;
5073  
5074 use Venus::Cli;
5075  
5076 my $cli = Venus::Cli->new(name => 'mycli');
5077  
5078 $cli->argument('input', {
5079 type => 'string',
5080 });
5081  
5082 $cli->choice('stdin', {
5083 argument => 'input',
5084 label => 'Standard input',
5085 });
5086  
5087 my $choice_label = $cli->choice_label('stdin');
5088  
5089 # "Standard input"
5090  
5091 =back
5092  
5093 =cut
5094  
5095 =head2 choice_list
5096  
5097 choice_list(string $name) (within[arrayref, hashref])
5098  
5099 The choice_list method returns a list of registered choice configurations.
5100 Returns a list in list context.
5101  
5102 I<Since C<4.15>>
5103  
5104 =over 4
5105  
5106 =item choice_list example 1
5107  
5108 package main;
5109  
5110 use Venus::Cli;
5111  
5112 my $cli = Venus::Cli->new(name => 'mycli');
5113  
5114 my $choice_list = $cli->choice_list;
5115  
5116 # []
5117  
5118 =back
5119  
5120 =over 4
5121  
5122 =item choice_list example 2
5123  
5124 package main;
5125  
5126 use Venus::Cli;
5127  
5128 my $cli = Venus::Cli->new(name => 'mycli');
5129  
5130 $cli->argument('input', {
5131 type => 'string',
5132 });
5133  
5134 $cli->choice('stdin', {
5135 argument => 'input',
5136 });
5137  
5138 my $choice_list = $cli->choice_list;
5139  
5140 # [{
5141 # name => 'stdin',
5142 # label => undef,
5143 # help => 'Expects a string value',
5144 # argument => 'input',
5145 # index => 0,
5146 # wants => 'string',
5147 # }]
5148  
5149 =back
5150  
5151 =cut
5152  
5153 =head2 choice_multiples
5154  
5155 choice_multiples(string $name) (boolean)
5156  
5157 The choice_multiples method returns the C<multiples> configuration value for
5158 the argument corresponding to the named choice.
5159  
5160 I<Since C<4.15>>
5161  
5162 =over 4
5163  
5164 =item choice_multiples example 1
5165  
5166 package main;
5167  
5168 use Venus::Cli;
5169  
5170 my $cli = Venus::Cli->new(name => 'mycli');
5171  
5172 my $choice_multiples = $cli->choice_multiples;
5173  
5174 # false
5175  
5176 =back
5177  
5178 =over 4
5179  
5180 =item choice_multiples example 2
5181  
5182 package main;
5183  
5184 use Venus::Cli;
5185  
5186 my $cli = Venus::Cli->new(name => 'mycli');
5187  
5188 $cli->argument('input', {
5189 multiples => true,
5190 type => 'string',
5191 });
5192  
5193 $cli->choice('stdin', {
5194 argument => 'input',
5195 });
5196  
5197 my $choice_multiples = $cli->choice_multiples('stdin');
5198  
5199 # true
5200  
5201 =back
5202  
5203 =cut
5204  
5205 =head2 choice_name
5206  
5207 choice_name(string $name) (string)
5208  
5209 The choice_name method returns the C<name> configuration value for the named
5210 choice.
5211  
5212 I<Since C<4.15>>
5213  
5214 =over 4
5215  
5216 =item choice_name example 1
5217  
5218 package main;
5219  
5220 use Venus::Cli;
5221  
5222 my $cli = Venus::Cli->new(name => 'mycli');
5223  
5224 my $choice_name = $cli->choice_name;
5225  
5226 # ""
5227  
5228 =back
5229  
5230 =over 4
5231  
5232 =item choice_name example 2
5233  
5234 package main;
5235  
5236 use Venus::Cli;
5237  
5238 my $cli = Venus::Cli->new(name => 'mycli');
5239  
5240 $cli->argument('input', {
5241 type => 'string',
5242 });
5243  
5244 $cli->choice('stdin', {
5245 name => 'STDIN',
5246 argument => 'input',
5247 });
5248  
5249 my $choice_name = $cli->choice_name('stdin');
5250  
5251 # "STDIN"
5252  
5253 =back
5254  
5255 =cut
5256  
5257 =head2 choice_names
5258  
5259 choice_names(string $name) (within[arrayref, string])
5260  
5261 The choice_names method returns the names (keys) of registered choices in
5262 the order declared. Returns a list in list context.
5263  
5264 I<Since C<4.15>>
5265  
5266 =over 4
5267  
5268 =item choice_names example 1
5269  
5270 package main;
5271  
5272 use Venus::Cli;
5273  
5274 my $cli = Venus::Cli->new(name => 'mycli');
5275  
5276 my $choice_names = $cli->choice_names;
5277  
5278 # []
5279  
5280 =back
5281  
5282 =over 4
5283  
5284 =item choice_names example 2
5285  
5286 package main;
5287  
5288 use Venus::Cli;
5289  
5290 my $cli = Venus::Cli->new(name => 'mycli');
5291  
5292 $cli->argument('input', {
5293 type => 'string',
5294 });
5295  
5296 $cli->choice('file', {
5297 argument => 'input',
5298 });
5299  
5300 $cli->choice('stdin', {
5301 argument => 'input',
5302 });
5303  
5304 my $choice_names = $cli->choice_names;
5305  
5306 # ['file', 'stdin']
5307  
5308 =back
5309  
5310 =over 4
5311  
5312 =item choice_names example 3
5313  
5314 package main;
5315  
5316 use Venus::Cli;
5317  
5318 my $cli = Venus::Cli->new(name => 'mycli');
5319  
5320 $cli->argument('input', {
5321 type => 'string',
5322 });
5323  
5324 $cli->choice('stdin', {
5325 argument => 'input',
5326 });
5327  
5328 $cli->choice('file', {
5329 argument => 'input',
5330 });
5331  
5332 my $choice_names = $cli->choice_names;
5333  
5334 # ['stdin', 'file']
5335  
5336 =back
5337  
5338 =cut
5339  
5340 =head2 choice_prompt
5341  
5342 choice_prompt(string $name) (string)
5343  
5344 The choice_prompt method returns the C<prompt> configuration value for the
5345 argument corresponding to the named choice.
5346  
5347 I<Since C<4.15>>
5348  
5349 =over 4
5350  
5351 =item choice_prompt example 1
5352  
5353 package main;
5354  
5355 use Venus::Cli;
5356  
5357 my $cli = Venus::Cli->new(name => 'mycli');
5358  
5359 my $choice_prompt = $cli->choice_prompt;
5360  
5361 # ""
5362  
5363 =back
5364  
5365 =over 4
5366  
5367 =item choice_prompt example 2
5368  
5369 package main;
5370  
5371 use Venus::Cli;
5372  
5373 my $cli = Venus::Cli->new(name => 'mycli');
5374  
5375 $cli->argument('input', {
5376 prompt => 'Example prompt',
5377 type => 'string',
5378 });
5379  
5380 $cli->choice('stdin', {
5381 argument => 'input',
5382 });
5383  
5384 my $choice_prompt = $cli->choice_prompt('stdin');
5385  
5386 # "Example prompt"
5387  
5388 =back
5389  
5390 =cut
5391  
5392 =head2 choice_range
5393  
5394 choice_range(string $name) (string)
5395  
5396 The choice_range method returns the C<range> configuration value for the
5397 argument corresponding to the named choice.
5398  
5399 I<Since C<4.15>>
5400  
5401 =over 4
5402  
5403 =item choice_range example 1
5404  
5405 package main;
5406  
5407 use Venus::Cli;
5408  
5409 my $cli = Venus::Cli->new(name => 'mycli');
5410  
5411 my $choice_range = $cli->choice_range;
5412  
5413 # ""
5414  
5415 =back
5416  
5417 =over 4
5418  
5419 =item choice_range example 2
5420  
5421 package main;
5422  
5423 use Venus::Cli;
5424  
5425 my $cli = Venus::Cli->new(name => 'mycli');
5426  
5427 $cli->argument('input', {
5428 range => '0:',
5429 type => 'string',
5430 });
5431  
5432 $cli->choice('stdin', {
5433 argument => 'input',
5434 });
5435  
5436 my $choice_range = $cli->choice_range('stdin');
5437  
5438 # "0:"
5439  
5440 =back
5441  
5442 =cut
5443  
5444 =head2 choice_required
5445  
5446 choice_required(string $name) (boolean)
5447  
5448 The choice_required method returns the C<required> configuration value for the
5449 argument corresponding to the named choice.
5450  
5451 I<Since C<4.15>>
5452  
5453 =over 4
5454  
5455 =item choice_required example 1
5456  
5457 package main;
5458  
5459 use Venus::Cli;
5460  
5461 my $cli = Venus::Cli->new(name => 'mycli');
5462  
5463 my $choice_required = $cli->choice_required;
5464  
5465 # false
5466  
5467 =back
5468  
5469 =over 4
5470  
5471 =item choice_required example 2
5472  
5473 package main;
5474  
5475 use Venus::Cli;
5476  
5477 my $cli = Venus::Cli->new(name => 'mycli');
5478  
5479 $cli->argument('input', {
5480 required => true,
5481 type => 'string',
5482 });
5483  
5484 $cli->choice('stdin', {
5485 argument => 'input',
5486 });
5487  
5488 my $choice_required = $cli->choice_required('stdin');
5489  
5490 # true
5491  
5492 =back
5493  
5494 =cut
5495  
5496 =head2 choice_type
5497  
5498 choice_type(string $name) (string)
5499  
5500 The choice_type method returns the C<type> configuration value for the
5501 argument corresponding to the named choice.
5502  
5503 I<Since C<4.15>>
5504  
5505 =over 4
5506  
5507 =item choice_type example 1
5508  
5509 package main;
5510  
5511 use Venus::Cli;
5512  
5513 my $cli = Venus::Cli->new(name => 'mycli');
5514  
5515 my $choice_type = $cli->choice_type;
5516  
5517 # ""
5518  
5519 =back
5520  
5521 =over 4
5522  
5523 =item choice_type example 2
5524  
5525 package main;
5526  
5527 use Venus::Cli;
5528  
5529 my $cli = Venus::Cli->new(name => 'mycli');
5530  
5531 $cli->argument('input', {
5532 type => 'string',
5533 });
5534  
5535 $cli->choice('stdin', {
5536 argument => 'input',
5537 });
5538  
5539 my $choice_type = $cli->choice_type('stdin');
5540  
5541 # "string"
5542  
5543 =back
5544  
5545 =cut
5546  
5547 =head2 choice_validate
5548  
5549 choice_validate(string $name) (within[arrayref, Venus::Validate])
5550  
5551 The choice_validate method returns a L<Venus::Validate> object for each value
5552 returned by L</choice_value> for the named choice. Returns a list in list
5553 context.
5554  
5555 I<Since C<4.15>>
5556  
5557 =over 4
5558  
5559 =item choice_validate example 1
5560  
5561 package main;
5562  
5563 use Venus::Cli;
5564  
5565 my $cli = Venus::Cli->new(name => 'mycli');
5566  
5567 my $choice_validate = $cli->choice_validate;
5568  
5569 # []
5570  
5571 =back
5572  
5573 =over 4
5574  
5575 =item choice_validate example 2
5576  
5577 package main;
5578  
5579 use Venus::Cli;
5580  
5581 my $cli = Venus::Cli->new(name => 'mycli');
5582  
5583 $cli->argument('input', {
5584 multiples => true,
5585 range => '0',
5586 type => 'string',
5587 });
5588  
5589 $cli->choice('stdin', {
5590 argument => 'input',
5591 });
5592  
5593 my $choice_validate = $cli->choice_validate('stdin');
5594  
5595 # [bless(..., "Venus::Validate")]
5596  
5597 =back
5598  
5599 =over 4
5600  
5601 =item choice_validate example 3
5602  
5603 package main;
5604  
5605 use Venus::Cli;
5606  
5607 my $cli = Venus::Cli->new(name => 'mycli');
5608  
5609 $cli->argument('input', {
5610 multiples => false,
5611 range => '0',
5612 type => 'string',
5613 });
5614  
5615 $cli->choice('stdin', {
5616 argument => 'input',
5617 });
5618  
5619 my $choice_validate = $cli->choice_validate('stdin');
5620  
5621 # bless(..., "Venus::Validate")
5622  
5623 =back
5624  
5625 =over 4
5626  
5627 =item choice_validate example 4
5628  
5629 package main;
5630  
5631 use Venus::Cli;
5632  
5633 my $cli = Venus::Cli->new(name => 'mycli');
5634  
5635 $cli->argument('input', {
5636 multiples => true,
5637 range => '0:',
5638 type => 'string',
5639 });
5640  
5641 $cli->choice('stdin', {
5642 argument => 'input',
5643 });
5644  
5645 $cli->parse('hello', 'world');
5646  
5647 my $choice_validate = $cli->choice_validate('stdin');
5648  
5649 # [bless(..., "Venus::Validate"), bless(..., "Venus::Validate")]
5650  
5651 =back
5652  
5653 =cut
5654  
5655 =head2 choice_value
5656  
5657 choice_value(string $name) (any)
5658  
5659 The choice_value method returns the parsed choice value for the named
5660 choice.
5661  
5662 I<Since C<4.15>>
5663  
5664 =over 4
5665  
5666 =item choice_value example 1
5667  
5668 package main;
5669  
5670 use Venus::Cli;
5671  
5672 my $cli = Venus::Cli->new(name => 'mycli');
5673  
5674 my $choice_value = $cli->choice_value;
5675  
5676 # undef
5677  
5678 =back
5679  
5680 =over 4
5681  
5682 =item choice_value example 2
5683  
5684 package main;
5685  
5686 use Venus::Cli;
5687  
5688 my $cli = Venus::Cli->new(name => 'mycli');
5689  
5690 $cli->argument('input', {
5691 multiples => false,
5692 range => '0:',
5693 type => 'string',
5694 });
5695  
5696 $cli->choice('stdin', {
5697 argument => 'input',
5698 });
5699  
5700 $cli->parse('hello', 'world');
5701  
5702 my $choice_value = $cli->choice_value('stdin');
5703  
5704 # "hello"
5705  
5706 =back
5707  
5708 =over 4
5709  
5710 =item choice_value example 3
5711  
5712 package main;
5713  
5714 use Venus::Cli;
5715  
5716 my $cli = Venus::Cli->new(name => 'mycli');
5717  
5718 $cli->argument('input', {
5719 multiples => true,
5720 range => '0:',
5721 type => 'string',
5722 });
5723  
5724 $cli->choice('stdin', {
5725 argument => 'input',
5726 });
5727  
5728 $cli->parse('hello', 'world');
5729  
5730 my $choice_value = $cli->choice_value('stdin');
5731  
5732 # ["hello", "world"]
5733  
5734 =back
5735  
5736 =cut
5737  
5738 =head2 choice_wants
5739  
5740 choice_wants(string $name) (string)
5741  
5742 The choice_wants method returns the C<wants> configuration value for the
5743 argument corresponding to the named choice.
5744  
5745 I<Since C<4.15>>
5746  
5747 =over 4
5748  
5749 =item choice_wants example 1
5750  
5751 package main;
5752  
5753 use Venus::Cli;
5754  
5755 my $cli = Venus::Cli->new(name => 'mycli');
5756  
5757 my $choice_wants = $cli->choice_wants;
5758  
5759 # ""
5760  
5761 =back
5762  
5763 =over 4
5764  
5765 =item choice_wants example 2
5766  
5767 package main;
5768  
5769 use Venus::Cli;
5770  
5771 my $cli = Venus::Cli->new(name => 'mycli');
5772  
5773 $cli->argument('input', {
5774 wants => 'string',
5775 });
5776  
5777 $cli->choice('stdin', {
5778 argument => 'input',
5779 });
5780  
5781 my $choice_wants = $cli->choice_wants('stdin');
5782  
5783 # "string"
5784  
5785 =back
5786  
5787 =cut
5788  
5789 =head2 command
5790  
5791 command(string $argument, string | arrayref $choice, string | coderef $handler) (maybe[hashref])
5792  
5793 The command method creates and associates an argument, choice, and route. It
5794 takes an argument name, a choice name (string or arrayref of parts), and a
5795 handler (method name or coderef). The method returns the route configuration
5796 for the command.
5797  
5798 I<Since C<4.15>>
5799  
5800 =over 4
5801  
5802 =item command example 1
5803  
5804 package main;
5805  
5806 use Venus::Cli;
5807  
5808 my $cli = Venus::Cli->new(name => 'mycli');
5809  
5810 my $command = $cli->command('command', ['user', 'create'], 'handle_user_create');
5811  
5812 # {
5813 # name => 'user create',
5814 # label => undef,
5815 # help => undef,
5816 # argument => 'command',
5817 # choice => 'user create',
5818 # handler => 'handle_user_create',
5819 # range => ':1',
5820 # index => 0,
5821 # }
5822  
5823 =back
5824  
5825 =over 4
5826  
5827 =item command example 2
5828  
5829 package main;
5830  
5831 use Venus::Cli;
5832  
5833 my $cli = Venus::Cli->new(name => 'mycli');
5834  
5835 my $command = $cli->command('command', 'user create', 'handle_user_create');
5836  
5837 # {
5838 # name => 'user create',
5839 # label => undef,
5840 # help => undef,
5841 # argument => 'command',
5842 # choice => 'user create',
5843 # handler => 'handle_user_create',
5844 # range => ':1',
5845 # index => 0,
5846 # }
5847  
5848 =back
5849  
5850 =over 4
5851  
5852 =item command example 3
5853  
5854 package main;
5855  
5856 use Venus::Cli;
5857  
5858 my $cli = Venus::Cli->new(name => 'mycli');
5859  
5860 my $command = $cli->command('command', ['user'], 'handle_user');
5861  
5862 # {
5863 # name => 'user',
5864 # label => undef,
5865 # help => undef,
5866 # argument => 'command',
5867 # choice => 'user',
5868 # handler => 'handle_user',
5869 # range => ':0',
5870 # index => 0,
5871 # }
5872  
5873 =back
5874  
5875 =over 4
5876  
5877 =item command example 4
5878  
5879 package main;
5880  
5881 use Venus::Cli;
5882  
5883 my $cli = Venus::Cli->new(name => 'mycli');
5884  
5885 $cli->command('command', ['user', 'create'], 'handle_user_create');
5886 $cli->command('command', ['user', 'delete'], 'handle_user_delete');
5887  
5888 my $argument = $cli->argument('command');
5889  
5890 # {
5891 # name => 'command',
5892 # ...
5893 # range => ':1',
5894 # }
5895  
5896 =back
5897  
5898 =cut
5899  
5900 =head2 dispatch
5901  
5902 dispatch(any @args) (any)
5903  
5904 The dispatch method parses CLI arguments, matches them against registered
5905 routes, and invokes the appropriate handler. If the handler is a coderef, it is
5906 called with the CLI instance, L</assigned_arguments>, and L</assigned_options>.
5907 If the handler is a local method name, it is called with </assigned_arguments>,
5908 and L</assigned_options>. If the handler is a package name, the package is
5909 loaded and instantiated. If the package is a L<Venus::Task>, its
5910 L<Venus::Task/handle> method is called. If the package is a L<Venus::Cli>, its
5911 L</dispatch> method is called. When dispatching to a package, only the relevant
5912 portion of the command line arguments (after the matched command) is passed.
5913  
5914 I<Since C<4.15>>
5915  
5916 =over 4
5917  
5918 =item dispatch example 1
5919  
5920 package main;
5921  
5922 use Venus::Cli;
5923  
5924 my $cli = Venus::Cli->new(name => 'mycli');
5925  
5926 my $dispatch = $cli->dispatch;
5927  
5928 # undef
5929  
5930 =back
5931  
5932 =over 4
5933  
5934 =item dispatch example 2
5935  
5936 package main;
5937  
5938 use Venus::Cli;
5939  
5940 my $cli = Venus::Cli->new(name => 'mycli');
5941  
5942 $cli->command('command', ['user', 'create'], 'handle_user_create');
5943  
5944 my $dispatch = $cli->dispatch('user', 'create');
5945  
5946 # undef (no handler method exists)
5947  
5948 =back
5949  
5950 =over 4
5951  
5952 =item dispatch example 3
5953  
5954 package main;
5955  
5956 use Venus::Cli;
5957  
5958 my $cli = Venus::Cli->new(name => 'mycli');
5959  
5960 my $handler_called = 0;
5961 my $handler_args;
5962  
5963 $cli->command('command', ['user', 'create'], sub {
5964 my ($self, $args, $opts) = @_;
5965 $handler_called = 1;
5966 $handler_args = [$args, $opts];
5967 return 'handler result';
5968 });
5969  
5970 my $dispatch = $cli->dispatch('user', 'create');
5971  
5972 # "handler result"
5973  
5974 =back
5975  
5976 =over 4
5977  
5978 =item dispatch example 4
5979  
5980 package main;
5981  
5982 use Venus::Cli;
5983  
5984 my $cli = Venus::Cli->new(name => 'mycli');
5985  
5986 $cli->command('command', ['user', 'create'], sub {'user_create'});
5987 $cli->command('command', ['user', 'delete'], sub {'user_delete'});
5988 $cli->command('command', ['user'], sub {'user'});
5989  
5990 my $dispatch = $cli->dispatch('user', 'create');
5991  
5992 # "user_create"
5993  
5994 =back
5995  
5996 =over 4
5997  
5998 =item dispatch example 5
5999  
6000 package main;
6001  
6002 use Venus::Cli;
6003  
6004 my $cli = Venus::Cli->new(name => 'mycli');
6005  
6006 $cli->command('command', ['user', 'create'], sub {'user_create'});
6007 $cli->command('command', ['user', 'delete'], sub {'user_delete'});
6008 $cli->command('command', ['user'], sub {'user'});
6009  
6010 my $dispatch = $cli->dispatch('user');
6011  
6012 # "user"
6013  
6014 =back
6015  
6016 =over 4
6017  
6018 =item dispatch example 6
6019  
6020 package main;
6021  
6022 use Venus::Cli;
6023  
6024 my $cli = Venus::Cli->new(name => 'mycli');
6025  
6026 $cli->command('command', ['user', 'create'], sub {'user_create'});
6027 $cli->command('command', ['user', 'delete'], sub {'user_delete'});
6028 $cli->command('command', ['user'], sub {'user'});
6029  
6030 my $dispatch = $cli->dispatch('user', 'delete');
6031  
6032 # "user_delete"
6033  
6034 =back
6035  
6036 =over 4
6037  
6038 =item dispatch example 7
6039  
6040 package main;
6041  
6042 use Venus::Cli;
6043  
6044 my $cli = Venus::Cli->new(name => 'mycli');
6045  
6046 $cli->option('verbose', {
6047 type => 'boolean',
6048 alias => 'v',
6049 });
6050  
6051 $cli->command('command', ['user', 'create'], sub {
6052 my ($self, $args, $opts) = @_;
6053 return $opts->{verbose} ? 'verbose' : 'quiet';
6054 });
6055  
6056 my $dispatch = $cli->dispatch('user', 'create', '--verbose');
6057  
6058 # "verbose"
6059  
6060 =back
6061  
6062 =over 4
6063  
6064 =item dispatch example 8
6065  
6066 package main;
6067  
6068 use Venus::Cli;
6069  
6070 my $cli = Venus::Cli->new(name => 'mycli');
6071  
6072 $cli->command('command', ['unknown'], sub {'unknown'});
6073  
6074 my $dispatch = $cli->dispatch('other');
6075  
6076 # undef (no matching route)
6077  
6078 =back
6079  
6080 =cut
6081  
6082 =head2 exit
6083  
6084 exit(number $expr, string | coderef $code, any @args) (any)
6085  
6086 The exit method terminates the program with a specified exit code. If no exit
6087 code is provided, it defaults to C<0>, indicating a successful exit. This
6088 method can be used to end the program explicitly, either after a specific task
6089 is completed or when an error occurs that requires halting execution. This
6090 method can dispatch to another method or callback before exiting.
6091  
6092 I<Since C<4.15>>
6093  
6094 =over 4
6095  
6096 =item exit example 1
6097  
6098 package main;
6099  
6100 use Venus::Cli;
6101  
6102 my $cli = Venus::Cli->new(name => 'mycli');
6103  
6104 $cli->exit;
6105  
6106 # 0
6107  
6108 =back
6109  
6110 =over 4
6111  
6112 =item exit example 2
6113  
6114 package main;
6115  
6116 use Venus::Cli;
6117  
6118 my $cli = Venus::Cli->new(name => 'mycli');
6119  
6120 $cli->exit(1);
6121  
6122 # 1
6123  
6124 =back
6125  
6126 =over 4
6127  
6128 =item exit example 3
6129  
6130 package main;
6131  
6132 use Venus::Cli;
6133  
6134 my $cli = Venus::Cli->new(name => 'mycli');
6135  
6136 $cli->exit(5, sub{
6137 $cli->{dispatched} = 1;
6138 });
6139  
6140 # 5
6141  
6142 =back
6143  
6144 =cut
6145  
6146 =head2 fail
6147  
6148 fail(string | coderef $code, any @args) (any)
6149  
6150 The fail method terminates the program with a the exit code C<1>, indicating a
6151 failure on exit. This method can be used to end the program explicitly, either
6152 after a specific task is completed or when an error occurs that requires
6153 halting execution. This method can dispatch to another method or callback
6154 before exiting.
6155  
6156 I<Since C<4.15>>
6157  
6158 =over 4
6159  
6160 =item fail example 1
6161  
6162 package main;
6163  
6164 use Venus::Cli;
6165  
6166 my $cli = Venus::Cli->new(name => 'mycli');
6167  
6168 $cli->fail;
6169  
6170 # 1
6171  
6172 =back
6173  
6174 =over 4
6175  
6176 =item fail example 2
6177  
6178 package main;
6179  
6180 use Venus::Cli;
6181  
6182 my $cli = Venus::Cli->new(name => 'mycli');
6183  
6184 $cli->fail(sub{
6185 $cli->{dispatched} = 1;
6186 });
6187  
6188 # 1
6189  
6190 =back
6191  
6192 =cut
6193  
6194 =head2 float
6195  
6196 float(string $method, any @args) (any)
6197  
6198 The float method is a configuration dispatcher and shorthand for C<{'type',
6199 'float'}>. It returns the data or dispatches to the next configuration
6200 dispatcher based on the name provided and merges the configurations produced.
6201  
6202 I<Since C<4.15>>
6203  
6204 =over 4
6205  
6206 =item float example 1
6207  
6208 # given: synopsis
6209  
6210 package main;
6211  
6212 my $float = $cli->float;
6213  
6214 # {type => 'float'}
6215  
6216 =back
6217  
6218 =over 4
6219  
6220 =item float example 2
6221  
6222 # given: synopsis
6223  
6224 package main;
6225  
6226 my $float = $cli->float(undef, {required => true});
6227  
6228 # {type => 'float', required => true}
6229  
6230 =back
6231  
6232 =over 4
6233  
6234 =item float example 3
6235  
6236 # given: synopsis
6237  
6238 package main;
6239  
6240 my $float = $cli->float('option', 'example');
6241  
6242 # {
6243 # name => 'example',
6244 # label => undef,
6245 # help => 'Expects a float value',
6246 # default => undef,
6247 # aliases => [],
6248 # multiples => 0,
6249 # prompt => undef,
6250 # range => undef,
6251 # required => 1,
6252 # type => 'float',
6253 # index => 0,
6254 # wants => 'float',
6255 # }
6256  
6257 =back
6258  
6259 =cut
6260  
6261 =head2 has_input
6262  
6263 has_input() (boolean)
6264  
6265 The has_input method returns true if input arguments and/or options are found,
6266 and otherwise returns false.
6267  
6268 I<Since C<4.15>>
6269  
6270 =over 4
6271  
6272 =item has_input example 1
6273  
6274 # given: synopsis
6275  
6276 package main;
6277  
6278 $cli->option('input', {
6279 type => 'string',
6280 });
6281  
6282 $cli->option('output', {
6283 type => 'string',
6284 });
6285  
6286 my $has_input = $cli->has_input;
6287  
6288 # false
6289  
6290 =back
6291  
6292 =over 4
6293  
6294 =item has_input example 2
6295  
6296 # given: synopsis
6297  
6298 package main;
6299  
6300 $cli->option('input', {
6301 type => 'string',
6302 });
6303  
6304 $cli->option('output', {
6305 type => 'string',
6306 });
6307  
6308 $cli->parse('--input', 'stdin');
6309  
6310 my $has_input = $cli->has_input;
6311  
6312 # true
6313  
6314 =back
6315  
6316 =cut
6317  
6318 =head2 has_input_arguments
6319  
6320 has_input_arguments() (boolean)
6321  
6322 The has_input_arguments method returns true if input arguments are found, and
6323 otherwise returns false.
6324  
6325 I<Since C<4.15>>
6326  
6327 =over 4
6328  
6329 =item has_input_arguments example 1
6330  
6331 # given: synopsis
6332  
6333 package main;
6334  
6335 $cli->argument('args', {
6336 range => '0:',
6337 type => 'string',
6338 });
6339  
6340 $cli->option('input', {
6341 type => 'string',
6342 });
6343  
6344 $cli->option('output', {
6345 type => 'string',
6346 });
6347  
6348 my $has_input_arguments = $cli->has_input_arguments;
6349  
6350 # false
6351  
6352 =back
6353  
6354 =over 4
6355  
6356 =item has_input_arguments example 2
6357  
6358 # given: synopsis
6359  
6360 package main;
6361  
6362 $cli->argument('args', {
6363 range => '0:',
6364 type => 'string',
6365 });
6366  
6367 $cli->option('input', {
6368 type => 'string',
6369 });
6370  
6371 $cli->option('output', {
6372 type => 'string',
6373 });
6374  
6375 $cli->parse('example');
6376  
6377 my $has_input_arguments = $cli->has_input_arguments;
6378  
6379 # true
6380  
6381 =back
6382  
6383 =cut
6384  
6385 =head2 has_input_options
6386  
6387 has_input_options() (boolean)
6388  
6389 The has_input_options method returns true if input options are found, and
6390 otherwise returns false.
6391  
6392 I<Since C<4.15>>
6393  
6394 =over 4
6395  
6396 =item has_input_options example 1
6397  
6398 # given: synopsis
6399  
6400 package main;
6401  
6402 $cli->argument('args', {
6403 range => '0:',
6404 type => 'string',
6405 });
6406  
6407 $cli->option('input', {
6408 type => 'string',
6409 });
6410  
6411 $cli->option('output', {
6412 type => 'string',
6413 });
6414  
6415 my $has_input_options = $cli->has_input_options;
6416  
6417 # false
6418  
6419 =back
6420  
6421 =over 4
6422  
6423 =item has_input_options example 2
6424  
6425 # given: synopsis
6426  
6427 package main;
6428  
6429 $cli->argument('args', {
6430 range => '0:',
6431 type => 'string',
6432 });
6433  
6434 $cli->option('input', {
6435 type => 'string',
6436 });
6437  
6438 $cli->option('output', {
6439 type => 'string',
6440 });
6441  
6442 $cli->parse('--input', 'stdout');
6443  
6444 my $has_input_options = $cli->has_input_options;
6445  
6446 # true
6447  
6448 =back
6449  
6450 =cut
6451  
6452 =head2 has_output
6453  
6454 has_output() (boolean)
6455  
6456 The has_output method returns true if output events are found, and otherwise
6457 returns false.
6458  
6459 I<Since C<4.15>>
6460  
6461 =over 4
6462  
6463 =item has_output example 1
6464  
6465 # given: synopsis
6466  
6467 package main;
6468  
6469 $cli->argument('args', {
6470 range => '0:',
6471 type => 'string',
6472 });
6473  
6474 $cli->option('input', {
6475 type => 'string',
6476 });
6477  
6478 $cli->option('output', {
6479 type => 'string',
6480 });
6481  
6482 my $has_output = $cli->has_output;
6483  
6484 # false
6485  
6486 =back
6487  
6488 =over 4
6489  
6490 =item has_output example 2
6491  
6492 # given: synopsis
6493  
6494 package main;
6495  
6496 $cli->argument('args', {
6497 range => '0:',
6498 type => 'string',
6499 });
6500  
6501 $cli->option('input', {
6502 type => 'string',
6503 });
6504  
6505 $cli->option('output', {
6506 type => 'string',
6507 });
6508  
6509 $cli->log_info('example output');
6510  
6511 my $has_output = $cli->has_output;
6512  
6513 # true
6514  
6515 =back
6516  
6517 =cut
6518  
6519 =head2 has_output_debug_events
6520  
6521 has_output_debug_events() (boolean)
6522  
6523 The has_output_debug_events method returns true if debug output events are
6524 found, and otherwise returns false.
6525  
6526 I<Since C<4.15>>
6527  
6528 =over 4
6529  
6530 =item has_output_debug_events example 1
6531  
6532 # given: synopsis
6533  
6534 package main;
6535  
6536 $cli->argument('args', {
6537 range => '0:',
6538 type => 'string',
6539 });
6540  
6541 $cli->option('input', {
6542 type => 'string',
6543 });
6544  
6545 $cli->option('output', {
6546 type => 'string',
6547 });
6548  
6549 $cli->log_info('example output');
6550  
6551 my $has_output_debug_events = $cli->has_output_debug_events;
6552  
6553 # false
6554  
6555 =back
6556  
6557 =over 4
6558  
6559 =item has_output_debug_events example 2
6560  
6561 # given: synopsis
6562  
6563 package main;
6564  
6565 $cli->argument('args', {
6566 range => '0:',
6567 type => 'string',
6568 });
6569  
6570 $cli->option('input', {
6571 type => 'string',
6572 });
6573  
6574 $cli->option('output', {
6575 type => 'string',
6576 });
6577  
6578 $cli->log_debug('example output');
6579  
6580 my $has_output_debug_events = $cli->has_output_debug_events;
6581  
6582 # true
6583  
6584 =back
6585  
6586 =cut
6587  
6588 =head2 has_output_error_events
6589  
6590 has_output_error_events() (boolean)
6591  
6592 The has_output_error_events method returns true if error output events are
6593 found, and otherwise returns false.
6594  
6595 I<Since C<4.15>>
6596  
6597 =over 4
6598  
6599 =item has_output_error_events example 1
6600  
6601 # given: synopsis
6602  
6603 package main;
6604  
6605 $cli->option('input', {
6606 type => 'string',
6607 });
6608  
6609 $cli->option('output', {
6610 type => 'string',
6611 });
6612  
6613 $cli->log_info('example output');
6614  
6615 my $has_output_error_events = $cli->has_output_error_events;
6616  
6617 # false
6618  
6619 =back
6620  
6621 =over 4
6622  
6623 =item has_output_error_events example 2
6624  
6625 # given: synopsis
6626  
6627 package main;
6628  
6629 $cli->option('input', {
6630 type => 'string',
6631 });
6632  
6633 $cli->option('output', {
6634 type => 'string',
6635 });
6636  
6637 $cli->log_error('example output');
6638  
6639 my $has_output_error_events = $cli->has_output_error_events;
6640  
6641 # true
6642  
6643 =back
6644  
6645 =cut
6646  
6647 =head2 has_output_fatal_events
6648  
6649 has_output_fatal_events() (boolean)
6650  
6651 The has_output_fatal_events method returns true if fatal output events are
6652 found, and otherwise returns false.
6653  
6654 I<Since C<4.15>>
6655  
6656 =over 4
6657  
6658 =item has_output_fatal_events example 1
6659  
6660 # given: synopsis
6661  
6662 package main;
6663  
6664 $cli->option('input', {
6665 type => 'string',
6666 });
6667  
6668 $cli->option('output', {
6669 type => 'string',
6670 });
6671  
6672 $cli->log_info('example output');
6673  
6674 my $has_output_fatal_events = $cli->has_output_fatal_events;
6675  
6676 # false
6677  
6678 =back
6679  
6680 =over 4
6681  
6682 =item has_output_fatal_events example 2
6683  
6684 # given: synopsis
6685  
6686 package main;
6687  
6688 $cli->option('input', {
6689 type => 'string',
6690 });
6691  
6692 $cli->option('output', {
6693 type => 'string',
6694 });
6695  
6696 $cli->log_fatal('example output');
6697  
6698 my $has_output_fatal_events = $cli->has_output_fatal_events;
6699  
6700 # true
6701  
6702 =back
6703  
6704 =cut
6705  
6706 =head2 has_output_info_events
6707  
6708 has_output_info_events() (boolean)
6709  
6710 The has_output_info_events method returns true if info output events are found,
6711 and otherwise returns false.
6712  
6713 I<Since C<4.15>>
6714  
6715 =over 4
6716  
6717 =item has_output_info_events example 1
6718  
6719 # given: synopsis
6720  
6721 package main;
6722  
6723 $cli->option('input', {
6724 type => 'string',
6725 });
6726  
6727 $cli->option('output', {
6728 type => 'string',
6729 });
6730  
6731 $cli->log_info('example output');
6732  
6733 my $has_output_info_events = $cli->has_output_info_events;
6734  
6735 # true
6736  
6737 =back
6738  
6739 =over 4
6740  
6741 =item has_output_info_events example 2
6742  
6743 # given: synopsis
6744  
6745 package main;
6746  
6747 $cli->option('input', {
6748 type => 'string',
6749 });
6750  
6751 $cli->option('output', {
6752 type => 'string',
6753 });
6754  
6755 $cli->log_error('example output');
6756  
6757 my $has_output_info_events = $cli->has_output_info_events;
6758  
6759 # false
6760  
6761 =back
6762  
6763 =cut
6764  
6765 =head2 has_output_trace_events
6766  
6767 has_output_trace_events() (boolean)
6768  
6769 The has_output_trace_events method returns true if trace output events are
6770 found, and otherwise returns false.
6771  
6772 I<Since C<4.15>>
6773  
6774 =over 4
6775  
6776 =item has_output_trace_events example 1
6777  
6778 # given: synopsis
6779  
6780 package main;
6781  
6782 $cli->option('input', {
6783 type => 'string',
6784 });
6785  
6786 $cli->option('output', {
6787 type => 'string',
6788 });
6789  
6790 $cli->log_info('example output');
6791  
6792 my $has_output_trace_events = $cli->has_output_trace_events;
6793  
6794 # false
6795  
6796 =back
6797  
6798 =over 4
6799  
6800 =item has_output_trace_events example 2
6801  
6802 # given: synopsis
6803  
6804 package main;
6805  
6806 $cli->option('input', {
6807 type => 'string',
6808 });
6809  
6810 $cli->option('output', {
6811 type => 'string',
6812 });
6813  
6814 $cli->log_trace('example output');
6815  
6816 my $has_output_trace_events = $cli->has_output_trace_events;
6817  
6818 # true
6819  
6820 =back
6821  
6822 =cut
6823  
6824 =head2 has_output_warn_events
6825  
6826 has_output_warn_events() (boolean)
6827  
6828 The has_output_warn_events method returns true if warn output events are found,
6829 and otherwise returns false.
6830  
6831 I<Since C<4.15>>
6832  
6833 =over 4
6834  
6835 =item has_output_warn_events example 1
6836  
6837 # given: synopsis
6838  
6839 package main;
6840  
6841 $cli->option('input', {
6842 type => 'string',
6843 });
6844  
6845 $cli->option('output', {
6846 type => 'string',
6847 });
6848  
6849 $cli->log_info('example output');
6850  
6851 my $has_output_warn_events = $cli->has_output_warn_events;
6852  
6853 # false
6854  
6855 =back
6856  
6857 =over 4
6858  
6859 =item has_output_warn_events example 2
6860  
6861 # given: synopsis
6862  
6863 package main;
6864  
6865 $cli->option('input', {
6866 type => 'string',
6867 });
6868  
6869 $cli->option('output', {
6870 type => 'string',
6871 });
6872  
6873 $cli->log_warn('example output');
6874  
6875 my $has_output_warn_events = $cli->has_output_warn_events;
6876  
6877 # true
6878  
6879 =back
6880  
6881 =cut
6882  
6883 =head2 help
6884  
6885 help() (Venus::Cli)
6886  
6887 The help method uses L</log_info> method to output CLI usage/help text.
6888  
6889 I<Since C<4.15>>
6890  
6891 =over 4
6892  
6893 =item help example 1
6894  
6895 # given: synopsis
6896  
6897 package main;
6898  
6899 $cli->option('input', {
6900 type => 'string',
6901 });
6902  
6903 $cli->option('output', {
6904 type => 'string',
6905 });
6906  
6907 my $help = $cli->help;
6908  
6909 # bless(..., "Venus::Cli")
6910  
6911 =back
6912  
6913 =cut
6914  
6915 =head2 input
6916  
6917 input() (hashref)
6918  
6919 The input method returns input arguments in scalar context, and returns
6920 arguments and options in list context. Arguments and options are returned as
6921 hashrefs.
6922  
6923 I<Since C<4.15>>
6924  
6925 =over 4
6926  
6927 =item input example 1
6928  
6929 # given: synopsis
6930  
6931 package main;
6932  
6933 $cli->argument('args', {
6934 range => '0:',
6935 type => 'string',
6936 });
6937  
6938 $cli->option('input', {
6939 type => 'string',
6940 });
6941  
6942 $cli->option('output', {
6943 type => 'string',
6944 });
6945  
6946 my $input = $cli->input;
6947  
6948 # {args => undef}
6949  
6950 =back
6951  
6952 =over 4
6953  
6954 =item input example 2
6955  
6956 # given: synopsis
6957  
6958 package main;
6959  
6960 $cli->argument('args', {
6961 range => '0:',
6962 multiples => 1,
6963 type => 'string',
6964 });
6965  
6966 $cli->option('input', {
6967 type => 'string',
6968 });
6969  
6970 $cli->option('output', {
6971 type => 'string',
6972 });
6973  
6974 $cli->parse('arg1', 'arg2');
6975  
6976 my $input = $cli->input;
6977  
6978 # {args => ['arg1', 'arg2']}
6979  
6980 =back
6981  
6982 =cut
6983  
6984 =head2 input_argument_count
6985  
6986 input_argument_count() (number)
6987  
6988 The input_argument_count method returns the number of arguments provided to the
6989 CLI.
6990  
6991 I<Since C<4.15>>
6992  
6993 =over 4
6994  
6995 =item input_argument_count example 1
6996  
6997 # given: synopsis
6998  
6999 package main;
7000  
7001 $cli->argument('args', {
7002 range => '0:',
7003 multiples => 1,
7004 type => 'string',
7005 });
7006  
7007 $cli->option('input', {
7008 type => 'string',
7009 });
7010  
7011 $cli->option('output', {
7012 type => 'string',
7013 });
7014  
7015 my $input_argument_count = $cli->input_argument_count;
7016  
7017 # 1
7018  
7019 =back
7020  
7021 =over 4
7022  
7023 =item input_argument_count example 2
7024  
7025 # given: synopsis
7026  
7027 package main;
7028  
7029 $cli->argument('args', {
7030 range => '0:',
7031 multiples => 1,
7032 type => 'string',
7033 });
7034  
7035 $cli->option('input', {
7036 type => 'string',
7037 });
7038  
7039 $cli->option('output', {
7040 type => 'string',
7041 });
7042  
7043 $cli->parse('arg1', 'arg2');
7044  
7045 my $input_argument_count = $cli->input_argument_count;
7046  
7047 # 1
7048  
7049 =back
7050  
7051 =cut
7052  
7053 =head2 input_argument_list
7054  
7055 input_argument_list() (arrayref)
7056  
7057 The input_argument_list method returns the list of argument names as an
7058 arrayref in scalar context, and as a list in list context.
7059  
7060 I<Since C<4.15>>
7061  
7062 =over 4
7063  
7064 =item input_argument_list example 1
7065  
7066 # given: synopsis
7067  
7068 package main;
7069  
7070 $cli->argument('args', {
7071 range => '0:',
7072 multiples => 1,
7073 type => 'string',
7074 });
7075  
7076 $cli->option('input', {
7077 type => 'string',
7078 });
7079  
7080 $cli->option('output', {
7081 type => 'string',
7082 });
7083  
7084 my $input_argument_list = $cli->input_argument_list;
7085  
7086 # ['args']
7087  
7088 =back
7089  
7090 =over 4
7091  
7092 =item input_argument_list example 2
7093  
7094 # given: synopsis
7095  
7096 package main;
7097  
7098 $cli->argument('args', {
7099 range => '0:',
7100 multiples => 1,
7101 type => 'string',
7102 });
7103  
7104 $cli->option('input', {
7105 type => 'string',
7106 });
7107  
7108 $cli->option('output', {
7109 type => 'string',
7110 });
7111  
7112 my @input_argument_list = $cli->input_argument_list;
7113  
7114 # ('args')
7115  
7116 =back
7117  
7118 =cut
7119  
7120 =head2 input_arguments
7121  
7122 input_arguments() (hashref)
7123  
7124 The input_arguments method returns the list of argument names and values as a
7125 hashref.
7126  
7127 I<Since C<4.15>>
7128  
7129 =over 4
7130  
7131 =item input_arguments example 1
7132  
7133 # given: synopsis
7134  
7135 package main;
7136  
7137 $cli->argument('args', {
7138 range => '0:',
7139 multiples => 1,
7140 type => 'string',
7141 });
7142  
7143 $cli->option('input', {
7144 type => 'string',
7145 });
7146  
7147 $cli->option('output', {
7148 type => 'string',
7149 });
7150  
7151 my $input_arguments = $cli->input_arguments;
7152  
7153 # {args => []}
7154  
7155 =back
7156  
7157 =over 4
7158  
7159 =item input_arguments example 2
7160  
7161 # given: synopsis
7162  
7163 package main;
7164  
7165 $cli->argument('args', {
7166 range => '0:',
7167 multiples => 1,
7168 type => 'string',
7169 });
7170  
7171 $cli->option('input', {
7172 type => 'string',
7173 });
7174  
7175 $cli->option('output', {
7176 type => 'string',
7177 });
7178  
7179 $cli->parse('arg1', 'arg2');
7180  
7181 my $input_arguments = $cli->input_arguments;
7182  
7183 # {args => ['arg1', 'arg2']}
7184  
7185 =back
7186  
7187 =cut
7188  
7189 =head2 input_arguments_defined
7190  
7191 input_arguments_defined() (hashref)
7192  
7193 The input_arguments_defined method returns the list of argument names and
7194 values as a hashref, excluding undefined and empty arrayref values.
7195  
7196 I<Since C<4.15>>
7197  
7198 =over 4
7199  
7200 =item input_arguments_defined example 1
7201  
7202 # given: synopsis
7203  
7204 package main;
7205  
7206 $cli->argument('args', {
7207 range => '0:',
7208 multiples => 1,
7209 type => 'string',
7210 });
7211  
7212 $cli->option('input', {
7213 type => 'string',
7214 });
7215  
7216 $cli->option('output', {
7217 type => 'string',
7218 });
7219  
7220 my $input_arguments_defined = $cli->input_arguments_defined;
7221  
7222 # {}
7223  
7224 =back
7225  
7226 =over 4
7227  
7228 =item input_arguments_defined example 2
7229  
7230 # given: synopsis
7231  
7232 package main;
7233  
7234 $cli->argument('args', {
7235 range => '0:',
7236 multiples => 1,
7237 type => 'string',
7238 });
7239  
7240 $cli->option('input', {
7241 type => 'string',
7242 });
7243  
7244 $cli->option('output', {
7245 type => 'string',
7246 });
7247  
7248 $cli->parse('arg1', 'arg2');
7249  
7250 my $input_arguments_defined = $cli->input_arguments_defined;
7251  
7252 # {args => ['arg1', 'arg2']}
7253  
7254 =back
7255  
7256 =cut
7257  
7258 =head2 input_arguments_defined_count
7259  
7260 input_arguments_defined_count() (number)
7261  
7262 The input_arguments_defined_count method returns the number of arguments found
7263 using L</input_arguments_defined>.
7264  
7265 I<Since C<4.15>>
7266  
7267 =over 4
7268  
7269 =item input_arguments_defined_count example 1
7270  
7271 # given: synopsis
7272  
7273 package main;
7274  
7275 $cli->argument('args', {
7276 range => '0:',
7277 multiples => 1,
7278 type => 'string',
7279 });
7280  
7281 $cli->option('input', {
7282 type => 'string',
7283 });
7284  
7285 $cli->option('output', {
7286 type => 'string',
7287 });
7288  
7289 my $input_arguments_defined_count = $cli->input_arguments_defined_count;
7290  
7291 # 0
7292  
7293 =back
7294  
7295 =over 4
7296  
7297 =item input_arguments_defined_count example 2
7298  
7299 # given: synopsis
7300  
7301 package main;
7302  
7303 $cli->argument('args', {
7304 range => '0:',
7305 multiples => 1,
7306 type => 'string',
7307 });
7308  
7309 $cli->option('input', {
7310 type => 'string',
7311 });
7312  
7313 $cli->option('output', {
7314 type => 'string',
7315 });
7316  
7317 $cli->parse('arg1', 'arg2');
7318  
7319 my $input_arguments_defined_count = $cli->input_arguments_defined_count;
7320  
7321 # 1
7322  
7323 =back
7324  
7325 =cut
7326  
7327 =head2 input_arguments_defined_list
7328  
7329 input_arguments_defined_list() (arrayref)
7330  
7331 The input_arguments_defined_list method returns the list of argument names
7332 found, using L</input_arguments_defined>, as an arrayref in scalar context, and
7333 as a list in list context.
7334  
7335 I<Since C<4.15>>
7336  
7337 =over 4
7338  
7339 =item input_arguments_defined_list example 1
7340  
7341 # given: synopsis
7342  
7343 package main;
7344  
7345 $cli->argument('args', {
7346 range => '0:',
7347 multiples => 1,
7348 type => 'string',
7349 });
7350  
7351 $cli->option('input', {
7352 type => 'string',
7353 });
7354  
7355 $cli->option('output', {
7356 type => 'string',
7357 });
7358  
7359 my $input_arguments_defined_list = $cli->input_arguments_defined_list;
7360  
7361 # []
7362  
7363 =back
7364  
7365 =over 4
7366  
7367 =item input_arguments_defined_list example 2
7368  
7369 # given: synopsis
7370  
7371 package main;
7372  
7373 $cli->argument('args', {
7374 range => '0:',
7375 multiples => 1,
7376 type => 'string',
7377 });
7378  
7379 $cli->option('input', {
7380 type => 'string',
7381 });
7382  
7383 $cli->option('output', {
7384 type => 'string',
7385 });
7386  
7387 $cli->parse('arg1', 'arg2');
7388  
7389 my $input_arguments_defined_list = $cli->input_arguments_defined_list;
7390  
7391 # ['args']
7392  
7393 =back
7394  
7395 =cut
7396  
7397 =head2 input_option_count
7398  
7399 input_option_count() (number)
7400  
7401 The input_option_count method returns the number of options provided to the
7402 CLI.
7403  
7404 I<Since C<4.15>>
7405  
7406 =over 4
7407  
7408 =item input_option_count example 1
7409  
7410 # given: synopsis
7411  
7412 package main;
7413  
7414 $cli->option('input', {
7415 type => 'string',
7416 });
7417  
7418 $cli->option('output', {
7419 type => 'string',
7420 });
7421  
7422 my $input_option_count = $cli->input_option_count;
7423  
7424 # 2
7425  
7426 =back
7427  
7428 =over 4
7429  
7430 =item input_option_count example 2
7431  
7432 # given: synopsis
7433  
7434 package main;
7435  
7436 $cli->option('input', {
7437 type => 'string',
7438 });
7439  
7440 $cli->option('output', {
7441 type => 'string',
7442 });
7443  
7444 $cli->parse('--input', 'stdin');
7445  
7446 my $input_option_count = $cli->input_option_count;
7447  
7448 # 2
7449  
7450 =back
7451  
7452 =cut
7453  
7454 =head2 input_option_list
7455  
7456 input_option_list() (arrayref)
7457  
7458 The input_option_list method returns the list of option names as an arrayref in
7459 scalar context, and as a list in list context.
7460  
7461 I<Since C<4.15>>
7462  
7463 =over 4
7464  
7465 =item input_option_list example 1
7466  
7467 # given: synopsis
7468  
7469 package main;
7470  
7471 $cli->option('input', {
7472 type => 'string',
7473 });
7474  
7475 $cli->option('output', {
7476 type => 'string',
7477 });
7478  
7479 my $input_option_list = $cli->input_option_list;
7480  
7481 # ['input', 'output']
7482  
7483 =back
7484  
7485 =over 4
7486  
7487 =item input_option_list example 2
7488  
7489 # given: synopsis
7490  
7491 package main;
7492  
7493 $cli->option('input', {
7494 type => 'string',
7495 });
7496  
7497 $cli->option('output', {
7498 type => 'string',
7499 });
7500  
7501 $cli->parse('--input', 'stdin', '--output', 'stdout');
7502  
7503 my $input_option_list = $cli->input_option_list;
7504  
7505 # ['input', 'output']
7506  
7507 =back
7508  
7509 =cut
7510  
7511 =head2 input_options
7512  
7513 input_options() (hashref)
7514  
7515 The input_options method returns the list of option names and values as a
7516 hashref.
7517  
7518 I<Since C<4.15>>
7519  
7520 =over 4
7521  
7522 =item input_options example 1
7523  
7524 # given: synopsis
7525  
7526 package main;
7527  
7528 $cli->option('input', {
7529 type => 'string',
7530 });
7531  
7532 $cli->option('output', {
7533 type => 'string',
7534 });
7535  
7536 my $input_options = $cli->input_options;
7537  
7538 # {input => undef, output => undef}
7539  
7540 =back
7541  
7542 =over 4
7543  
7544 =item input_options example 2
7545  
7546 # given: synopsis
7547  
7548 package main;
7549  
7550 $cli->option('input', {
7551 type => 'string',
7552 });
7553  
7554 $cli->option('output', {
7555 type => 'string',
7556 });
7557  
7558 $cli->parse('--input', 'stdin', '--output', 'stdout');
7559  
7560 my $input_options = $cli->input_options;
7561  
7562 # {input => undef, output => undef}
7563  
7564 =back
7565  
7566 =cut
7567  
7568 =head2 input_options_defined
7569  
7570 input_options_defined() (hashref)
7571  
7572 The input_options_defined method returns the list of option names and values as
7573 a hashref, excluding undefined and empty arrayref values.
7574  
7575 I<Since C<4.15>>
7576  
7577 =over 4
7578  
7579 =item input_options_defined example 1
7580  
7581 # given: synopsis
7582  
7583 package main;
7584  
7585 $cli->option('input', {
7586 type => 'string',
7587 });
7588  
7589 $cli->option('output', {
7590 type => 'string',
7591 });
7592  
7593 my $input_options_defined = $cli->input_options_defined;
7594  
7595 # {}
7596  
7597 =back
7598  
7599 =over 4
7600  
7601 =item input_options_defined example 2
7602  
7603 # given: synopsis
7604  
7605 package main;
7606  
7607 $cli->option('input', {
7608 type => 'string',
7609 });
7610  
7611 $cli->option('output', {
7612 type => 'string',
7613 });
7614  
7615 $cli->parse('--input', 'stdin', '--output', 'stdout');
7616  
7617 my $input_options_defined = $cli->input_options_defined;
7618  
7619 # {input => 'stdin', output => 'stdout'}
7620  
7621 =back
7622  
7623 =cut
7624  
7625 =head2 input_options_defined_count
7626  
7627 input_options_defined_count() (number)
7628  
7629 The input_options_defined_count method returns the number of options found
7630 using L</input_options_defined>.
7631  
7632 I<Since C<4.15>>
7633  
7634 =over 4
7635  
7636 =item input_options_defined_count example 1
7637  
7638 # given: synopsis
7639  
7640 package main;
7641  
7642 $cli->option('input', {
7643 type => 'string',
7644 });
7645  
7646 $cli->option('output', {
7647 type => 'string',
7648 });
7649  
7650 my $input_options_defined_count = $cli->input_options_defined_count;
7651  
7652 # 0
7653  
7654 =back
7655  
7656 =over 4
7657  
7658 =item input_options_defined_count example 2
7659  
7660 # given: synopsis
7661  
7662 package main;
7663  
7664 $cli->option('input', {
7665 type => 'string',
7666 });
7667  
7668 $cli->option('output', {
7669 type => 'string',
7670 });
7671  
7672 $cli->parse('--input', 'stdin', '--output', 'stdout');
7673  
7674 my $input_options_defined_count = $cli->input_options_defined_count;
7675  
7676 # 2
7677  
7678 =back
7679  
7680 =cut
7681  
7682 =head2 input_options_defined_list
7683  
7684 input_options_defined_list() (arrayref)
7685  
7686 The input_options_defined_list method returns the list of option names found,
7687 using L</input_options_defined>, as an arrayref in scalar context, and as a
7688 list in list context.
7689  
7690 I<Since C<4.15>>
7691  
7692 =over 4
7693  
7694 =item input_options_defined_list example 1
7695  
7696 # given: synopsis
7697  
7698 package main;
7699  
7700 $cli->option('input', {
7701 type => 'string',
7702 });
7703  
7704 $cli->option('output', {
7705 type => 'string',
7706 });
7707  
7708 my $input_options_defined_list = $cli->input_options_defined_list;
7709  
7710 # []
7711  
7712 =back
7713  
7714 =over 4
7715  
7716 =item input_options_defined_list example 2
7717  
7718 # given: synopsis
7719  
7720 package main;
7721  
7722 $cli->option('input', {
7723 type => 'string',
7724 });
7725  
7726 $cli->option('output', {
7727 type => 'string',
7728 });
7729  
7730 $cli->parse('--input', 'stdin', '--output', 'stdout');
7731  
7732 my $input_options_defined_list = $cli->input_options_defined_list;
7733  
7734 # ['input', 'output']
7735  
7736 =back
7737  
7738 =over 4
7739  
7740 =item input_options_defined_list example 3
7741  
7742 # given: synopsis
7743  
7744 package main;
7745  
7746 $cli->option('input', {
7747 type => 'string',
7748 });
7749  
7750 $cli->option('output', {
7751 type => 'string',
7752 });
7753  
7754 $cli->parse('--output', 'stdout');
7755  
7756 my $input_options_defined_list = $cli->input_options_defined_list;
7757  
7758 # ['output']
7759  
7760 =back
7761  
7762 =cut
7763  
7764 =head2 lines
7765  
7766 lines(string $text, number $length, number $indent) (string)
7767  
7768 The lines method takes a string of text, a maximum character length for
7769 each line, and an optional number of spaces to use for indentation
7770 (defaulting to C<0>). It returns the text formatted as a string where each
7771 line wraps at the specified length and is indented with the given number
7772 of spaces. The default lenght is C<80>.
7773  
7774 I<Since C<4.15>>
7775  
7776 =over 4
7777  
7778 =item lines example 1
7779  
7780 package main;
7781  
7782 use Venus::Cli;
7783  
7784 my $cli = Venus::Cli->new(name => 'mycli');
7785  
7786 my $message = join(' ',
7787 'This is an example of a long line of text that needs',
7788 'to be wrapped and formatted.'
7789 );
7790  
7791 my $string = $cli->lines($message, 40, 2);
7792  
7793 # " This is an example of a long line of
7794 # text that needs to be wrapped and
7795 # formatted."
7796  
7797 =back
7798  
7799 =cut
7800  
7801 =head2 log
7802  
7803 log() (Venus::Log)
7804  
7805 The log method returns a L<Venus::Log> object passing L</log_handler> and
7806 L</log_level> to its constructor.
7807  
7808 I<Since C<4.15>>
7809  
7810 =over 4
7811  
7812 =item log example 1
7813  
7814 package main;
7815  
7816 use Venus::Cli;
7817  
7818 my $cli = Venus::Cli->new(name => 'mycli');
7819  
7820 my $log = $cli->log;
7821  
7822 # bless(..., "Venus::Log")
7823  
7824 =back
7825  
7826 =cut
7827  
7828 =head2 log_debug
7829  
7830 log_debug(any @args) (Venus::Log)
7831  
7832 The log_debug method dispatches to the C<debug> method on the object returned
7833 by L</log>.
7834  
7835 I<Since C<4.15>>
7836  
7837 =over 4
7838  
7839 =item log_debug example 1
7840  
7841 package main;
7842  
7843 use Venus::Cli;
7844  
7845 my $cli = Venus::Cli->new(name => 'mycli');
7846  
7847 my $log_debug = $cli->log_debug('Example debug');
7848  
7849 # bless(..., "Venus::Log")
7850  
7851 =back
7852  
7853 =cut
7854  
7855 =head2 log_error
7856  
7857 log_error(any @args) (Venus::Log)
7858  
7859 The log_error method dispatches to the C<error> method on the object returned
7860 by L</log>.
7861  
7862 I<Since C<4.15>>
7863  
7864 =over 4
7865  
7866 =item log_error example 1
7867  
7868 package main;
7869  
7870 use Venus::Cli;
7871  
7872 my $cli = Venus::Cli->new(name => 'mycli');
7873  
7874 my $log_error = $cli->log_error('Example error');
7875  
7876 # bless(..., "Venus::Log")
7877  
7878 =back
7879  
7880 =cut
7881  
7882 =head2 log_events
7883  
7884 log_events() (arrayref)
7885  
7886 The log_events method returns the log messages collected by the default
7887 L</log_handler>.
7888  
7889 I<Since C<4.15>>
7890  
7891 =over 4
7892  
7893 =item log_events example 1
7894  
7895 package main;
7896  
7897 use Venus::Cli;
7898  
7899 my $cli = Venus::Cli->new(name => 'mycli');
7900  
7901 $cli->log_debug('Example debug');
7902  
7903 $cli->log_error('Example error');
7904  
7905 my $log_events = $cli->log_events;
7906  
7907 # [['debug', 'Example debug'], ['debug', 'Example error']]
7908  
7909 =back
7910  
7911 =cut
7912  
7913 =head2 log_fatal
7914  
7915 log_fatal(any @args) (Venus::Log)
7916  
7917 The log_fatal method dispatches to the C<fatal> method on the object returned
7918 by L</log>.
7919  
7920 I<Since C<4.15>>
7921  
7922 =over 4
7923  
7924 =item log_fatal example 1
7925  
7926 package main;
7927  
7928 use Venus::Cli;
7929  
7930 my $cli = Venus::Cli->new(name => 'mycli');
7931  
7932 my $log_fatal = $cli->log_fatal('Example fatal');
7933  
7934 # bless(..., "Venus::Log")
7935  
7936 =back
7937  
7938 =cut
7939  
7940 =head2 log_flush
7941  
7942 log_flush(string | coderef $code) (Venus::Cli)
7943  
7944 The log_flush method dispatches to the method or callback provided for each
7945 L<"log event"|/log_event>, then purges all log events.
7946  
7947 I<Since C<4.15>>
7948  
7949 =over 4
7950  
7951 =item log_flush example 1
7952  
7953 package main;
7954  
7955 use Venus::Cli;
7956  
7957 my $cli = Venus::Cli->new(name => 'mycli');
7958  
7959 $cli->log_debug('Example debug 1');
7960  
7961 $cli->log_debug('Example debug 2');
7962  
7963 my $log_flush = $cli->log_flush(sub{
7964 push @{$cli->{flushed} ||= []}, $_;
7965 });
7966  
7967 # bless(..., "Venus::Cli")
7968  
7969 =back
7970  
7971 =over 4
7972  
7973 =item log_flush example 2
7974  
7975 package main;
7976  
7977 use Venus::Cli;
7978  
7979 my $cli = Venus::Cli->new(name => 'mycli');
7980  
7981 $cli->log_debug('Example debug 1');
7982  
7983 $cli->log_debug('Example debug 2');
7984  
7985 my $log_flush = $cli->log_flush(sub{
7986 my ($self, $event) = @_;
7987 push @{$cli->{flushed} ||= []}, $event;
7988 });
7989  
7990 # bless(..., "Venus::Cli")
7991  
7992 =back
7993  
7994 =cut
7995  
7996 =head2 log_handler
7997  
7998 log_handler() (coderef)
7999  
8000 The log_handler method is passed to the L<Venus::Log> constructor in L</log>
8001 and by default handles log events by recording them to be
8002 L<"flushed"|/log_flush> later.
8003  
8004 I<Since C<4.15>>
8005  
8006 =over 4
8007  
8008 =item log_handler example 1
8009  
8010 package main;
8011  
8012 use Venus::Cli;
8013  
8014 my $cli = Venus::Cli->new(name => 'mycli');
8015  
8016 my $log_handler = $cli->log_handler;
8017  
8018 # sub{...}
8019  
8020 =back
8021  
8022 =cut
8023  
8024 =head2 log_info
8025  
8026 log_info(any @args) (Venus::Log)
8027  
8028 The log_info method dispatches to the C<info> method on the object returned
8029 by L</log>.
8030  
8031 I<Since C<4.15>>
8032  
8033 =over 4
8034  
8035 =item log_info example 1
8036  
8037 package main;
8038  
8039 use Venus::Cli;
8040  
8041 my $cli = Venus::Cli->new(name => 'mycli');
8042  
8043 my $log_info = $cli->log_info('Example info');
8044  
8045 # bless(..., "Venus::Log")
8046  
8047 =back
8048  
8049 =cut
8050  
8051 =head2 log_level
8052  
8053 log_level() (string)
8054  
8055 The log_level method is passed to the L<Venus::Log> constructor in L</log> and
8056 by default specifies a log-level of C<debug>.
8057  
8058 I<Since C<4.15>>
8059  
8060 =over 4
8061  
8062 =item log_level example 1
8063  
8064 package main;
8065  
8066 use Venus::Cli;
8067  
8068 my $cli = Venus::Cli->new(name => 'mycli');
8069  
8070 my $log_level = $cli->log_level;
8071  
8072 # "trace"
8073  
8074 =back
8075  
8076 =cut
8077  
8078 =head2 log_trace
8079  
8080 log_trace(any @args) (Venus::Log)
8081  
8082 The log_trace method dispatches to the C<trace> method on the object returned
8083 by L</log>.
8084  
8085 I<Since C<4.15>>
8086  
8087 =over 4
8088  
8089 =item log_trace example 1
8090  
8091 package main;
8092  
8093 use Venus::Cli;
8094  
8095 my $cli = Venus::Cli->new(name => 'mycli');
8096  
8097 my $log_trace = $cli->log_trace('Example trace');
8098  
8099 # bless(..., "Venus::Log")
8100  
8101 =back
8102  
8103 =cut
8104  
8105 =head2 log_warn
8106  
8107 log_warn(any @args) (Venus::Log)
8108  
8109 The log_warn method dispatches to the C<warn> method on the object returned
8110 by L</log>.
8111  
8112 I<Since C<4.15>>
8113  
8114 =over 4
8115  
8116 =item log_warn example 1
8117  
8118 package main;
8119  
8120 use Venus::Cli;
8121  
8122 my $cli = Venus::Cli->new(name => 'mycli');
8123  
8124 my $log_warn = $cli->log_warn('Example warn');
8125  
8126 # bless(..., "Venus::Log")
8127  
8128 =back
8129  
8130 =cut
8131  
8132 =head2 multiple
8133  
8134 multiple(string $method, any @args) (any)
8135  
8136 The multiple method is a configuration dispatcher and shorthand for
8137 C<{'multiples', true}>. It returns the data or dispatches to the next
8138 configuration dispatcher based on the name provided and merges the
8139 configurations produced.
8140  
8141 I<Since C<4.15>>
8142  
8143 =over 4
8144  
8145 =item multiple example 1
8146  
8147 # given: synopsis
8148  
8149 package main;
8150  
8151 my $multiple = $cli->multiple;
8152  
8153 # {multiples => true}
8154  
8155 =back
8156  
8157 =over 4
8158  
8159 =item multiple example 2
8160  
8161 # given: synopsis
8162  
8163 package main;
8164  
8165 my $multiple = $cli->multiple(undef, {required => true});
8166  
8167 # {multiples => true, required => true}
8168  
8169 =back
8170  
8171 =over 4
8172  
8173 =item multiple example 3
8174  
8175 # given: synopsis
8176  
8177 package main;
8178  
8179 my $multiple = $cli->multiple('option', 'example');
8180  
8181 # {
8182 # name => 'example',
8183 # label => undef,
8184 # help => 'Expects a string value',
8185 # default => undef,
8186 # aliases => [],
8187 # multiples => 1,
8188 # prompt => undef,
8189 # range => undef,
8190 # required => 1,
8191 # type => 'string',
8192 # index => 0,
8193 # wants => 'string',
8194 # }
8195  
8196 =back
8197  
8198 =cut
8199  
8200 =head2 new
8201  
8202 new(any @args) (Venus::Cli)
8203  
8204 The new method constructs an instance of the package.
8205  
8206 I<Since C<4.15>>
8207  
8208 =over 4
8209  
8210 =item new example 1
8211  
8212 package main;
8213  
8214 use Venus::Cli;
8215  
8216 my $cli = Venus::Cli->new('mycli');
8217  
8218 # bless(..., "Venus::Cli")
8219  
8220 # $cli->name;
8221  
8222 # "mycli"
8223  
8224 =back
8225  
8226 =over 4
8227  
8228 =item new example 2
8229  
8230 package main;
8231  
8232 use Venus::Cli;
8233  
8234 my $cli = Venus::Cli->new(name => 'mycli');
8235  
8236 # bless(..., "Venus::Cli")
8237  
8238 # $cli->name;
8239  
8240 # "mycli"
8241  
8242 =back
8243  
8244 =cut
8245  
8246 =head2 no_input
8247  
8248 no_input() (boolean)
8249  
8250 The no_input method returns true if no arguments or options are provided to the
8251 CLI, and false otherwise.
8252  
8253 I<Since C<4.15>>
8254  
8255 =over 4
8256  
8257 =item no_input example 1
8258  
8259 # given: synopsis
8260  
8261 package main;
8262  
8263 $cli->option('input', {
8264 type => 'string',
8265 });
8266  
8267 $cli->option('output', {
8268 type => 'string',
8269 });
8270  
8271 my $no_input = $cli->no_input;
8272  
8273 # true
8274  
8275 =back
8276  
8277 =over 4
8278  
8279 =item no_input example 2
8280  
8281 # given: synopsis
8282  
8283 package main;
8284  
8285 $cli->option('input', {
8286 type => 'string',
8287 });
8288  
8289 $cli->option('output', {
8290 type => 'string',
8291 });
8292  
8293 $cli->parse('--input', 'stdin', '--output', 'stdout');
8294  
8295 my $no_input = $cli->no_input;
8296  
8297 # false
8298  
8299 =back
8300  
8301 =cut
8302  
8303 =head2 no_input_arguments
8304  
8305 no_input_arguments() (boolean)
8306  
8307 The no_input_arguments method returns true if no arguments are provided to the
8308 CLI, and false otherwise.
8309  
8310 I<Since C<4.15>>
8311  
8312 =over 4
8313  
8314 =item no_input_arguments example 1
8315  
8316 # given: synopsis
8317  
8318 package main;
8319  
8320 $cli->argument('args', {
8321 range => '0:',
8322 multiples => 1,
8323 type => 'string',
8324 });
8325  
8326 $cli->option('input', {
8327 type => 'string',
8328 });
8329  
8330 $cli->option('output', {
8331 type => 'string',
8332 });
8333  
8334 my $no_input_arguments = $cli->no_input_arguments;
8335  
8336 # true
8337  
8338 =back
8339  
8340 =over 4
8341  
8342 =item no_input_arguments example 2
8343  
8344 # given: synopsis
8345  
8346 package main;
8347  
8348 $cli->argument('args', {
8349 range => '0:',
8350 multiples => 1,
8351 type => 'string',
8352 });
8353  
8354 $cli->option('input', {
8355 type => 'string',
8356 });
8357  
8358 $cli->option('output', {
8359 type => 'string',
8360 });
8361  
8362 $cli->parse('arg1', 'arg2', '--output', 'stdout');
8363  
8364 my $no_input_arguments = $cli->no_input_arguments;
8365  
8366 # false
8367  
8368 =back
8369  
8370 =cut
8371  
8372 =head2 no_input_options
8373  
8374 no_input_options() (boolean)
8375  
8376 The no_input_options method returns true if no options are provided to the CLI,
8377 and false otherwise.
8378  
8379 I<Since C<4.15>>
8380  
8381 =over 4
8382  
8383 =item no_input_options example 1
8384  
8385 # given: synopsis
8386  
8387 package main;
8388  
8389 $cli->option('input', {
8390 type => 'string',
8391 });
8392  
8393 $cli->option('output', {
8394 type => 'string',
8395 });
8396  
8397 my $no_input_options = $cli->no_input_options;
8398  
8399 # true
8400  
8401 =back
8402  
8403 =over 4
8404  
8405 =item no_input_options example 2
8406  
8407 # given: synopsis
8408  
8409 package main;
8410  
8411 $cli->option('input', {
8412 type => 'string',
8413 });
8414  
8415 $cli->option('output', {
8416 type => 'string',
8417 });
8418  
8419 $cli->parse('--input', 'stdin');
8420  
8421 my $no_input_options = $cli->no_input_options;
8422  
8423 # false
8424  
8425 =back
8426  
8427 =cut
8428  
8429 =head2 no_output
8430  
8431 no_output() (boolean)
8432  
8433 The no_output method returns true if no output events are found, and false
8434 otherwise.
8435  
8436 I<Since C<4.15>>
8437  
8438 =over 4
8439  
8440 =item no_output example 1
8441  
8442 # given: synopsis
8443  
8444 package main;
8445  
8446 my $no_output = $cli->no_output;
8447  
8448 # true
8449  
8450 =back
8451  
8452 =over 4
8453  
8454 =item no_output example 2
8455  
8456 # given: synopsis
8457  
8458 package main;
8459  
8460 $cli->log_info('example output');
8461  
8462 my $no_output = $cli->no_output;
8463  
8464 # false
8465  
8466 =back
8467  
8468 =cut
8469  
8470 =head2 no_output_debug_events
8471  
8472 no_output_debug_events() (boolean)
8473  
8474 The no_output_debug_events method returns true if no debug output events are
8475 found, and false otherwise.
8476  
8477 I<Since C<4.15>>
8478  
8479 =over 4
8480  
8481 =item no_output_debug_events example 1
8482  
8483 # given: synopsis
8484  
8485 package main;
8486  
8487 $cli->log_info('example output');
8488  
8489 my $no_output_debug_events = $cli->no_output_debug_events;
8490  
8491 # true
8492  
8493 =back
8494  
8495 =over 4
8496  
8497 =item no_output_debug_events example 2
8498  
8499 # given: synopsis
8500  
8501 package main;
8502  
8503 $cli->log_debug('example output');
8504  
8505 my $no_output_debug_events = $cli->no_output_debug_events;
8506  
8507 # false
8508  
8509 =back
8510  
8511 =cut
8512  
8513 =head2 no_output_error_events
8514  
8515 no_output_error_events() (boolean)
8516  
8517 The no_output_error_events method returns true if no error output events are
8518 found, and false otherwise.
8519  
8520 I<Since C<4.15>>
8521  
8522 =over 4
8523  
8524 =item no_output_error_events example 1
8525  
8526 # given: synopsis
8527  
8528 package main;
8529  
8530 $cli->log_info('example output');
8531  
8532 my $no_output_error_events = $cli->no_output_error_events;
8533  
8534 # true
8535  
8536 =back
8537  
8538 =over 4
8539  
8540 =item no_output_error_events example 2
8541  
8542 # given: synopsis
8543  
8544 package main;
8545  
8546 $cli->log_error('example output');
8547  
8548 my $no_output_error_events = $cli->no_output_error_events;
8549  
8550 # false
8551  
8552 =back
8553  
8554 =cut
8555  
8556 =head2 no_output_fatal_events
8557  
8558 no_output_fatal_events() (boolean)
8559  
8560 The no_output_fatal_events method returns true if no fatal output events are
8561 found, and false otherwise.
8562  
8563 I<Since C<4.15>>
8564  
8565 =over 4
8566  
8567 =item no_output_fatal_events example 1
8568  
8569 # given: synopsis
8570  
8571 package main;
8572  
8573 $cli->log_info('example output');
8574  
8575 my $no_output_fatal_events = $cli->no_output_fatal_events;
8576  
8577 # true
8578  
8579 =back
8580  
8581 =over 4
8582  
8583 =item no_output_fatal_events example 2
8584  
8585 # given: synopsis
8586  
8587 package main;
8588  
8589 $cli->log_fatal('example output');
8590  
8591 my $no_output_fatal_events = $cli->no_output_fatal_events;
8592  
8593 # false
8594  
8595 =back
8596  
8597 =cut
8598  
8599 =head2 no_output_info_events
8600  
8601 no_output_info_events() (boolean)
8602  
8603 The no_output_info_events method returns true if no info output events are
8604 found, and false otherwise.
8605  
8606 I<Since C<4.15>>
8607  
8608 =over 4
8609  
8610 =item no_output_info_events example 1
8611  
8612 # given: synopsis
8613  
8614 package main;
8615  
8616 $cli->log_info('example output');
8617  
8618 my $no_output_info_events = $cli->no_output_info_events;
8619  
8620 # false
8621  
8622 =back
8623  
8624 =over 4
8625  
8626 =item no_output_info_events example 2
8627  
8628 # given: synopsis
8629  
8630 package main;
8631  
8632 $cli->log_error('example output');
8633  
8634 my $no_output_info_events = $cli->no_output_info_events;
8635  
8636 # true
8637  
8638 =back
8639  
8640 =cut
8641  
8642 =head2 no_output_trace_events
8643  
8644 no_output_trace_events() (boolean)
8645  
8646 The no_output_trace_events method returns true if no trace output events are
8647 found, and false otherwise.
8648  
8649 I<Since C<4.15>>
8650  
8651 =over 4
8652  
8653 =item no_output_trace_events example 1
8654  
8655 # given: synopsis
8656  
8657 package main;
8658  
8659 $cli->log_info('example output');
8660  
8661 my $no_output_trace_events = $cli->no_output_trace_events;
8662  
8663 # true
8664  
8665 =back
8666  
8667 =over 4
8668  
8669 =item no_output_trace_events example 2
8670  
8671 # given: synopsis
8672  
8673 package main;
8674  
8675 $cli->log_trace('example output');
8676  
8677 my $no_output_trace_events = $cli->no_output_trace_events;
8678  
8679 # false
8680  
8681 =back
8682  
8683 =cut
8684  
8685 =head2 no_output_warn_events
8686  
8687 no_output_warn_events() (boolean)
8688  
8689 The no_output_warn_events method returns true if no warn output events are
8690 found, and false otherwise.
8691  
8692 I<Since C<4.15>>
8693  
8694 =over 4
8695  
8696 =item no_output_warn_events example 1
8697  
8698 # given: synopsis
8699  
8700 package main;
8701  
8702 $cli->log_info('example output');
8703  
8704 my $no_output_warn_events = $cli->no_output_warn_events;
8705  
8706 # true
8707  
8708 =back
8709  
8710 =over 4
8711  
8712 =item no_output_warn_events example 2
8713  
8714 # given: synopsis
8715  
8716 package main;
8717  
8718 $cli->log_warn('example output');
8719  
8720 my $no_output_warn_events = $cli->no_output_warn_events;
8721  
8722 # false
8723  
8724 =back
8725  
8726 =cut
8727  
8728 =head2 number
8729  
8730 number(string $method, any @args) (any)
8731  
8732 The number method is a configuration dispatcher and shorthand for C<{'type',
8733 'number'}>. It returns the data or dispatches to the next configuration
8734 dispatcher based on the name provided and merges the configurations produced.
8735  
8736 I<Since C<4.15>>
8737  
8738 =over 4
8739  
8740 =item number example 1
8741  
8742 # given: synopsis
8743  
8744 package main;
8745  
8746 my $number = $cli->number;
8747  
8748 # {type => 'number'}
8749  
8750 =back
8751  
8752 =over 4
8753  
8754 =item number example 2
8755  
8756 # given: synopsis
8757  
8758 package main;
8759  
8760 my $number = $cli->number(undef, {required => true});
8761  
8762 # {type => 'number', required => true}
8763  
8764 =back
8765  
8766 =over 4
8767  
8768 =item number example 3
8769  
8770 # given: synopsis
8771  
8772 package main;
8773  
8774 my $number = $cli->number('option', 'example');
8775  
8776 # {
8777 # name => 'example',
8778 # label => undef,
8779 # help => 'Expects a number value',
8780 # default => undef,
8781 # aliases => [],
8782 # multiples => 0,
8783 # prompt => undef,
8784 # range => undef,
8785 # required => 1,
8786 # type => 'number',
8787 # index => 0,
8788 # wants => 'number',
8789 # }
8790  
8791 =back
8792  
8793 =cut
8794  
8795 =head2 okay
8796  
8797 okay(string | coderef $code, any @args) (any)
8798  
8799 The okay method terminates the program with a the exit code C<0>,
8800 indicating a successful exit. This method can be used to end the program
8801 explicitly, either after a specific task is completed or when an error
8802 occurs that requires halting execution. This method can dispatch to
8803 another method or callback before exiting.
8804  
8805 I<Since C<4.15>>
8806  
8807 =over 4
8808  
8809 =item okay example 1
8810  
8811 package main;
8812  
8813 use Venus::Cli;
8814  
8815 my $cli = Venus::Cli->new(name => 'mycli');
8816  
8817 $cli->okay;
8818  
8819 # 0
8820  
8821 =back
8822  
8823 =over 4
8824  
8825 =item okay example 2
8826  
8827 package main;
8828  
8829 use Venus::Cli;
8830  
8831 my $cli = Venus::Cli->new(name => 'mycli');
8832  
8833 $cli->okay(sub{
8834 $cli->{dispatched} = 1;
8835 });
8836  
8837 # 0
8838  
8839 =back
8840  
8841 =cut
8842  
8843 =head2 option
8844  
8845 option(string $name, hashref $data) (maybe[hashref])
8846  
8847 The option method registers and returns the configuration for the option
8848 specified. The method takes a name (option name) and a hashref of
8849 configuration values. The possible configuration values are as follows:
8850  
8851 =over 4
8852  
8853 =item *
8854  
8855 The C<name> key holds the name of the option.
8856  
8857 =item *
8858  
8859 The C<label> key holds the name of the option as it should be displayed in
8860 the CLI help text.
8861  
8862 =item *
8863  
8864 The C<help> key holds the help text specific to this option.
8865  
8866 =item *
8867  
8868 The C<default> key holds the default value that should used if no value for
8869 this option is provided to the CLI.
8870  
8871 =item *
8872  
8873 The C<aliases> (or C<alias>) key holds the arrayref of aliases that can be
8874 provided to the CLI to specify a value (or values) for this option.
8875  
8876 =item *
8877  
8878 The C<multiples> key denotes whether this option can be used more than once,
8879 to collect multiple values, and holds a C<1> if multiples are allowed and a C<0>
8880 otherwise.
8881  
8882 =item *
8883  
8884 The C<prompt> key holds the question or statement that should be presented to
8885 the user of the CLI if no value has been provided for this option and no
8886 default value has been set.
8887  
8888 =item *
8889  
8890 The C<range> key holds a two-value arrayref where the first value is the
8891 starting index and the second value is the ending index. These values are used
8892 to select values from the parsed arguments array as the value(s) for this
8893 argument. This value is ignored if the C<multiples> key is set to C<0>.
8894  
8895 =item *
8896  
8897 The C<required> key denotes whether this option is required or not, and holds
8898 a C<1> if required and a C<0> otherwise.
8899  
8900 =item *
8901  
8902 The C<type> key holds the data type of the option expected. Valid values are
8903 "number", "string", "float", "boolean", or "yesno". B<Note:> Valid boolean
8904 values are C<1>, C<0>, C<"true">, and C<"false">.
8905  
8906 =item *
8907  
8908 The C<wants> key holds the text to be used as a value being assigned to the
8909 option in the usage text. This value defaults to the type specified, or
8910 C<"string">.
8911  
8912 =back
8913  
8914 I<Since C<4.15>>
8915  
8916 =over 4
8917  
8918 =item option example 1
8919  
8920 # given: synopsis
8921  
8922 package main;
8923  
8924 my $option = $cli->option('name', {
8925 label => 'Name',
8926 help => 'The name of the user',
8927 default => 'Unknown',
8928 required => 1,
8929 type => 'string'
8930 });
8931  
8932 # {
8933 # name => 'name',
8934 # label => 'Name',
8935 # help => 'The name of the user',
8936 # default => 'Unknown',
8937 # aliases => [],
8938 # multiples => 0,
8939 # prompt => undef,
8940 # range => undef,
8941 # required => 1,
8942 # type => 'string',
8943 # index => 0,
8944 # wants => 'string',
8945 # }
8946  
8947 =back
8948  
8949 =cut
8950  
8951 =head2 option_aliases
8952  
8953 option_aliases(string $name) (arrayref)
8954  
8955 The option_aliases method returns the C<aliases> configuration value for the
8956 named option.
8957  
8958 I<Since C<4.15>>
8959  
8960 =over 4
8961  
8962 =item option_aliases example 1
8963  
8964 package main;
8965  
8966 use Venus::Cli;
8967  
8968 my $cli = Venus::Cli->new(name => 'mycli');
8969  
8970 my $option_aliases = $cli->option_aliases;
8971  
8972 # []
8973  
8974 =back
8975  
8976 =over 4
8977  
8978 =item option_aliases example 2
8979  
8980 package main;
8981  
8982 use Venus::Cli;
8983  
8984 my $cli = Venus::Cli->new(name => 'mycli');
8985  
8986 $cli->option('input', {
8987 alias => 'i',
8988 type => 'string',
8989 });
8990  
8991 my $option_aliases = $cli->option_aliases('input');
8992  
8993 # ['i']
8994  
8995 =back
8996  
8997 =over 4
8998  
8999 =item option_aliases example 3
9000  
9001 package main;
9002  
9003 use Venus::Cli;
9004  
9005 my $cli = Venus::Cli->new(name => 'mycli');
9006  
9007 $cli->option('input', {
9008 aliases => 'i',
9009 type => 'string',
9010 });
9011  
9012 my $option_aliases = $cli->option_aliases('input');
9013  
9014 # ['i']
9015  
9016 =back
9017  
9018 =over 4
9019  
9020 =item option_aliases example 4
9021  
9022 package main;
9023  
9024 use Venus::Cli;
9025  
9026 my $cli = Venus::Cli->new(name => 'mycli');
9027  
9028 $cli->option('input', {
9029 aliases => ['i'],
9030 type => 'string',
9031 });
9032  
9033 my $option_aliases = $cli->option_aliases('input');
9034  
9035 # ['i']
9036  
9037 =back
9038  
9039 =cut
9040  
9041 =head2 option_count
9042  
9043 option_count() (number)
9044  
9045 The option_count method returns the count of registered options.
9046  
9047 I<Since C<4.15>>
9048  
9049 =over 4
9050  
9051 =item option_count example 1
9052  
9053 package main;
9054  
9055 use Venus::Cli;
9056  
9057 my $cli = Venus::Cli->new(name => 'mycli');
9058  
9059 my $option_count = $cli->option_count;
9060  
9061 # 0
9062  
9063 =back
9064  
9065 =over 4
9066  
9067 =item option_count example 2
9068  
9069 package main;
9070  
9071 use Venus::Cli;
9072  
9073 my $cli = Venus::Cli->new(name => 'mycli');
9074  
9075 $cli->option('input', {
9076 type => 'string',
9077 });
9078  
9079 $cli->option('output', {
9080 type => 'string',
9081 });
9082  
9083 my $option_count = $cli->option_count;
9084  
9085 # 2
9086  
9087 =back
9088  
9089 =cut
9090  
9091 =head2 option_default
9092  
9093 option_default(string $name) (string)
9094  
9095 The option_default method returns the C<default> configuration value for the
9096 named option.
9097  
9098 I<Since C<4.15>>
9099  
9100 =over 4
9101  
9102 =item option_default example 1
9103  
9104 package main;
9105  
9106 use Venus::Cli;
9107  
9108 my $cli = Venus::Cli->new(name => 'mycli');
9109  
9110 my $option_default = $cli->option_default;
9111  
9112 # ""
9113  
9114 =back
9115  
9116 =over 4
9117  
9118 =item option_default example 2
9119  
9120 package main;
9121  
9122 use Venus::Cli;
9123  
9124 my $cli = Venus::Cli->new(name => 'mycli');
9125  
9126 $cli->option('input', {
9127 default => 'stdin',
9128 });
9129  
9130 my $option_default = $cli->option_default('input');
9131  
9132 # "stdin"
9133  
9134 =back
9135  
9136 =cut
9137  
9138 =head2 option_errors
9139  
9140 option_errors(string $name) (within[arrayref, Venus::Validate])
9141  
9142 The option_errors method returns a list of L<"issues"|Venus::Validate/issue>,
9143 if any, for each value returned by L</option_value> for the named option.
9144 Returns a list in list context.
9145  
9146 I<Since C<4.15>>
9147  
9148 =over 4
9149  
9150 =item option_errors example 1
9151  
9152 package main;
9153  
9154 use Venus::Cli;
9155  
9156 my $cli = Venus::Cli->new(name => 'mycli');
9157  
9158 my $option_errors = $cli->option_errors;
9159  
9160 # []
9161  
9162 =back
9163  
9164 =over 4
9165  
9166 =item option_errors example 2
9167  
9168 package main;
9169  
9170 use Venus::Cli;
9171  
9172 my $cli = Venus::Cli->new(name => 'mycli');
9173  
9174 $cli->option('input', {
9175 type => 'string',
9176 });
9177  
9178 $cli->parse('--input hello');
9179  
9180 my $option_errors = $cli->option_errors('input');
9181  
9182 # []
9183  
9184 =back
9185  
9186 =over 4
9187  
9188 =item option_errors example 3
9189  
9190 package main;
9191  
9192 use Venus::Cli;
9193  
9194 my $cli = Venus::Cli->new(name => 'mycli');
9195  
9196 $cli->option('input', {
9197 default => 'hello',
9198 type => 'number',
9199 });
9200  
9201 $cli->parse('--input hello');
9202  
9203 my $option_errors = $cli->option_errors('input');
9204  
9205 # [['type', ['number']]]
9206  
9207 =back
9208  
9209 =cut
9210  
9211 =head2 option_help
9212  
9213 option_help(string $name) (string)
9214  
9215 The option_help method returns the C<help> configuration value for the named
9216 option.
9217  
9218 I<Since C<4.15>>
9219  
9220 =over 4
9221  
9222 =item option_help example 1
9223  
9224 package main;
9225  
9226 use Venus::Cli;
9227  
9228 my $cli = Venus::Cli->new(name => 'mycli');
9229  
9230 my $option_help = $cli->option_help;
9231  
9232 # ""
9233  
9234 =back
9235  
9236 =over 4
9237  
9238 =item option_help example 2
9239  
9240 package main;
9241  
9242 use Venus::Cli;
9243  
9244 my $cli = Venus::Cli->new(name => 'mycli');
9245  
9246 $cli->option('input', {
9247 help => 'Example help text',
9248 });
9249  
9250 my $option_help = $cli->option_help('input');
9251  
9252 # "Example help text"
9253  
9254 =back
9255  
9256 =cut
9257  
9258 =head2 option_label
9259  
9260 option_label(string $name) (string)
9261  
9262 The option_label method returns the C<label> configuration value for the
9263 named option.
9264  
9265 I<Since C<4.15>>
9266  
9267 =over 4
9268  
9269 =item option_label example 1
9270  
9271 package main;
9272  
9273 use Venus::Cli;
9274  
9275 my $cli = Venus::Cli->new(name => 'mycli');
9276  
9277 my $option_label = $cli->option_label;
9278  
9279 # ""
9280  
9281 =back
9282  
9283 =over 4
9284  
9285 =item option_label example 2
9286  
9287 package main;
9288  
9289 use Venus::Cli;
9290  
9291 my $cli = Venus::Cli->new(name => 'mycli');
9292  
9293 $cli->option('input', {
9294 label => 'Input',
9295 });
9296  
9297 my $option_label = $cli->option_label('input');
9298  
9299 # "Input"
9300  
9301 =back
9302  
9303 =cut
9304  
9305 =head2 option_list
9306  
9307 option_list(string $name) (within[arrayref, hashref])
9308  
9309 The option_list method returns a list of registered option configurations.
9310 Returns a list in list context.
9311  
9312 I<Since C<4.15>>
9313  
9314 =over 4
9315  
9316 =item option_list example 1
9317  
9318 package main;
9319  
9320 use Venus::Cli;
9321  
9322 my $cli = Venus::Cli->new(name => 'mycli');
9323  
9324 my $option_list = $cli->option_list;
9325  
9326 # []
9327  
9328 =back
9329  
9330 =over 4
9331  
9332 =item option_list example 2
9333  
9334 package main;
9335  
9336 use Venus::Cli;
9337  
9338 my $cli = Venus::Cli->new(name => 'mycli');
9339  
9340 $cli->option('input', {
9341 type => 'string',
9342 });
9343  
9344 my $option_list = $cli->option_list;
9345  
9346 # [{
9347 # name => 'input',
9348 # label => undef,
9349 # help => 'Expects a string value',
9350 # aliases => [],
9351 # default => undef,
9352 # multiples => 0,
9353 # prompt => undef,
9354 # range => undef,
9355 # required => false,
9356 # type => 'string',
9357 # index => 0,
9358 # wants => 'string',
9359 # }]
9360  
9361 =back
9362  
9363 =cut
9364  
9365 =head2 option_multiples
9366  
9367 option_multiples(string $name) (boolean)
9368  
9369 The option_multiples method returns the C<multiples> configuration value for
9370 the named option.
9371  
9372 I<Since C<4.15>>
9373  
9374 =over 4
9375  
9376 =item option_multiples example 1
9377  
9378 package main;
9379  
9380 use Venus::Cli;
9381  
9382 my $cli = Venus::Cli->new(name => 'mycli');
9383  
9384 my $option_multiples = $cli->option_multiples;
9385  
9386 # false
9387  
9388 =back
9389  
9390 =over 4
9391  
9392 =item option_multiples example 2
9393  
9394 package main;
9395  
9396 use Venus::Cli;
9397  
9398 my $cli = Venus::Cli->new(name => 'mycli');
9399  
9400 $cli->option('input', {
9401 multiples => true,
9402 });
9403  
9404 my $option_multiples = $cli->option_multiples('input');
9405  
9406 # true
9407  
9408 =back
9409  
9410 =cut
9411  
9412 =head2 option_name
9413  
9414 option_name(string $name) (string)
9415  
9416 The option_name method returns the C<name> configuration value for the named
9417 option.
9418  
9419 I<Since C<4.15>>
9420  
9421 =over 4
9422  
9423 =item option_name example 1
9424  
9425 package main;
9426  
9427 use Venus::Cli;
9428  
9429 my $cli = Venus::Cli->new(name => 'mycli');
9430  
9431 my $option_name = $cli->option_name;
9432  
9433 # ""
9434  
9435 =back
9436  
9437 =over 4
9438  
9439 =item option_name example 2
9440  
9441 package main;
9442  
9443 use Venus::Cli;
9444  
9445 my $cli = Venus::Cli->new(name => 'mycli');
9446  
9447 $cli->option('input', {
9448 name => 'INPUT',
9449 });
9450  
9451 my $option_name = $cli->option_name('input');
9452  
9453 # ""
9454  
9455 =back
9456  
9457 =over 4
9458  
9459 =item option_name example 3
9460  
9461 package main;
9462  
9463 use Venus::Cli;
9464  
9465 my $cli = Venus::Cli->new(name => 'mycli');
9466  
9467 $cli->option('input', {
9468 name => 'INPUT',
9469 });
9470  
9471 my $option_name = $cli->option_name('INPUT');
9472  
9473 # "INPUT"
9474  
9475 =back
9476  
9477 =cut
9478  
9479 =head2 option_names
9480  
9481 option_names(string $name) (within[arrayref, string])
9482  
9483 The option_names method returns the names (keys) of registered options in
9484 the order declared. Returns a list in list context.
9485  
9486 I<Since C<4.15>>
9487  
9488 =over 4
9489  
9490 =item option_names example 1
9491  
9492 package main;
9493  
9494 use Venus::Cli;
9495  
9496 my $cli = Venus::Cli->new(name => 'mycli');
9497  
9498 my $option_names = $cli->option_names;
9499  
9500 # []
9501  
9502 =back
9503  
9504 =over 4
9505  
9506 =item option_names example 2
9507  
9508 package main;
9509  
9510 use Venus::Cli;
9511  
9512 my $cli = Venus::Cli->new(name => 'mycli');
9513  
9514 $cli->option('input', {
9515 type => 'string',
9516 });
9517  
9518 $cli->option('output', {
9519 type => 'string',
9520 });
9521  
9522 my $option_names = $cli->option_names;
9523  
9524 # ['input', 'output']
9525  
9526 =back
9527  
9528 =over 4
9529  
9530 =item option_names example 3
9531  
9532 package main;
9533  
9534 use Venus::Cli;
9535  
9536 my $cli = Venus::Cli->new(name => 'mycli');
9537  
9538 $cli->option('output', {
9539 type => 'string',
9540 });
9541  
9542 $cli->option('input', {
9543 type => 'string',
9544 });
9545  
9546 my $option_names = $cli->option_names;
9547  
9548 # ['output', 'input']
9549  
9550 =back
9551  
9552 =cut
9553  
9554 =head2 option_prompt
9555  
9556 option_prompt(string $name) (string)
9557  
9558 The option_prompt method returns the C<prompt> configuration value for the
9559 named option.
9560  
9561 I<Since C<4.15>>
9562  
9563 =over 4
9564  
9565 =item option_prompt example 1
9566  
9567 package main;
9568  
9569 use Venus::Cli;
9570  
9571 my $cli = Venus::Cli->new(name => 'mycli');
9572  
9573 my $option_prompt = $cli->option_prompt;
9574  
9575 # ""
9576  
9577 =back
9578  
9579 =over 4
9580  
9581 =item option_prompt example 2
9582  
9583 package main;
9584  
9585 use Venus::Cli;
9586  
9587 my $cli = Venus::Cli->new(name => 'mycli');
9588  
9589 $cli->option('input', {
9590 prompt => 'Example prompt',
9591 });
9592  
9593 my $option_prompt = $cli->option_prompt('input');
9594  
9595 # "Example prompt"
9596  
9597 =back
9598  
9599 =cut
9600  
9601 =head2 option_range
9602  
9603 option_range(string $name) (string)
9604  
9605 The option_range method returns the C<range> configuration value for the
9606 named option.
9607  
9608 I<Since C<4.15>>
9609  
9610 =over 4
9611  
9612 =item option_range example 1
9613  
9614 package main;
9615  
9616 use Venus::Cli;
9617  
9618 my $cli = Venus::Cli->new(name => 'mycli');
9619  
9620 my $option_range = $cli->option_range;
9621  
9622 # ""
9623  
9624 =back
9625  
9626 =over 4
9627  
9628 =item option_range example 2
9629  
9630 package main;
9631  
9632 use Venus::Cli;
9633  
9634 my $cli = Venus::Cli->new(name => 'mycli');
9635  
9636 $cli->option('input', {
9637 range => '0',
9638 });
9639  
9640 my $option_range = $cli->option_range('input');
9641  
9642 # "0"
9643  
9644 =back
9645  
9646 =over 4
9647  
9648 =item option_range example 3
9649  
9650 package main;
9651  
9652 use Venus::Cli;
9653  
9654 my $cli = Venus::Cli->new(name => 'mycli');
9655  
9656 $cli->option('input', {
9657 range => '0:5',
9658 });
9659  
9660 my $option_range = $cli->option_range('input');
9661  
9662 # "0:5"
9663  
9664 =back
9665  
9666 =cut
9667  
9668 =head2 option_required
9669  
9670 option_required(string $name) (boolean)
9671  
9672 The option_required method returns the C<required> configuration value for
9673 the named option.
9674  
9675 I<Since C<4.15>>
9676  
9677 =over 4
9678  
9679 =item option_required example 1
9680  
9681 package main;
9682  
9683 use Venus::Cli;
9684  
9685 my $cli = Venus::Cli->new(name => 'mycli');
9686  
9687 my $option_required = $cli->option_required;
9688  
9689 # false
9690  
9691 =back
9692  
9693 =over 4
9694  
9695 =item option_required example 2
9696  
9697 package main;
9698  
9699 use Venus::Cli;
9700  
9701 my $cli = Venus::Cli->new(name => 'mycli');
9702  
9703 $cli->option('input', {
9704 required => true,
9705 });
9706  
9707 my $option_required = $cli->option_required('input');
9708  
9709 # true
9710  
9711 =back
9712  
9713 =cut
9714  
9715 =head2 option_type
9716  
9717 option_type(string $name) (string)
9718  
9719 The option_type method returns the C<type> configuration value for the named
9720 option. Valid values are as follows:
9721  
9722 =over 4
9723  
9724 =item *
9725  
9726 C<number>
9727  
9728 =item *
9729  
9730 C<string>
9731  
9732 =item *
9733  
9734 C<float>
9735  
9736 =item *
9737  
9738 C<boolean> - B<Note:> Valid boolean values are C<1>, C<0>, C<"true">, and C<"false">.
9739  
9740 =item *
9741  
9742 C<yesno>
9743  
9744 =back
9745  
9746 I<Since C<4.15>>
9747  
9748 =over 4
9749  
9750 =item option_type example 1
9751  
9752 package main;
9753  
9754 use Venus::Cli;
9755  
9756 my $cli = Venus::Cli->new(name => 'mycli');
9757  
9758 my $option_type = $cli->option_type;
9759  
9760 # ""
9761  
9762 =back
9763  
9764 =over 4
9765  
9766 =item option_type example 2
9767  
9768 package main;
9769  
9770 use Venus::Cli;
9771  
9772 my $cli = Venus::Cli->new(name => 'mycli');
9773  
9774 $cli->option('input', {
9775 type => 'boolean',
9776 });
9777  
9778 my $option_type = $cli->option_type('input');
9779  
9780 # "boolean"
9781  
9782 =back
9783  
9784 =cut
9785  
9786 =head2 option_validate
9787  
9788 option_validate(string $name) (Venus::Validate | within[arrayref, Venus::Validate])
9789  
9790 The option_validate method returns a L<Venus::Validate> object for each value
9791 returned by L</option_value> for the named option. Returns a list in list
9792 context.
9793  
9794 I<Since C<4.15>>
9795  
9796 =over 4
9797  
9798 =item option_validate example 1
9799  
9800 package main;
9801  
9802 use Venus::Cli;
9803  
9804 my $cli = Venus::Cli->new(name => 'mycli');
9805  
9806 my $option_validate = $cli->option_validate;
9807  
9808 # []
9809  
9810 =back
9811  
9812 =over 4
9813  
9814 =item option_validate example 2
9815  
9816 package main;
9817  
9818 use Venus::Cli;
9819  
9820 my $cli = Venus::Cli->new(name => 'mycli');
9821  
9822 $cli->option('input', {
9823 multiples => true,
9824 type => 'string',
9825 });
9826  
9827 my $option_validate = $cli->option_validate('input');
9828  
9829 # [bless(..., "Venus::Validate")]
9830  
9831 =back
9832  
9833 =over 4
9834  
9835 =item option_validate example 3
9836  
9837 package main;
9838  
9839 use Venus::Cli;
9840  
9841 my $cli = Venus::Cli->new(name => 'mycli');
9842  
9843 $cli->option('input', {
9844 multiples => false,
9845 type => 'string',
9846 });
9847  
9848 my $option_validate = $cli->option_validate('input');
9849  
9850 # bless(..., "Venus::Validate")
9851  
9852 =back
9853  
9854 =over 4
9855  
9856 =item option_validate example 4
9857  
9858 package main;
9859  
9860 use Venus::Cli;
9861  
9862 my $cli = Venus::Cli->new(name => 'mycli');
9863  
9864 $cli->option('input', {
9865 multiples => true,
9866 type => 'string',
9867 });
9868  
9869 $cli->parse('--input', 'hello', '--input', 'world');
9870  
9871 my $option_validate = $cli->option_validate('input');
9872  
9873 # [bless(..., "Venus::Validate"), bless(..., "Venus::Validate")]
9874  
9875 =back
9876  
9877 =cut
9878  
9879 =head2 option_value
9880  
9881 option_value(string $name) (any)
9882  
9883 The option_value method returns the parsed option value for the named
9884 option.
9885  
9886 I<Since C<4.15>>
9887  
9888 =over 4
9889  
9890 =item option_value example 1
9891  
9892 package main;
9893  
9894 use Venus::Cli;
9895  
9896 my $cli = Venus::Cli->new(name => 'mycli');
9897  
9898 my $option_value = $cli->option_value;
9899  
9900 # undef
9901  
9902 =back
9903  
9904 =over 4
9905  
9906 =item option_value example 2
9907  
9908 package main;
9909  
9910 use Venus::Cli;
9911  
9912 my $cli = Venus::Cli->new(name => 'mycli');
9913  
9914 $cli->option('input', {
9915 multiples => false,
9916 type => 'string',
9917 });
9918  
9919 $cli->parse('--input', 'hello', '--input', 'world');
9920  
9921 my $option_value = $cli->option_value('input');
9922  
9923 # "world"
9924  
9925 =back
9926  
9927 =over 4
9928  
9929 =item option_value example 3
9930  
9931 package main;
9932  
9933 use Venus::Cli;
9934  
9935 my $cli = Venus::Cli->new(name => 'mycli');
9936  
9937 $cli->option('input', {
9938 multiples => true,
9939 type => 'string',
9940 });
9941  
9942 $cli->parse('--input', 'hello', '--input', 'world');
9943  
9944 my $option_value = $cli->option_value('input');
9945  
9946 # ["hello", "world"]
9947  
9948 =back
9949  
9950 =cut
9951  
9952 =head2 option_wants
9953  
9954 option_wants(string $name) (string)
9955  
9956 The option_wants method returns the C<wants> configuration value for the
9957 named option.
9958  
9959 I<Since C<4.15>>
9960  
9961 =over 4
9962  
9963 =item option_wants example 1
9964  
9965 package main;
9966  
9967 use Venus::Cli;
9968  
9969 my $cli = Venus::Cli->new(name => 'mycli');
9970  
9971 my $option_wants = $cli->option_wants;
9972  
9973 # ""
9974  
9975 =back
9976  
9977 =over 4
9978  
9979 =item option_wants example 2
9980  
9981 package main;
9982  
9983 use Venus::Cli;
9984  
9985 my $cli = Venus::Cli->new(name => 'mycli');
9986  
9987 $cli->option('input', {
9988 wants => 'string',
9989 });
9990  
9991 my $option_wants = $cli->option_wants('input');
9992  
9993 # "string"
9994  
9995 =back
9996  
9997 =cut
9998  
9999 =head2 optional
10000  
10001 optional(string $method, any @args) (any)
10002  
10003 The optional method is a configuration dispatcher and shorthand for
10004 C<{'required', false}>. It returns the data or dispatches to the next
10005 configuration dispatcher based on the name provided and merges the
10006 configurations produced.
10007  
10008 I<Since C<4.15>>
10009  
10010 =over 4
10011  
10012 =item optional example 1
10013  
10014 # given: synopsis
10015  
10016 package main;
10017  
10018 my $optional = $cli->optional;
10019  
10020 # {required => false}
10021  
10022 =back
10023  
10024 =over 4
10025  
10026 =item optional example 2
10027  
10028 # given: synopsis
10029  
10030 package main;
10031  
10032 my $optional = $cli->optional(undef, {type => 'boolean'});
10033  
10034 # {required => false, type => 'boolean'}
10035  
10036 =back
10037  
10038 =over 4
10039  
10040 =item optional example 3
10041  
10042 # given: synopsis
10043  
10044 package main;
10045  
10046 my $optional = $cli->optional('option', 'example');
10047  
10048 # {
10049 # name => 'example',
10050 # label => undef,
10051 # help => 'Expects a string value',
10052 # default => undef,
10053 # aliases => [],
10054 # multiples => 0,
10055 # prompt => undef,
10056 # range => undef,
10057 # required => 0,
10058 # type => 'string',
10059 # index => 0,
10060 # wants => 'string',
10061 # }
10062  
10063 =back
10064  
10065 =cut
10066  
10067 =head2 opts
10068  
10069 opts() (Venus::Opts)
10070  
10071 The opts method returns the list of parsed command-line options as a
10072 L<Venus::Opts> object.
10073  
10074 I<Since C<4.15>>
10075  
10076 =over 4
10077  
10078 =item opts example 1
10079  
10080 # given: synopsis
10081  
10082 package main;
10083  
10084 my $opts = $cli->opts;
10085  
10086 # bless(..., "Venus::Opts")
10087  
10088 =back
10089  
10090 =over 4
10091  
10092 =item opts example 2
10093  
10094 # given: synopsis
10095  
10096 package main;
10097  
10098 $cli->option('input', {
10099 type => 'string',
10100 });
10101  
10102 $cli->parse('--input', 'hello world');
10103  
10104 my $opts = $cli->opts;
10105  
10106 # bless(..., "Venus::Opts")
10107  
10108 # $opts->input;
10109  
10110 =back
10111  
10112 =cut
10113  
10114 =head2 output
10115  
10116 output(string $level) (any)
10117  
10118 The output method returns the list of output events as an arrayref in scalar
10119 context, and a list in list context. The method optionally takes a log-level
10120 and if provided will only return output events for that log-level.
10121  
10122 I<Since C<4.15>>
10123  
10124 =over 4
10125  
10126 =item output example 1
10127  
10128 # given: synopsis
10129  
10130 package main;
10131  
10132 my $output = $cli->output;
10133  
10134 # undef
10135  
10136 =back
10137  
10138 =over 4
10139  
10140 =item output example 2
10141  
10142 # given: synopsis
10143  
10144 package main;
10145  
10146 $cli->log_info('example output');
10147  
10148 my $output = $cli->output;
10149  
10150 # "example output"
10151  
10152 =back
10153  
10154 =over 4
10155  
10156 =item output example 3
10157  
10158 # given: synopsis
10159  
10160 package main;
10161  
10162 $cli->log_info('example output 1');
10163  
10164 $cli->log_info('example output 2');
10165  
10166 my @output = $cli->output;
10167  
10168 # ('example output 1', 'example output 2')
10169  
10170 =back
10171  
10172 =cut
10173  
10174 =head2 output_debug_events
10175  
10176 output_debug_events() (arrayref)
10177  
10178 The output_debug_events method returns the list of debug output events as an
10179 arrayref in scalar context, and a list in list context.
10180  
10181 I<Since C<4.15>>
10182  
10183 =over 4
10184  
10185 =item output_debug_events example 1
10186  
10187 # given: synopsis
10188  
10189 package main;
10190  
10191 $cli->log_info('example output');
10192  
10193 my $output_debug_events = $cli->output_debug_events;
10194  
10195 # []
10196  
10197 =back
10198  
10199 =over 4
10200  
10201 =item output_debug_events example 2
10202  
10203 # given: synopsis
10204  
10205 package main;
10206  
10207 $cli->log_debug('example output');
10208  
10209 my $output_debug_events = $cli->output_debug_events;
10210  
10211 # ['example output']
10212  
10213 =back
10214  
10215 =over 4
10216  
10217 =item output_debug_events example 3
10218  
10219 # given: synopsis
10220  
10221 package main;
10222  
10223 $cli->log_debug('example output 1');
10224  
10225 $cli->log_debug('example output 2');
10226  
10227 my $output_debug_events = $cli->output_debug_events;
10228  
10229 # ['example output 1', 'example output 2']
10230  
10231 =back
10232  
10233 =over 4
10234  
10235 =item output_debug_events example 4
10236  
10237 # given: synopsis
10238  
10239 package main;
10240  
10241 $cli->log_debug('example output 1');
10242  
10243 $cli->log_debug('example output 2');
10244  
10245 my @output_debug_events = $cli->output_debug_events;
10246  
10247 # ('example output 1', 'example output 2')
10248  
10249 =back
10250  
10251 =cut
10252  
10253 =head2 output_error_events
10254  
10255 output_error_events() (arrayref)
10256  
10257 The output_error_events method returns the list of error output events as an
10258 arrayref in scalar context, and a list in list context.
10259  
10260 I<Since C<4.15>>
10261  
10262 =over 4
10263  
10264 =item output_error_events example 1
10265  
10266 # given: synopsis
10267  
10268 package main;
10269  
10270 $cli->log_info('example output');
10271  
10272 my $output_error_events = $cli->output_error_events;
10273  
10274 # []
10275  
10276 =back
10277  
10278 =over 4
10279  
10280 =item output_error_events example 2
10281  
10282 # given: synopsis
10283  
10284 package main;
10285  
10286 $cli->log_error('example output');
10287  
10288 my $output_error_events = $cli->output_error_events;
10289  
10290 # ['example output']
10291  
10292 =back
10293  
10294 =over 4
10295  
10296 =item output_error_events example 3
10297  
10298 # given: synopsis
10299  
10300 package main;
10301  
10302 $cli->log_error('example output 1');
10303  
10304 $cli->log_error('example output 2');
10305  
10306 my $output_error_events = $cli->output_error_events;
10307  
10308 # ['example output 1', 'example output 2']
10309  
10310 =back
10311  
10312 =over 4
10313  
10314 =item output_error_events example 4
10315  
10316 # given: synopsis
10317  
10318 package main;
10319  
10320 $cli->log_error('example output 1');
10321  
10322 $cli->log_error('example output 2');
10323  
10324 my @output_error_events = $cli->output_error_events;
10325  
10326 # ('example output 1', 'example output 2')
10327  
10328 =back
10329  
10330 =cut
10331  
10332 =head2 output_fatal_events
10333  
10334 output_fatal_events() (arrayref)
10335  
10336 The output_fatal_events method returns the list of fatal output events as an
10337 arrayref in scalar context, and a list in list context.
10338  
10339 I<Since C<4.15>>
10340  
10341 =over 4
10342  
10343 =item output_fatal_events example 1
10344  
10345 # given: synopsis
10346  
10347 package main;
10348  
10349 $cli->log_info('example output');
10350  
10351 my $output_fatal_events = $cli->output_fatal_events;
10352  
10353 # []
10354  
10355 =back
10356  
10357 =over 4
10358  
10359 =item output_fatal_events example 2
10360  
10361 # given: synopsis
10362  
10363 package main;
10364  
10365 $cli->log_fatal('example output');
10366  
10367 my $output_fatal_events = $cli->output_fatal_events;
10368  
10369 # ['example output']
10370  
10371 =back
10372  
10373 =over 4
10374  
10375 =item output_fatal_events example 3
10376  
10377 # given: synopsis
10378  
10379 package main;
10380  
10381 $cli->log_fatal('example output 1');
10382  
10383 $cli->log_fatal('example output 2');
10384  
10385 my $output_fatal_events = $cli->output_fatal_events;
10386  
10387 # ['example output 1', 'example output 2']
10388  
10389 =back
10390  
10391 =over 4
10392  
10393 =item output_fatal_events example 4
10394  
10395 # given: synopsis
10396  
10397 package main;
10398  
10399 $cli->log_fatal('example output 1');
10400  
10401 $cli->log_fatal('example output 2');
10402  
10403 my @output_fatal_events = $cli->output_fatal_events;
10404  
10405 # ('example output 1', 'example output 2')
10406  
10407 =back
10408  
10409 =cut
10410  
10411 =head2 output_info_events
10412  
10413 output_info_events() (arrayref)
10414  
10415 The output_info_events method returns the list of info output events as an
10416 arrayref in scalar context, and a list in list context.
10417  
10418 I<Since C<4.15>>
10419  
10420 =over 4
10421  
10422 =item output_info_events example 1
10423  
10424 # given: synopsis
10425  
10426 package main;
10427  
10428 $cli->log_warn('example output');
10429  
10430 my $output_info_events = $cli->output_info_events;
10431  
10432 # []
10433  
10434 =back
10435  
10436 =over 4
10437  
10438 =item output_info_events example 2
10439  
10440 # given: synopsis
10441  
10442 package main;
10443  
10444 $cli->log_info('example output');
10445  
10446 my $output_info_events = $cli->output_info_events;
10447  
10448 # ['example output']
10449  
10450 =back
10451  
10452 =over 4
10453  
10454 =item output_info_events example 3
10455  
10456 # given: synopsis
10457  
10458 package main;
10459  
10460 $cli->log_info('example output 1');
10461  
10462 $cli->log_info('example output 2');
10463  
10464 my $output_info_events = $cli->output_info_events;
10465  
10466 # ['example output 1', 'example output 2']
10467  
10468 =back
10469  
10470 =over 4
10471  
10472 =item output_info_events example 4
10473  
10474 # given: synopsis
10475  
10476 package main;
10477  
10478 $cli->log_info('example output 1');
10479  
10480 $cli->log_info('example output 2');
10481  
10482 my @output_info_events = $cli->output_info_events;
10483  
10484 # ('example output 1', 'example output 2')
10485  
10486 =back
10487  
10488 =cut
10489  
10490 =head2 output_trace_events
10491  
10492 output_trace_events() (arrayref)
10493  
10494 The output_trace_events method returns the list of trace output events as an
10495 arrayref in scalar context, and a list in list context.
10496  
10497 I<Since C<4.15>>
10498  
10499 =over 4
10500  
10501 =item output_trace_events example 1
10502  
10503 # given: synopsis
10504  
10505 package main;
10506  
10507 $cli->log_info('example output');
10508  
10509 my $output_trace_events = $cli->output_trace_events;
10510  
10511 # []
10512  
10513 =back
10514  
10515 =over 4
10516  
10517 =item output_trace_events example 2
10518  
10519 # given: synopsis
10520  
10521 package main;
10522  
10523 $cli->log_trace('example output');
10524  
10525 my $output_trace_events = $cli->output_trace_events;
10526  
10527 # ['example output']
10528  
10529 =back
10530  
10531 =over 4
10532  
10533 =item output_trace_events example 3
10534  
10535 # given: synopsis
10536  
10537 package main;
10538  
10539 $cli->log_trace('example output 1');
10540  
10541 $cli->log_trace('example output 2');
10542  
10543 my $output_trace_events = $cli->output_trace_events;
10544  
10545 # ['example output 1', 'example output 2']
10546  
10547 =back
10548  
10549 =over 4
10550  
10551 =item output_trace_events example 4
10552  
10553 # given: synopsis
10554  
10555 package main;
10556  
10557 $cli->log_trace('example output 1');
10558  
10559 $cli->log_trace('example output 2');
10560  
10561 my @output_trace_events = $cli->output_trace_events;
10562  
10563 # ('example output 1', 'example output 2')
10564  
10565 =back
10566  
10567 =cut
10568  
10569 =head2 output_warn_events
10570  
10571 output_warn_events() (arrayref)
10572  
10573 The output_warn_events method returns the list of warn output events as an
10574 arrayref in scalar context, and a list in list context.
10575  
10576 I<Since C<4.15>>
10577  
10578 =over 4
10579  
10580 =item output_warn_events example 1
10581  
10582 # given: synopsis
10583  
10584 package main;
10585  
10586 $cli->log_info('example output');
10587  
10588 my $output_warn_events = $cli->output_warn_events;
10589  
10590 # []
10591  
10592 =back
10593  
10594 =over 4
10595  
10596 =item output_warn_events example 2
10597  
10598 # given: synopsis
10599  
10600 package main;
10601  
10602 $cli->log_warn('example output');
10603  
10604 my $output_warn_events = $cli->output_warn_events;
10605  
10606 # ['example output']
10607  
10608 =back
10609  
10610 =over 4
10611  
10612 =item output_warn_events example 3
10613  
10614 # given: synopsis
10615  
10616 package main;
10617  
10618 $cli->log_warn('example output 1');
10619  
10620 $cli->log_warn('example output 2');
10621  
10622 my $output_warn_events = $cli->output_warn_events;
10623  
10624 # ['example output 1', 'example output 2']
10625  
10626 =back
10627  
10628 =over 4
10629  
10630 =item output_warn_events example 4
10631  
10632 # given: synopsis
10633  
10634 package main;
10635  
10636 $cli->log_warn('example output 1');
10637  
10638 $cli->log_warn('example output 2');
10639  
10640 my @output_warn_events = $cli->output_warn_events;
10641  
10642 # ('example output 1', 'example output 2')
10643  
10644 =back
10645  
10646 =cut
10647  
10648 =head2 parse
10649  
10650 parse(any @args) (Venus::Cli)
10651  
10652 The parse method accepts arbitrary input (typically strings or arrayrefs of
10653 strings) and parses out the arguments and options made available via
10654 L</parsed_arguments> and L</parsed_options> respectively. If no arguments are
10655 provided C<@ARGV> is used as a default.
10656  
10657 I<Since C<4.15>>
10658  
10659 =over 4
10660  
10661 =item parse example 1
10662  
10663 package main;
10664  
10665 use Venus::Cli;
10666  
10667 my $cli = Venus::Cli->new(name => 'mycli');
10668  
10669 my $parse = $cli->parse;
10670  
10671 # bless(..., "Venus::Cli")
10672  
10673 # $cli->parsed_arguments
10674  
10675 # []
10676  
10677 # $result->parsed_options
10678  
10679 # {}
10680  
10681 =back
10682  
10683 =over 4
10684  
10685 =item parse example 2
10686  
10687 package main;
10688  
10689 use Venus::Cli;
10690  
10691 my $cli = Venus::Cli->new(name => 'mycli');
10692  
10693 my $parse = $cli->parse('hello', 'world');
10694  
10695 # bless(..., "Venus::Cli")
10696  
10697 # $cli->parsed_arguments
10698  
10699 # ['hello', 'world']
10700  
10701 # $result->parsed_options
10702  
10703 # {}
10704  
10705 =back
10706  
10707 =over 4
10708  
10709 =item parse example 3
10710  
10711 package main;
10712  
10713 use Venus::Cli;
10714  
10715 my $cli = Venus::Cli->new(name => 'mycli');
10716  
10717 $cli->option('input', {
10718 type => 'string',
10719 });
10720  
10721 $cli->option('output', {
10722 type => 'string',
10723 });
10724  
10725 $cli->argument('extra', {
10726 range => '0:',
10727 type => 'string',
10728 });
10729  
10730 my $parse = $cli->parse('--input', 'stdin', '--output', 'stdout', 'hello', 'world');
10731  
10732 # bless(..., "Venus::Cli")
10733  
10734 # $cli->parsed_arguments
10735  
10736 # ['hello', 'world']
10737  
10738 # $result->parsed_options
10739  
10740 # {input => 'stdin', output => 'stdout'}
10741  
10742 =back
10743  
10744 =cut
10745  
10746 =head2 parsed
10747  
10748 parsed() (arrayref | hashref)
10749  
10750 The parsed method is shorthand for calling the L</parsed_arguments> and/or
10751 L</parsed_options> method directly. In scalar context this method returns
10752 L</parsed_options>. In list context returns L</parsed_options> and
10753 L</parsed_arguments> in that order.
10754  
10755 I<Since C<4.15>>
10756  
10757 =over 4
10758  
10759 =item parsed example 1
10760  
10761 package main;
10762  
10763 use Venus::Cli;
10764  
10765 my $cli = Venus::Cli->new(name => 'mycli');
10766  
10767 my $parsed = $cli->parsed;
10768  
10769 # {}
10770  
10771 =back
10772  
10773 =over 4
10774  
10775 =item parsed example 2
10776  
10777 package main;
10778  
10779 use Venus::Cli;
10780  
10781 my $cli = Venus::Cli->new(name => 'mycli');
10782  
10783 $cli->parse('hello world');
10784  
10785 my $parsed = $cli->parsed;
10786  
10787 # {}
10788  
10789 =back
10790  
10791 =over 4
10792  
10793 =item parsed example 3
10794  
10795 package main;
10796  
10797 use Venus::Cli;
10798  
10799 my $cli = Venus::Cli->new(name => 'mycli');
10800  
10801 $cli->parse('hello', 'world');
10802  
10803 my ($options, $arguments) = $cli->parsed;
10804  
10805 # ({}, ['hello', 'world'])
10806  
10807 =back
10808  
10809 =over 4
10810  
10811 =item parsed example 4
10812  
10813 package main;
10814  
10815 use Venus::Cli;
10816  
10817 my $cli = Venus::Cli->new(name => 'mycli');
10818  
10819 $cli->option('input', {
10820 type => 'string',
10821 });
10822  
10823 $cli->option('output', {
10824 type => 'string',
10825 });
10826  
10827 $cli->argument('extra', {
10828 range => '0:',
10829 type => 'string',
10830 });
10831  
10832 my $parse = $cli->parse('--input', 'stdin', '--output', 'stdout', 'hello world');
10833  
10834 my $parsed = $cli->parsed;
10835  
10836 # {input => 'stdin', output => 'stdout'}
10837  
10838 =back
10839  
10840 =over 4
10841  
10842 =item parsed example 5
10843  
10844 package main;
10845  
10846 use Venus::Cli;
10847  
10848 my $cli = Venus::Cli->new(name => 'mycli');
10849  
10850 $cli->option('input', {
10851 type => 'string',
10852 });
10853  
10854 $cli->option('output', {
10855 type => 'string',
10856 });
10857  
10858 $cli->argument('extra', {
10859 range => '0:',
10860 type => 'string',
10861 });
10862  
10863 my $parse = $cli->parse('--input', 'stdin', '--output', 'stdout', 'hello', 'world');
10864  
10865 my ($options, $arguments) = $cli->parsed;
10866  
10867 # ({input => 'stdin', output => 'stdout'}, ['hello', 'world'])
10868  
10869 =back
10870  
10871 =cut
10872  
10873 =head2 parsed_arguments
10874  
10875 parsed_arguments(arrayref $data) (arrayref)
10876  
10877 The parsed_arguments method gets or sets the set of parsed arguments. This
10878 method calls L</parse> if no data has been set.
10879  
10880 I<Since C<4.15>>
10881  
10882 =over 4
10883  
10884 =item parsed_arguments example 1
10885  
10886 package main;
10887  
10888 use Venus::Cli;
10889  
10890 my $cli = Venus::Cli->new(name => 'mycli');
10891  
10892 $cli->option('input', {
10893 type => 'string',
10894 });
10895  
10896 $cli->option('output', {
10897 type => 'string',
10898 });
10899  
10900 $cli->argument('extra', {
10901 range => '0:',
10902 type => 'string',
10903 });
10904  
10905 local @ARGV = qw(--input stdin --output stdout hello world);
10906  
10907 my $parsed_arguments = $cli->parsed_arguments;
10908  
10909 # ['hello', 'world']
10910  
10911 =back
10912  
10913 =cut
10914  
10915 =head2 parsed_options
10916  
10917 parsed_options(hashref $data) (hashref)
10918  
10919 The parsed_options method method gets or sets the set of parsed options. This
10920 method calls L</parse> if no data has been set.
10921  
10922 I<Since C<4.15>>
10923  
10924 =over 4
10925  
10926 =item parsed_options example 1
10927  
10928 package main;
10929  
10930 use Venus::Cli;
10931  
10932 my $cli = Venus::Cli->new(name => 'mycli');
10933  
10934 $cli->option('input', {
10935 type => 'string',
10936 });
10937  
10938 $cli->option('output', {
10939 type => 'string',
10940 });
10941  
10942 $cli->argument('extra', {
10943 range => '0:',
10944 type => 'string',
10945 });
10946  
10947 local @ARGV = qw(--input stdin --output stdout hello world);
10948  
10949 my $parsed_options = $cli->parsed_options;
10950  
10951 # {input => 'stdin', output => 'stdout'}
10952  
10953 =back
10954  
10955 =cut
10956  
10957 =head2 pass
10958  
10959 pass(string | coderef $code, any @args) (any)
10960  
10961 The pass method terminates the program with a the exit code C<0>, indicating a
10962 successful exit. This method can be used to end the program explicitly, either
10963 after a specific task is completed or when an error occurs that requires
10964 halting execution. This method can dispatch to another method or callback
10965 before exiting.
10966  
10967 I<Since C<4.15>>
10968  
10969 =over 4
10970  
10971 =item pass example 1
10972  
10973 package main;
10974  
10975 use Venus::Cli;
10976  
10977 my $cli = Venus::Cli->new(name => 'mycli');
10978  
10979 $cli->pass;
10980  
10981 # 0
10982  
10983 =back
10984  
10985 =over 4
10986  
10987 =item pass example 2
10988  
10989 package main;
10990  
10991 use Venus::Cli;
10992  
10993 my $cli = Venus::Cli->new(name => 'mycli');
10994  
10995 $cli->pass(sub{
10996 $cli->{dispatched} = 1;
10997 });
10998  
10999 # 0
11000  
11001 =back
11002  
11003 =cut
11004  
11005 =head2 reorder
11006  
11007 reorder() (Venus::Cli)
11008  
11009 The reorder method re-indexes the L<"arguments"|/argument_list>,
11010 L<"choices"|/choice_list>, and L<"options"|/option_list>, based on the order
11011 they were declared.
11012  
11013 I<Since C<4.15>>
11014  
11015 =over 4
11016  
11017 =item reorder example 1
11018  
11019 package main;
11020  
11021 use Venus::Cli;
11022  
11023 my $cli = Venus::Cli->new(name => 'mycli');
11024  
11025 $cli->argument('input', {
11026 type => 'string',
11027 index => 1,
11028 });
11029  
11030 $cli->argument('output', {
11031 type => 'string',
11032 index => 3,
11033 });
11034  
11035 $cli->option('file', {
11036 type => 'string',
11037 index => 1,
11038 });
11039  
11040 $cli->option('directory', {
11041 type => 'string',
11042 index => 3,
11043 });
11044  
11045 $cli->choice('stdin', {
11046 argument => 'input',
11047 type => 'string',
11048 index => 1,
11049 });
11050  
11051 $cli->choice('stdout', {
11052 argument => 'output',
11053 type => 'string',
11054 index => 3,
11055 });
11056  
11057 my $reorder = $cli->reorder;
11058  
11059 # bless(..., "Venus::Cli")
11060  
11061 =back
11062  
11063 =cut
11064  
11065 =head2 reorder_arguments
11066  
11067 reorder_arguments() (Venus::Cli)
11068  
11069 The reorder_arguments method re-indexes the L<"arguments"|/argument_list> based
11070 on the order they were declared.
11071  
11072 I<Since C<4.15>>
11073  
11074 =over 4
11075  
11076 =item reorder_arguments example 1
11077  
11078 package main;
11079  
11080 use Venus::Cli;
11081  
11082 my $cli = Venus::Cli->new(name => 'mycli');
11083  
11084 $cli->argument('input', {
11085 type => 'string',
11086 index => 1,
11087 });
11088  
11089 $cli->argument('output', {
11090 type => 'string',
11091 index => 3,
11092 });
11093  
11094 my $reorder_arguments = $cli->reorder_arguments;
11095  
11096 # bless(..., "Venus::Cli")
11097  
11098 =back
11099  
11100 =cut
11101  
11102 =head2 reorder_choices
11103  
11104 reorder_choices() (Venus::Cli)
11105  
11106 The reorder_choices method re-indexes the L<"choices"|/choice_list> based on
11107 the order they were declared.
11108  
11109 I<Since C<4.15>>
11110  
11111 =over 4
11112  
11113 =item reorder_choices example 1
11114  
11115 package main;
11116  
11117 use Venus::Cli;
11118  
11119 my $cli = Venus::Cli->new(name => 'mycli');
11120  
11121 $cli->argument('input', {
11122 type => 'string',
11123 index => 1,
11124 });
11125  
11126 $cli->argument('output', {
11127 type => 'string',
11128 index => 3,
11129 });
11130  
11131 $cli->choice('stdin', {
11132 argument => 'input',
11133 type => 'string',
11134 index => 1,
11135 });
11136  
11137 $cli->choice('stdout', {
11138 argument => 'output',
11139 type => 'string',
11140 index => 3,
11141 });
11142  
11143 my $reorder_choices = $cli->reorder_choices;
11144  
11145 # bless(..., "Venus::Cli")
11146  
11147 =back
11148  
11149 =cut
11150  
11151 =head2 reorder_options
11152  
11153 reorder_options() (Venus::Cli)
11154  
11155 The reorder_options method re-indexes the L<"options"|/option_list> based on
11156 the order they were declared.
11157  
11158 I<Since C<4.15>>
11159  
11160 =over 4
11161  
11162 =item reorder_options example 1
11163  
11164 package main;
11165  
11166 use Venus::Cli;
11167  
11168 my $cli = Venus::Cli->new(name => 'mycli');
11169  
11170 $cli->option('file', {
11171 type => 'string',
11172 index => 1,
11173 });
11174  
11175 $cli->option('directory', {
11176 type => 'string',
11177 index => 3,
11178 });
11179  
11180 my $reorder_options = $cli->reorder_options;
11181  
11182 # bless(..., "Venus::Cli")
11183  
11184 =back
11185  
11186 =cut
11187  
11188 =head2 reorder_routes
11189  
11190 reorder_routes() (Venus::Cli)
11191  
11192 The reorder_routes method reorders the registered routes based on their
11193 indices. This method returns the invocant.
11194  
11195 I<Since C<4.15>>
11196  
11197 =over 4
11198  
11199 =item reorder_routes example 1
11200  
11201 package main;
11202  
11203 use Venus::Cli;
11204  
11205 my $cli = Venus::Cli->new(name => 'mycli');
11206  
11207 $cli->route('user create', {
11208 handler => 'handle_user_create',
11209 index => 1,
11210 });
11211  
11212 $cli->route('user delete', {
11213 handler => 'handle_user_delete',
11214 index => 0,
11215 });
11216  
11217 my $reorder_routes = $cli->reorder_routes;
11218  
11219 # bless(..., "Venus::Cli")
11220  
11221 =back
11222  
11223 =cut
11224  
11225 =head2 required
11226  
11227 required(string $method, any @args) (any)
11228  
11229 The required method is a configuration dispatcher and shorthand for
11230 C<{'required', true}>. It returns the data or dispatches to the next
11231 configuration dispatcher based on the name provided and merges the
11232 configurations produced.
11233  
11234 I<Since C<4.15>>
11235  
11236 =over 4
11237  
11238 =item required example 1
11239  
11240 # given: synopsis
11241  
11242 package main;
11243  
11244 my $required = $cli->required;
11245  
11246 # {required => true}
11247  
11248 =back
11249  
11250 =over 4
11251  
11252 =item required example 2
11253  
11254 # given: synopsis
11255  
11256 package main;
11257  
11258 my $required = $cli->required(undef, {type => 'boolean'});
11259  
11260 # {required => true, type => 'boolean'}
11261  
11262 =back
11263  
11264 =over 4
11265  
11266 =item required example 3
11267  
11268 # given: synopsis
11269  
11270 package main;
11271  
11272 my $required = $cli->required('option', 'example');
11273  
11274 # {
11275 # name => 'example',
11276 # label => undef,
11277 # help => 'Expects a string value',
11278 # default => undef,
11279 # aliases => [],
11280 # multiples => 0,
11281 # prompt => undef,
11282 # range => undef,
11283 # required => 1,
11284 # type => 'string',
11285 # index => 0,
11286 # wants => 'string',
11287 # }
11288  
11289 =back
11290  
11291 =cut
11292  
11293 =head2 reset
11294  
11295 reset() (Venus::Cli)
11296  
11297 The reset method clears the argument and option configurations, cached parsed
11298 values, and returns the invocant.
11299  
11300 I<Since C<4.15>>
11301  
11302 =over 4
11303  
11304 =item reset example 1
11305  
11306 # given: synopsis
11307  
11308 package main;
11309  
11310 $cli->option('input', {
11311 type => 'string',
11312 });
11313  
11314 $cli->option('output', {
11315 type => 'string',
11316 });
11317  
11318 my $reset = $cli->reset;
11319  
11320 # bless(..., "Venus::Cli")
11321  
11322 =back
11323  
11324 =over 4
11325  
11326 =item reset example 2
11327  
11328 # given: synopsis
11329  
11330 package main;
11331  
11332 $cli->option('input', {
11333 type => 'string',
11334 });
11335  
11336 $cli->option('output', {
11337 type => 'string',
11338 });
11339  
11340 $cli->parse('--input', 'stdin', '--output', 'stdout');
11341  
11342 my $reset = $cli->reset;
11343  
11344 # bless(..., "Venus::Cli")
11345  
11346 =back
11347  
11348 =cut
11349  
11350 =head2 route
11351  
11352 route(string $name, hashref $data) (maybe[hashref])
11353  
11354 The route method registers and returns the configuration for the route
11355 specified. The method takes a name (route name) and a hashref of configuration
11356 values. The possible configuration values are as follows:
11357  
11358 =over 4
11359  
11360 =item *
11361  
11362 The C<name> key holds the name of the route.
11363  
11364 =item *
11365  
11366 The C<label> key holds the name of the route as it should be displayed in the
11367 CLI help text.
11368  
11369 =item *
11370  
11371 The C<help> key holds the help text specific to this route.
11372  
11373 =item *
11374  
11375 The C<argument> key holds the name of the argument that this route is
11376 associated with.
11377  
11378 =item *
11379  
11380 The C<choice> key holds the name of the choice that this route is associated
11381 with.
11382  
11383 =item *
11384  
11385 The C<handler> key holds the (local) method name, or L<Venus::Cli> derived
11386 package, or coderef to execute when this route is matched.
11387  
11388 =item *
11389  
11390 The C<range> key holds the range specification for the argument.
11391  
11392 =item *
11393  
11394 The C<wants> key holds the text to be used as a value placeholder in the CLI
11395 help text.
11396  
11397 =back
11398  
11399 I<Since C<4.15>>
11400  
11401 =over 4
11402  
11403 =item route example 1
11404  
11405 package main;
11406  
11407 use Venus::Cli;
11408  
11409 my $cli = Venus::Cli->new(name => 'mycli');
11410  
11411 my $route = $cli->route('user create');
11412  
11413 # undef
11414  
11415 =back
11416  
11417 =over 4
11418  
11419 =item route example 2
11420  
11421 package main;
11422  
11423 use Venus::Cli;
11424  
11425 my $cli = Venus::Cli->new(name => 'mycli');
11426  
11427 my $route = $cli->route('user create', {
11428 handler => 'handle_user_create',
11429 });
11430  
11431 # {
11432 # name => 'user create',
11433 # label => undef,
11434 # help => undef,
11435 # argument => undef,
11436 # choice => undef,
11437 # handler => 'handle_user_create',
11438 # range => undef,
11439 # index => 0,
11440 # }
11441  
11442 =back
11443  
11444 =over 4
11445  
11446 =item route example 3
11447  
11448 package main;
11449  
11450 use Venus::Cli;
11451  
11452 my $cli = Venus::Cli->new(name => 'mycli');
11453  
11454 $cli->route('user create', {
11455 handler => 'handle_user_create',
11456 });
11457  
11458 my $route = $cli->route('user create');
11459  
11460 # {
11461 # name => 'user create',
11462 # label => undef,
11463 # help => undef,
11464 # argument => undef,
11465 # choice => undef,
11466 # handler => 'handle_user_create',
11467 # range => undef,
11468 # index => 0,
11469 # }
11470  
11471 =back
11472  
11473 =over 4
11474  
11475 =item route example 4
11476  
11477 package main;
11478  
11479 use Venus::Cli;
11480  
11481 my $cli = Venus::Cli->new(name => 'mycli');
11482  
11483 $cli->route('user create', {
11484 handler => 'handle_user_create',
11485 });
11486  
11487 my $route = $cli->route('user create', undef);
11488  
11489 # {
11490 # name => 'user create',
11491 # ...
11492 # }
11493  
11494 =back
11495  
11496 =cut
11497  
11498 =head2 route_argument
11499  
11500 route_argument(string $name) (maybe[hashref])
11501  
11502 The route_argument method returns the argument configuration for the named
11503 route.
11504  
11505 I<Since C<4.15>>
11506  
11507 =over 4
11508  
11509 =item route_argument example 1
11510  
11511 package main;
11512  
11513 use Venus::Cli;
11514  
11515 my $cli = Venus::Cli->new(name => 'mycli');
11516  
11517 my $route_argument = $cli->route_argument;
11518  
11519 # ""
11520  
11521 =back
11522  
11523 =over 4
11524  
11525 =item route_argument example 2
11526  
11527 package main;
11528  
11529 use Venus::Cli;
11530  
11531 my $cli = Venus::Cli->new(name => 'mycli');
11532  
11533 $cli->argument('command', {
11534 range => ':1',
11535 });
11536  
11537 $cli->route('user create', {
11538 argument => 'command',
11539 handler => 'handle_user_create',
11540 });
11541  
11542 my $route_argument = $cli->route_argument('user create');
11543  
11544 # {
11545 # name => 'command',
11546 # ...
11547 # }
11548  
11549 =back
11550  
11551 =cut
11552  
11553 =head2 route_choice
11554  
11555 route_choice(string $name) (maybe[hashref])
11556  
11557 The route_choice method returns the choice configuration for the named route.
11558  
11559 I<Since C<4.15>>
11560  
11561 =over 4
11562  
11563 =item route_choice example 1
11564  
11565 package main;
11566  
11567 use Venus::Cli;
11568  
11569 my $cli = Venus::Cli->new(name => 'mycli');
11570  
11571 my $route_choice = $cli->route_choice;
11572  
11573 # ""
11574  
11575 =back
11576  
11577 =over 4
11578  
11579 =item route_choice example 2
11580  
11581 package main;
11582  
11583 use Venus::Cli;
11584  
11585 my $cli = Venus::Cli->new(name => 'mycli');
11586  
11587 $cli->argument('command', {
11588 range => ':1',
11589 });
11590  
11591 $cli->choice('user create', {
11592 argument => 'command',
11593 });
11594  
11595 $cli->route('user create', {
11596 argument => 'command',
11597 choice => 'user create',
11598 handler => 'handle_user_create',
11599 });
11600  
11601 my $route_choice = $cli->route_choice('user create');
11602  
11603 # {
11604 # name => 'user create',
11605 # ...
11606 # }
11607  
11608 =back
11609  
11610 =cut
11611  
11612 =head2 route_count
11613  
11614 route_count() (number)
11615  
11616 The route_count method returns the number of registered routes.
11617  
11618 I<Since C<4.15>>
11619  
11620 =over 4
11621  
11622 =item route_count example 1
11623  
11624 package main;
11625  
11626 use Venus::Cli;
11627  
11628 my $cli = Venus::Cli->new(name => 'mycli');
11629  
11630 my $route_count = $cli->route_count;
11631  
11632 # 0
11633  
11634 =back
11635  
11636 =over 4
11637  
11638 =item route_count example 2
11639  
11640 package main;
11641  
11642 use Venus::Cli;
11643  
11644 my $cli = Venus::Cli->new(name => 'mycli');
11645  
11646 $cli->route('user create', {
11647 handler => 'handle_user_create',
11648 });
11649  
11650 $cli->route('user delete', {
11651 handler => 'handle_user_delete',
11652 });
11653  
11654 my $route_count = $cli->route_count;
11655  
11656 # 2
11657  
11658 =back
11659  
11660 =cut
11661  
11662 =head2 route_handler
11663  
11664 route_handler(string $name) (maybe[string | coderef])
11665  
11666 The route_handler method returns the handler for the named route.
11667  
11668 I<Since C<4.15>>
11669  
11670 =over 4
11671  
11672 =item route_handler example 1
11673  
11674 package main;
11675  
11676 use Venus::Cli;
11677  
11678 my $cli = Venus::Cli->new(name => 'mycli');
11679  
11680 my $route_handler = $cli->route_handler;
11681  
11682 # undef
11683  
11684 =back
11685  
11686 =over 4
11687  
11688 =item route_handler example 2
11689  
11690 package main;
11691  
11692 use Venus::Cli;
11693  
11694 my $cli = Venus::Cli->new(name => 'mycli');
11695  
11696 $cli->route('user create', {
11697 handler => 'handle_user_create',
11698 });
11699  
11700 my $route_handler = $cli->route_handler('user create');
11701  
11702 # "handle_user_create"
11703  
11704 =back
11705  
11706 =over 4
11707  
11708 =item route_handler example 3
11709  
11710 package main;
11711  
11712 use Venus::Cli;
11713  
11714 my $cli = Venus::Cli->new(name => 'mycli');
11715  
11716 my $handler = sub { ... };
11717  
11718 $cli->route('user create', {
11719 handler => $handler,
11720 });
11721  
11722 my $route_handler = $cli->route_handler('user create');
11723  
11724 # sub { ... }
11725  
11726 =back
11727  
11728 =cut
11729  
11730 =head2 route_help
11731  
11732 route_help(string $name) (string)
11733  
11734 The route_help method returns the help text for the named route.
11735  
11736 I<Since C<4.15>>
11737  
11738 =over 4
11739  
11740 =item route_help example 1
11741  
11742 package main;
11743  
11744 use Venus::Cli;
11745  
11746 my $cli = Venus::Cli->new(name => 'mycli');
11747  
11748 my $route_help = $cli->route_help;
11749  
11750 # ""
11751  
11752 =back
11753  
11754 =over 4
11755  
11756 =item route_help example 2
11757  
11758 package main;
11759  
11760 use Venus::Cli;
11761  
11762 my $cli = Venus::Cli->new(name => 'mycli');
11763  
11764 $cli->route('user create', {
11765 handler => 'handle_user_create',
11766 help => 'Create a new user',
11767 });
11768  
11769 my $route_help = $cli->route_help('user create');
11770  
11771 # "Create a new user"
11772  
11773 =back
11774  
11775 =cut
11776  
11777 =head2 route_label
11778  
11779 route_label(string $name) (string)
11780  
11781 The route_label method returns the label for the named route.
11782  
11783 I<Since C<4.15>>
11784  
11785 =over 4
11786  
11787 =item route_label example 1
11788  
11789 package main;
11790  
11791 use Venus::Cli;
11792  
11793 my $cli = Venus::Cli->new(name => 'mycli');
11794  
11795 my $route_label = $cli->route_label;
11796  
11797 # ""
11798  
11799 =back
11800  
11801 =over 4
11802  
11803 =item route_label example 2
11804  
11805 package main;
11806  
11807 use Venus::Cli;
11808  
11809 my $cli = Venus::Cli->new(name => 'mycli');
11810  
11811 $cli->route('user create', {
11812 handler => 'handle_user_create',
11813 label => 'User Create',
11814 });
11815  
11816 my $route_label = $cli->route_label('user create');
11817  
11818 # "User Create"
11819  
11820 =back
11821  
11822 =cut
11823  
11824 =head2 route_list
11825  
11826 route_list() (arrayref[hashref])
11827  
11828 The route_list method returns a list of all registered route configurations in
11829 insertion order.
11830  
11831 I<Since C<4.15>>
11832  
11833 =over 4
11834  
11835 =item route_list example 1
11836  
11837 package main;
11838  
11839 use Venus::Cli;
11840  
11841 my $cli = Venus::Cli->new(name => 'mycli');
11842  
11843 my $route_list = $cli->route_list;
11844  
11845 # []
11846  
11847 =back
11848  
11849 =over 4
11850  
11851 =item route_list example 2
11852  
11853 package main;
11854  
11855 use Venus::Cli;
11856  
11857 my $cli = Venus::Cli->new(name => 'mycli');
11858  
11859 $cli->route('user create', {
11860 handler => 'handle_user_create',
11861 });
11862  
11863 $cli->route('user delete', {
11864 handler => 'handle_user_delete',
11865 });
11866  
11867 my $route_list = $cli->route_list;
11868  
11869 # [
11870 # { name => 'user create', ... },
11871 # { name => 'user delete', ... },
11872 # ]
11873  
11874 =back
11875  
11876 =cut
11877  
11878 =head2 route_name
11879  
11880 route_name(string $name) (string)
11881  
11882 The route_name method returns the name of the named route.
11883  
11884 I<Since C<4.15>>
11885  
11886 =over 4
11887  
11888 =item route_name example 1
11889  
11890 package main;
11891  
11892 use Venus::Cli;
11893  
11894 my $cli = Venus::Cli->new(name => 'mycli');
11895  
11896 my $route_name = $cli->route_name;
11897  
11898 # ""
11899  
11900 =back
11901  
11902 =over 4
11903  
11904 =item route_name example 2
11905  
11906 package main;
11907  
11908 use Venus::Cli;
11909  
11910 my $cli = Venus::Cli->new(name => 'mycli');
11911  
11912 $cli->route('user create', {
11913 handler => 'handle_user_create',
11914 });
11915  
11916 my $route_name = $cli->route_name('user create');
11917  
11918 # "user create"
11919  
11920 =back
11921  
11922 =cut
11923  
11924 =head2 route_names
11925  
11926 route_names() (arrayref[string])
11927  
11928 The route_names method returns a list of all registered route names in
11929 insertion order.
11930  
11931 I<Since C<4.15>>
11932  
11933 =over 4
11934  
11935 =item route_names example 1
11936  
11937 package main;
11938  
11939 use Venus::Cli;
11940  
11941 my $cli = Venus::Cli->new(name => 'mycli');
11942  
11943 my $route_names = $cli->route_names;
11944  
11945 # []
11946  
11947 =back
11948  
11949 =over 4
11950  
11951 =item route_names example 2
11952  
11953 package main;
11954  
11955 use Venus::Cli;
11956  
11957 my $cli = Venus::Cli->new(name => 'mycli');
11958  
11959 $cli->route('user create', {
11960 handler => 'handle_user_create',
11961 });
11962  
11963 $cli->route('user delete', {
11964 handler => 'handle_user_delete',
11965 });
11966  
11967 my $route_names = $cli->route_names;
11968  
11969 # ["user create", "user delete"]
11970  
11971 =back
11972  
11973 =cut
11974  
11975 =head2 route_range
11976  
11977 route_range(string $name) (string)
11978  
11979 The route_range method returns the range for the named route.
11980  
11981 I<Since C<4.15>>
11982  
11983 =over 4
11984  
11985 =item route_range example 1
11986  
11987 package main;
11988  
11989 use Venus::Cli;
11990  
11991 my $cli = Venus::Cli->new(name => 'mycli');
11992  
11993 my $route_range = $cli->route_range;
11994  
11995 # ""
11996  
11997 =back
11998  
11999 =over 4
12000  
12001 =item route_range example 2
12002  
12003 package main;
12004  
12005 use Venus::Cli;
12006  
12007 my $cli = Venus::Cli->new(name => 'mycli');
12008  
12009 $cli->route('user create', {
12010 handler => 'handle_user_create',
12011 range => ':1',
12012 });
12013  
12014 my $route_range = $cli->route_range('user create');
12015  
12016 # ":1"
12017  
12018 =back
12019  
12020 =cut
12021  
12022 =head2 single
12023  
12024 single(string $method, any @args) (any)
12025  
12026 The single method is a configuration dispatcher and shorthand for
12027 C<{'multiples', false}>. It returns the data or dispatches to the next
12028 configuration dispatcher based on the name provided and merges the
12029 configurations produced.
12030  
12031 I<Since C<4.15>>
12032  
12033 =over 4
12034  
12035 =item single example 1
12036  
12037 # given: synopsis
12038  
12039 package main;
12040  
12041 my $single = $cli->single;
12042  
12043 # {multiples => false}
12044  
12045 =back
12046  
12047 =over 4
12048  
12049 =item single example 2
12050  
12051 # given: synopsis
12052  
12053 package main;
12054  
12055 my $single = $cli->single(undef, {type => 'boolean'});
12056  
12057 # {multiples => false, type => 'boolean'}
12058  
12059 =back
12060  
12061 =over 4
12062  
12063 =item single example 3
12064  
12065 # given: synopsis
12066  
12067 package main;
12068  
12069 my $single = $cli->single('option', 'example');
12070  
12071 # {
12072 # name => 'example',
12073 # label => undef,
12074 # help => 'Expects a string value',
12075 # default => undef,
12076 # aliases => [],
12077 # multiples => 0,
12078 # prompt => undef,
12079 # range => undef,
12080 # required => 0,
12081 # type => 'string',
12082 # index => 0,
12083 # wants => 'string',
12084 # }
12085  
12086 =back
12087  
12088 =cut
12089  
12090 =head2 spec
12091  
12092 spec(hashref $data) (Venus::Cli)
12093  
12094 The spec method configures the CLI instance from a hashref specification. It
12095 accepts a hashref containing any of the following keys: C<name>, C<version>,
12096 C<summary>, C<description>, C<header>, C<footer>, C<arguments>, C<options>,
12097 C<choices>, C<routes>, and C<commands>. The method returns the invocant.
12098  
12099 I<Since C<4.15>>
12100  
12101 =over 4
12102  
12103 =item spec example 1
12104  
12105 package main;
12106  
12107 use Venus::Cli;
12108  
12109 my $cli = Venus::Cli->new;
12110  
12111 my $spec = $cli->spec;
12112  
12113 # bless(..., "Venus::Cli")
12114  
12115 =back
12116  
12117 =over 4
12118  
12119 =item spec example 2
12120  
12121 package main;
12122  
12123 use Venus::Cli;
12124  
12125 my $cli = Venus::Cli->new;
12126  
12127 my $spec = $cli->spec({
12128 name => 'mycli',
12129 version => '1.0.0',
12130 summary => 'My CLI application',
12131 });
12132  
12133 # bless(..., "Venus::Cli")
12134  
12135 =back
12136  
12137 =over 4
12138  
12139 =item spec example 3
12140  
12141 package main;
12142  
12143 use Venus::Cli;
12144  
12145 my $cli = Venus::Cli->new;
12146  
12147 my $spec = $cli->spec({
12148 name => 'mycli',
12149 options => [
12150 {
12151 name => 'verbose',
12152 type => 'boolean',
12153 aliases => ['v'],
12154 help => 'Enable verbose output',
12155 },
12156 {
12157 name => 'config',
12158 type => 'string',
12159 aliases => ['c'],
12160 help => 'Path to config file',
12161 },
12162 ],
12163 });
12164  
12165 # bless(..., "Venus::Cli")
12166  
12167 =back
12168  
12169 =over 4
12170  
12171 =item spec example 4
12172  
12173 package main;
12174  
12175 use Venus::Cli;
12176  
12177 my $cli = Venus::Cli->new;
12178  
12179 my $spec = $cli->spec({
12180 name => 'mycli',
12181 arguments => [
12182 {
12183 name => 'input',
12184 type => 'string',
12185 help => 'Input file path',
12186 },
12187 ],
12188 });
12189  
12190 # bless(..., "Venus::Cli")
12191  
12192 =back
12193  
12194 =over 4
12195  
12196 =item spec example 5
12197  
12198 package main;
12199  
12200 use Venus::Cli;
12201  
12202 my $cli = Venus::Cli->new;
12203  
12204 my $spec = $cli->spec({
12205 name => 'mycli',
12206 commands => [
12207 ['command', 'user', 'create', 'handle_user_create'],
12208 ['command', 'user', 'delete', 'handle_user_delete'],
12209 ],
12210 });
12211  
12212 # bless(..., "Venus::Cli")
12213  
12214 =back
12215  
12216 =over 4
12217  
12218 =item spec example 6
12219  
12220 package main;
12221  
12222 use Venus::Cli;
12223  
12224 my $cli = Venus::Cli->new;
12225  
12226 my $spec = $cli->spec({
12227 name => 'mycli',
12228 version => '1.0.0',
12229 summary => 'User management CLI',
12230 description => 'A command-line tool for managing users',
12231 header => 'Welcome to mycli',
12232 footer => 'For more info, visit example.com',
12233 arguments => [
12234 {
12235 name => 'action',
12236 type => 'string',
12237 range => '0',
12238 },
12239 ],
12240 options => [
12241 {
12242 name => 'verbose',
12243 type => 'boolean',
12244 aliases => ['v'],
12245 },
12246 ],
12247 choices => [
12248 {
12249 name => 'create',
12250 argument => 'action',
12251 help => 'Create a new user',
12252 },
12253 {
12254 name => 'delete',
12255 argument => 'action',
12256 help => 'Delete a user',
12257 },
12258 ],
12259 routes => [
12260 {
12261 name => 'create',
12262 argument => 'action',
12263 choice => 'create',
12264 handler => 'handle_create',
12265 },
12266 {
12267 name => 'delete',
12268 argument => 'action',
12269 choice => 'delete',
12270 handler => 'handle_delete',
12271 },
12272 ],
12273 });
12274  
12275 # bless(..., "Venus::Cli")
12276  
12277 =back
12278  
12279 =cut
12280  
12281 =head2 string
12282  
12283 string(string $method, any @args) (any)
12284  
12285 The string method is a configuration dispatcher and shorthand for C<{'type',
12286 'string'}>. It returns the data or dispatches to the next configuration
12287 dispatcher based on the name provided and merges the configurations produced.
12288  
12289 I<Since C<4.15>>
12290  
12291 =over 4
12292  
12293 =item string example 1
12294  
12295 # given: synopsis
12296  
12297 package main;
12298  
12299 my $string = $cli->string;
12300  
12301 # {type => 'string'}
12302  
12303 =back
12304  
12305 =over 4
12306  
12307 =item string example 2
12308  
12309 # given: synopsis
12310  
12311 package main;
12312  
12313 my $string = $cli->string(undef, {required => true});
12314  
12315 # {type => 'string', required => true}
12316  
12317 =back
12318  
12319 =over 4
12320  
12321 =item string example 3
12322  
12323 # given: synopsis
12324  
12325 package main;
12326  
12327 my $string = $cli->string('option', 'example');
12328  
12329 # {
12330 # name => 'example',
12331 # label => undef,
12332 # help => 'Expects a string value',
12333 # default => undef,
12334 # aliases => [],
12335 # multiples => 0,
12336 # prompt => undef,
12337 # range => undef,
12338 # required => 1,
12339 # type => 'string',
12340 # index => 0,
12341 # wants => 'string',
12342 # }
12343  
12344 =back
12345  
12346 =cut
12347  
12348 =head2 usage
12349  
12350 usage() (string)
12351  
12352 The usage method provides the command-line usage information for the CLI. It
12353 outputs details such as available choices, arguments, options, and a general
12354 summary of how to use the CLI. This method is useful for users needing guidance
12355 on the various arguments, options, and choices available, and how they work.
12356  
12357 I<Since C<4.15>>
12358  
12359 =over 4
12360  
12361 =item usage example 1
12362  
12363 package main;
12364  
12365 use Venus::Cli;
12366  
12367 my $cli = Venus::Cli->new(name => 'mycli');
12368  
12369 my $usage = $cli->usage;
12370  
12371 # "Usage: mycli"
12372  
12373 =back
12374  
12375 =over 4
12376  
12377 =item usage example 2
12378  
12379 package main;
12380  
12381 use Venus::Cli;
12382  
12383 my $cli = Venus::Cli->new(
12384 name => 'mycli',
12385 summary => 'Example summary',
12386 );
12387  
12388 my $usage = $cli->usage;
12389  
12390 # "mycli - Example summary
12391 #
12392 # Usage: mycli"
12393  
12394 =back
12395  
12396 =over 4
12397  
12398 =item usage example 3
12399  
12400 package main;
12401  
12402 use Venus::Cli;
12403  
12404 my $cli = Venus::Cli->new(
12405 name => 'mycli',
12406 summary => 'Example summary',
12407 version => '0.0.1',
12408 );
12409  
12410 my $usage = $cli->usage;
12411  
12412 # "mycli version 0.0.1 - Example summary
12413 #
12414 # Usage: mycli"
12415  
12416 =back
12417  
12418 =over 4
12419  
12420 =item usage example 4
12421  
12422 package main;
12423  
12424 use Venus::Cli;
12425  
12426 my $cli = Venus::Cli->new(
12427 name => 'mycli',
12428 summary => 'Example summary',
12429 version => '0.0.1',
12430 );
12431  
12432 $cli->argument('input', {
12433 type => 'string',
12434 });
12435  
12436 $cli->argument('output', {
12437 type => 'string',
12438 });
12439  
12440 my $usage = $cli->usage;
12441  
12442 # mycli version 0.0.1 - Example summary
12443 #
12444 # Usage: mycli [<input>] [<output>]
12445 #
12446 # Arguments:
12447 # [<input>]
12448 # Expects a string value
12449 # (optional)
12450 # [<output>]
12451 # Expects a string value
12452 # (optional)
12453  
12454 =back
12455  
12456 =over 4
12457  
12458 =item usage example 5
12459  
12460 package main;
12461  
12462 use Venus::Cli;
12463  
12464 my $cli = Venus::Cli->new(
12465 name => 'mycli',
12466 summary => 'Example summary',
12467 version => '0.0.1',
12468 );
12469  
12470 $cli->argument('input', {
12471 required => true,
12472 type => 'string',
12473 });
12474  
12475 $cli->argument('output', {
12476 default => 'file',
12477 type => 'string',
12478 });
12479  
12480 my $usage = $cli->usage;
12481  
12482 # mycli version 0.0.1 - Example summary
12483 #
12484 # Usage: mycli <input> [<output>]
12485 #
12486 # Arguments:
12487 # <input>
12488 # Expects a string value
12489 # (required)
12490 # [<output>]
12491 # Expects a string value
12492 # (optional)
12493 # Default: file
12494  
12495 =back
12496  
12497 =over 4
12498  
12499 =item usage example 6
12500  
12501 package main;
12502  
12503 use Venus::Cli;
12504  
12505 my $cli = Venus::Cli->new(
12506 name => 'mycli',
12507 summary => 'Example summary',
12508 version => '0.0.1',
12509 );
12510  
12511 $cli->argument('input', {
12512 name => 'INPUT',
12513 type => 'string',
12514 });
12515  
12516 $cli->argument('output', {
12517 name => 'OUTPUT',
12518 type => 'string',
12519 });
12520  
12521 my $usage = $cli->usage;
12522  
12523 # mycli version 0.0.1 - Example summary
12524 #
12525 # Usage: mycli [<INPUT>] [<OUTPUT>]
12526 #
12527 # Arguments:
12528 # [<INPUT>]
12529 # Expects a string value
12530 # (optional)
12531 # [<OUTPUT>]
12532 # Expects a string value
12533 # (optional)
12534  
12535 =back
12536  
12537 =over 4
12538  
12539 =item usage example 7
12540  
12541 package main;
12542  
12543 use Venus::Cli;
12544  
12545 my $cli = Venus::Cli->new(
12546 name => 'mycli',
12547 summary => 'Example summary',
12548 version => '0.0.1',
12549 );
12550  
12551 $cli->argument('input', {
12552 name => 'input',
12553 label => 'Input.',
12554 type => 'string',
12555 });
12556  
12557 $cli->argument('output', {
12558 name => 'output',
12559 label => 'Output.',
12560 type => 'string',
12561 });
12562  
12563 my $usage = $cli->usage;
12564  
12565 # mycli version 0.0.1 - Example summary
12566 #
12567 # Usage: mycli [<input>] [<output>]
12568 #
12569 # Arguments:
12570 # Input.
12571 # Expects a string value
12572 # (optional)
12573 # Output.
12574 # Expects a string value
12575 # (optional)
12576  
12577 =back
12578  
12579 =over 4
12580  
12581 =item usage example 8
12582  
12583 package main;
12584  
12585 use Venus::Cli;
12586  
12587 my $cli = Venus::Cli->new(
12588 name => 'mycli',
12589 summary => 'Example summary',
12590 version => '0.0.1',
12591 );
12592  
12593 $cli->argument('input', {
12594 name => 'input',
12595 help => 'Provide the input device to use',
12596 type => 'string',
12597 });
12598  
12599 $cli->argument('output', {
12600 name => 'output',
12601 help => 'Provide the output device to use',
12602 type => 'string',
12603 });
12604  
12605 my $usage = $cli->usage;
12606  
12607 # mycli version 0.0.1 - Example summary
12608 #
12609 # Usage: mycli [<input>] [<output>]
12610 #
12611 # Arguments:
12612 # [<input>]
12613 # Provide the input device to use
12614 # (optional)
12615 # [<output>]
12616 # Provide the output device to use
12617 # (optional)
12618  
12619 =back
12620  
12621 =over 4
12622  
12623 =item usage example 9
12624  
12625 package main;
12626  
12627 use Venus::Cli;
12628  
12629 my $cli = Venus::Cli->new(
12630 name => 'mycli',
12631 summary => 'Example summary',
12632 version => '0.0.1',
12633 );
12634  
12635 $cli->argument('input', {
12636 name => 'input',
12637 help => 'Provide the input device to use',
12638 type => 'string',
12639 });
12640  
12641 $cli->argument('output', {
12642 name => 'output',
12643 help => 'Provide the output device to use',
12644 multiples => true,
12645 type => 'string',
12646 });
12647  
12648 my $usage = $cli->usage;
12649  
12650 # mycli version 0.0.1 - Example summary
12651 #
12652 # Usage: mycli [<input>] [<output> ...]
12653 #
12654 # Arguments:
12655 # [<input>]
12656 # Provide the input device to use
12657 # (optional)
12658 # [<output> ...]
12659 # Provide the output device to use
12660 # (optional)
12661  
12662 =back
12663  
12664 =over 4
12665  
12666 =item usage example 10
12667  
12668 package main;
12669  
12670 use Venus::Cli;
12671  
12672 my $cli = Venus::Cli->new(
12673 name => 'mycli',
12674 );
12675  
12676 $cli->option('input', {
12677 type => 'string',
12678 });
12679  
12680 $cli->option('output', {
12681 type => 'string',
12682 });
12683  
12684 $cli->argument('lines', {
12685 multiples => true,
12686 range => '0:',
12687 type => 'string',
12688 });
12689  
12690 my $usage = $cli->usage;
12691  
12692 # Usage: mycli [<lines> ...] [--input] [--output]
12693 #
12694 # Arguments:
12695 # [<lines> ...]
12696 # Expects a string value
12697 # (optional)
12698 #
12699 # Options:
12700 # [--input=<string>]
12701 # Expects a string value
12702 # (optional)
12703 # [--output=<string>]
12704 # Expects a string value
12705 # (optional)
12706  
12707 =back
12708  
12709 =over 4
12710  
12711 =item usage example 11
12712  
12713 package main;
12714  
12715 use Venus::Cli;
12716  
12717 my $cli = Venus::Cli->new(
12718 name => 'mycli',
12719 );
12720  
12721 $cli->option('input', {
12722 type => 'string',
12723 });
12724  
12725 $cli->option('output', {
12726 type => 'string',
12727 });
12728  
12729 $cli->option('verbose', {
12730 type => 'boolean',
12731 });
12732  
12733 $cli->option('help', {
12734 alias => 'h',
12735 type => 'boolean',
12736 });
12737  
12738 $cli->argument('lines', {
12739 multiples => true,
12740 range => '0:',
12741 type => 'string',
12742 });
12743  
12744 my $usage = $cli->usage;
12745  
12746 # Usage: mycli [<lines> ...] [--input] [--output] [--verbose] [--help]
12747 #
12748 # Arguments:
12749 # [<lines> ...]
12750 # Expects a string value
12751 # (optional)
12752 #
12753 # Options:
12754 # [--input=<string>]
12755 # Expects a string value
12756 # (optional)
12757 # [--output=<string>]
12758 # Expects a string value
12759 # (optional)
12760 # [--verbose]
12761 # Expects a boolean value
12762 # (optional)
12763 # [-h, --help]
12764 # Expects a boolean value
12765 # (optional)
12766  
12767 =back
12768  
12769 =over 4
12770  
12771 =item usage example 12
12772  
12773 package main;
12774  
12775 use Venus::Cli;
12776  
12777 my $cli = Venus::Cli->new(
12778 name => 'mycli',
12779 );
12780  
12781 $cli->option('input', {
12782 multiples => true,
12783 type => 'string',
12784 });
12785  
12786 $cli->option('output', {
12787 multiples => true,
12788 type => 'string',
12789 });
12790  
12791 $cli->option('verbose', {
12792 type => 'boolean',
12793 });
12794  
12795 $cli->option('help', {
12796 alias => 'h',
12797 type => 'boolean',
12798 });
12799  
12800 $cli->argument('lines', {
12801 multiples => true,
12802 range => '0:',
12803 type => 'string',
12804 });
12805  
12806 my $usage = $cli->usage;
12807  
12808 # Usage: mycli [<lines> ...] [--input ...] [--output ...] [--verbose] [--help]
12809 #
12810 # Arguments:
12811 # [<lines> ...]
12812 # Expects a string value
12813 # (optional)
12814 #
12815 # Options:
12816 # [--input=<string> ...]
12817 # Expects a string value
12818 # (optional)
12819 # [--output=<string> ...]
12820 # Expects a string value
12821 # (optional)
12822 # [--verbose]
12823 # Expects a boolean value
12824 # (optional)
12825 # [-h, --help]
12826 # Expects a boolean value
12827 # (optional)
12828  
12829 =back
12830  
12831 =over 4
12832  
12833 =item usage example 13
12834  
12835 package main;
12836  
12837 use Venus::Cli;
12838  
12839 my $cli = Venus::Cli->new(
12840 name => 'mycli',
12841 );
12842  
12843 $cli->option('input', {
12844 alias => 'i',
12845 multiples => true,
12846 required => true,
12847 type => 'string',
12848 wants => 'input',
12849 });
12850  
12851 $cli->option('output', {
12852 alias => 'o',
12853 multiples => true,
12854 type => 'string',
12855 wants => 'output',
12856 });
12857  
12858 $cli->option('verbose', {
12859 aliases => ['v'],
12860 type => 'boolean',
12861 });
12862  
12863 $cli->option('help', {
12864 aliases => ['h'],
12865 type => 'boolean',
12866 });
12867  
12868 $cli->argument('lines', {
12869 multiples => true,
12870 range => '0:',
12871 type => 'string',
12872 });
12873  
12874 my $usage = $cli->usage;
12875  
12876 # Usage: mycli [<lines> ...] --input ... [--output ...] [--verbose] [--help]
12877 #
12878 # Arguments:
12879 # [<lines> ...]
12880 # Expects a string value
12881 # (optional)
12882 #
12883 # Options:
12884 # -i, --input=<input> ...
12885 # Expects a string value
12886 # (required)
12887 # [-o, --output=<output> ...]
12888 # Expects a string value
12889 # (optional)
12890 # [-v, --verbose]
12891 # Expects a boolean value
12892 # (optional)
12893 # [-h, --help]
12894 # Expects a boolean value
12895 # (optional)
12896  
12897 =back
12898  
12899 =over 4
12900  
12901 =item usage example 14
12902  
12903 package main;
12904  
12905 use Venus::Cli;
12906  
12907 my $cli = Venus::Cli->new(
12908 name => 'mycli',
12909 );
12910  
12911 $cli->option('input', {
12912 alias => 'i',
12913 multiples => true,
12914 required => true,
12915 type => 'string',
12916 wants => 'input',
12917 });
12918  
12919 $cli->option('output', {
12920 alias => 'o',
12921 multiples => true,
12922 type => 'string',
12923 wants => 'output',
12924 });
12925  
12926 $cli->option('verbose', {
12927 aliases => ['v'],
12928 type => 'boolean',
12929 });
12930  
12931 $cli->option('help', {
12932 aliases => ['h'],
12933 type => 'boolean',
12934 });
12935  
12936 $cli->argument('lines', {
12937 multiples => true,
12938 range => '0:',
12939 type => 'string',
12940 });
12941  
12942 $cli->option('exit-code', {
12943 alias => 'ec',
12944 type => 'number',
12945 default => 0,
12946 });
12947  
12948 my $usage = $cli->usage;
12949  
12950 # Usage: mycli [<lines> ...] --input ... [--output ...] [--verbose] [--help]
12951 # [--exit-code]
12952 #
12953 # Arguments:
12954 # [<lines> ...]
12955 # Expects a string value
12956 # (optional)
12957 #
12958 # Options:
12959 # -i, --input=<input> ...
12960 # Expects a string value
12961 # (required)
12962 # [-o, --output=<output> ...]
12963 # Expects a string value
12964 # (optional)
12965 # [-v, --verbose]
12966 # Expects a boolean value
12967 # (optional)
12968 # [-h, --help]
12969 # Expects a boolean value
12970 # (optional)
12971 # [--ec, --exit-code=<number>]
12972 # Expects a number value
12973 # (optional)
12974 # Default: 0
12975  
12976 =back
12977  
12978 =over 4
12979  
12980 =item usage example 15
12981  
12982 package main;
12983  
12984 use Venus::Cli;
12985  
12986 my $cli = Venus::Cli->new(
12987 name => 'mycli',
12988 );
12989  
12990 $cli->argument('input', {
12991 type => 'string',
12992 default => 'stdin',
12993 });
12994  
12995 $cli->argument('output', {
12996 type => 'string',
12997 default => 'stdout',
12998 });
12999  
13000 $cli->option('verbose', {
13001 aliases => ['v'],
13002 type => 'boolean',
13003 });
13004  
13005 $cli->option('help', {
13006 aliases => ['h'],
13007 type => 'boolean',
13008 });
13009  
13010 $cli->option('exit-code', {
13011 alias => 'ec',
13012 type => 'number',
13013 default => 0,
13014 });
13015  
13016 $cli->choice('stdin', {
13017 argument => 'input',
13018 });
13019  
13020 $cli->choice('in-file', {
13021 argument => 'input',
13022 });
13023  
13024 $cli->choice('stdout', {
13025 argument => 'output',
13026 });
13027  
13028 $cli->choice('out-file', {
13029 argument => 'output',
13030 });
13031  
13032 my $usage = $cli->usage;
13033  
13034 # Usage: mycli [<input>] [<output>] [--verbose] [--help] [--exit-code]
13035 #
13036 # Arguments:
13037 # [<input>]
13038 # Expects a string value
13039 # (optional)
13040 # Default: stdin
13041 # [<output>]
13042 # Expects a string value
13043 # (optional)
13044 # Default: stdout
13045 #
13046 # Options:
13047 # [-v, --verbose]
13048 # Expects a boolean value
13049 # (optional)
13050 # [-h, --help]
13051 # Expects a boolean value
13052 # (optional)
13053 # [--ec, --exit-code=<number>]
13054 # Expects a number value
13055 # (optional)
13056 # Default: 0
13057 #
13058 # Choices for [<input>]:
13059 # stdin
13060 # Expects a string value
13061 # [<input>]
13062 # in-file
13063 # Expects a string value
13064 # [<input>]
13065 #
13066 # Choices for [<output>]:
13067 # stdout
13068 # Expects a string value
13069 # [<output>]
13070 # out-file
13071 # Expects a string value
13072 # [<output>]
13073  
13074 =back
13075  
13076 =over 4
13077  
13078 =item usage example 16
13079  
13080 package main;
13081  
13082 use Venus::Cli;
13083  
13084 my $cli = Venus::Cli->new(
13085 name => 'mycli',
13086 );
13087  
13088 $cli->argument('choice', {
13089 help => 'See "choices" below',
13090 type => 'string',
13091 default => 'open',
13092 });
13093  
13094 $cli->choice('open', {
13095 argument => 'choice',
13096 });
13097  
13098 $cli->choice('close', {
13099 argument => 'choice',
13100 });
13101  
13102 $cli->choice('read', {
13103 argument => 'choice',
13104 });
13105  
13106 $cli->choice('write', {
13107 argument => 'choice',
13108 });
13109  
13110 my $usage = $cli->usage;
13111  
13112 # Usage: mycli [<choice>]
13113 #
13114 # Arguments:
13115 # [<choice>]
13116 # See "choices" below
13117 # (optional)
13118 # Default: open
13119 #
13120 # Choices for [<choice>]:
13121 # open
13122 # Expects a string value
13123 # [<choice>]
13124 # close
13125 # Expects a string value
13126 # [<choice>]
13127 # read
13128 # Expects a string value
13129 # [<choice>]
13130 # write
13131 # Expects a string value
13132 # [<choice>]
13133  
13134 =back
13135  
13136 =over 4
13137  
13138 =item usage example 17
13139  
13140 package main;
13141  
13142 use Venus::Cli;
13143  
13144 my $cli = Venus::Cli->new(
13145 name => 'mycli',
13146 );
13147  
13148 $cli->argument('choice', {
13149 help => 'See "choices" below',
13150 type => 'string',
13151 required => true,
13152 });
13153  
13154 $cli->choice('open', {
13155 argument => 'choice',
13156 });
13157  
13158 $cli->choice('close', {
13159 argument => 'choice',
13160 });
13161  
13162 $cli->choice('read', {
13163 argument => 'choice',
13164 });
13165  
13166 $cli->choice('write', {
13167 argument => 'choice',
13168 });
13169  
13170 my $usage = $cli->usage;
13171  
13172 # Usage: mycli <choice>
13173 #
13174 # Arguments:
13175 # <choice>
13176 # See "choices" below
13177 # (required)
13178 #
13179 # Choices for <choice>:
13180 # open
13181 # Expects a string value
13182 # <choice>
13183 # close
13184 # Expects a string value
13185 # <choice>
13186 # read
13187 # Expects a string value
13188 # <choice>
13189 # write
13190 # Expects a string value
13191 # <choice>
13192  
13193 =back
13194  
13195 =cut
13196  
13197 =head2 usage_argument_default
13198  
13199 usage_argument_default(string $name) (string)
13200  
13201 The usage_argument_default method renders the C<default> configuration value
13202 for the named argument for use in the CLI L</usage> text.
13203  
13204 I<Since C<4.15>>
13205  
13206 =over 4
13207  
13208 =item usage_argument_default example 1
13209  
13210 package main;
13211  
13212 use Venus::Cli;
13213  
13214 my $cli = Venus::Cli->new(name => 'mycli');
13215  
13216 my $usage_argument_default = $cli->usage_argument_default;
13217  
13218 # ""
13219  
13220 =back
13221  
13222 =over 4
13223  
13224 =item usage_argument_default example 2
13225  
13226 package main;
13227  
13228 use Venus::Cli;
13229  
13230 my $cli = Venus::Cli->new(name => 'mycli');
13231  
13232 $cli->argument('input', {
13233 default => 'stdin',
13234 });
13235  
13236 my $usage_argument_default = $cli->usage_argument_default('input');
13237  
13238 # "Default: stdin"
13239  
13240 =back
13241  
13242 =over 4
13243  
13244 =item usage_argument_default example 3
13245  
13246 package main;
13247  
13248 use Venus::Cli;
13249  
13250 my $cli = Venus::Cli->new(name => 'mycli');
13251  
13252 $cli->argument('input', {
13253 default => ['stdin', 'file'],
13254 });
13255  
13256 my $usage_argument_default = $cli->usage_argument_default('input');
13257  
13258 # "Default: stdin, file"
13259  
13260 =back
13261  
13262 =cut
13263  
13264 =head2 usage_argument_help
13265  
13266 usage_argument_help(string $name) (string)
13267  
13268 The usage_argument_help method renders the C<help> configuration value for the
13269 named argument for use in the CLI L</usage> text.
13270  
13271 I<Since C<4.15>>
13272  
13273 =over 4
13274  
13275 =item usage_argument_help example 1
13276  
13277 package main;
13278  
13279 use Venus::Cli;
13280  
13281 my $cli = Venus::Cli->new(name => 'mycli');
13282  
13283 my $usage_argument_help = $cli->usage_argument_help;
13284  
13285 # ""
13286  
13287 =back
13288  
13289 =over 4
13290  
13291 =item usage_argument_help example 2
13292  
13293 package main;
13294  
13295 use Venus::Cli;
13296  
13297 my $cli = Venus::Cli->new(name => 'mycli');
13298  
13299 $cli->argument('input', {
13300 help => 'Provide input.',
13301 });
13302  
13303 my $usage_argument_help = $cli->usage_argument_help('input');
13304  
13305 # "Provide input."
13306  
13307 =back
13308  
13309 =cut
13310  
13311 =head2 usage_argument_label
13312  
13313 usage_argument_label(string $name) (string)
13314  
13315 The usage_argument_label method renders the C<label> configuration value for
13316 the named argument for use in the CLI L</usage> text.
13317  
13318 I<Since C<4.15>>
13319  
13320 =over 4
13321  
13322 =item usage_argument_label example 1
13323  
13324 package main;
13325  
13326 use Venus::Cli;
13327  
13328 my $cli = Venus::Cli->new(name => 'mycli');
13329  
13330 my $usage_argument_label = $cli->usage_argument_label;
13331  
13332 # ""
13333  
13334 =back
13335  
13336 =over 4
13337  
13338 =item usage_argument_label example 2
13339  
13340 package main;
13341  
13342 use Venus::Cli;
13343  
13344 my $cli = Venus::Cli->new(name => 'mycli');
13345  
13346 $cli->argument('input', {
13347 label => 'Input.',
13348 });
13349  
13350 my $usage_argument_label = $cli->usage_argument_label('input');
13351  
13352 # "Input."
13353  
13354 =back
13355  
13356 =cut
13357  
13358 =head2 usage_argument_required
13359  
13360 usage_argument_required(string $name) (string)
13361  
13362 The usage_argument_required method renders the C<required> configuration value
13363 for the named argument for use in the CLI L</usage> text.
13364  
13365 I<Since C<4.15>>
13366  
13367 =over 4
13368  
13369 =item usage_argument_required example 1
13370  
13371 package main;
13372  
13373 use Venus::Cli;
13374  
13375 my $cli = Venus::Cli->new(name => 'mycli');
13376  
13377 my $usage_argument_required = $cli->usage_argument_required;
13378  
13379 # "(optional)"
13380  
13381 =back
13382  
13383 =over 4
13384  
13385 =item usage_argument_required example 2
13386  
13387 package main;
13388  
13389 use Venus::Cli;
13390  
13391 my $cli = Venus::Cli->new(name => 'mycli');
13392  
13393 $cli->argument('input', {
13394 required => true,
13395 });
13396  
13397 my $usage_argument_required = $cli->usage_argument_required('input');
13398  
13399 # "(required)"
13400  
13401 =back
13402  
13403 =over 4
13404  
13405 =item usage_argument_required example 3
13406  
13407 package main;
13408  
13409 use Venus::Cli;
13410  
13411 my $cli = Venus::Cli->new(name => 'mycli');
13412  
13413 $cli->argument('input', {
13414 required => false,
13415 });
13416  
13417 my $usage_argument_required = $cli->usage_argument_required('input');
13418  
13419 # "(optional)"
13420  
13421 =back
13422  
13423 =cut
13424  
13425 =head2 usage_argument_token
13426  
13427 usage_argument_token(string $name) (string)
13428  
13429 The usage_argument_token method renders the C<token> configuration value for
13430 the named argument for use in the CLI L</usage> text.
13431  
13432 I<Since C<4.15>>
13433  
13434 =over 4
13435  
13436 =item usage_argument_token example 1
13437  
13438 package main;
13439  
13440 use Venus::Cli;
13441  
13442 my $cli = Venus::Cli->new(name => 'mycli');
13443  
13444 my $usage_argument_token = $cli->usage_argument_token;
13445  
13446 # ""
13447  
13448 =back
13449  
13450 =over 4
13451  
13452 =item usage_argument_token example 2
13453  
13454 package main;
13455  
13456 use Venus::Cli;
13457  
13458 my $cli = Venus::Cli->new(name => 'mycli');
13459  
13460 $cli->argument('input', {
13461 required => true,
13462 multiples => false,
13463 type => 'string',
13464 });
13465  
13466 my $usage_argument_token = $cli->usage_argument_token('input');
13467  
13468 # "<input>"
13469  
13470 =back
13471  
13472 =over 4
13473  
13474 =item usage_argument_token example 3
13475  
13476 package main;
13477  
13478 use Venus::Cli;
13479  
13480 my $cli = Venus::Cli->new(name => 'mycli');
13481  
13482 $cli->argument('input', {
13483 required => true,
13484 multiples => true,
13485 type => 'string',
13486 });
13487  
13488 my $usage_argument_token = $cli->usage_argument_token('input');
13489  
13490 # "<input> ..."
13491  
13492 =back
13493  
13494 =over 4
13495  
13496 =item usage_argument_token example 4
13497  
13498 package main;
13499  
13500 use Venus::Cli;
13501  
13502 my $cli = Venus::Cli->new(name => 'mycli');
13503  
13504 $cli->argument('input', {
13505 required => false,
13506 multiples => false,
13507 type => 'string',
13508 });
13509  
13510 my $usage_argument_token = $cli->usage_argument_token('input');
13511  
13512 # "[<input>]"
13513  
13514 =back
13515  
13516 =over 4
13517  
13518 =item usage_argument_token example 5
13519  
13520 package main;
13521  
13522 use Venus::Cli;
13523  
13524 my $cli = Venus::Cli->new(name => 'mycli');
13525  
13526 $cli->argument('input', {
13527 required => false,
13528 multiples => true,
13529 type => 'string',
13530 });
13531  
13532 my $usage_argument_token = $cli->usage_argument_token('input');
13533  
13534 # "[<input> ...]"
13535  
13536 =back
13537  
13538 =cut
13539  
13540 =head2 usage_arguments
13541  
13542 usage_arguments() (string)
13543  
13544 The usage_arguments method renders all registered arguments for use in the CLI
13545 L</usage> text.
13546  
13547 I<Since C<4.15>>
13548  
13549 =over 4
13550  
13551 =item usage_arguments example 1
13552  
13553 package main;
13554  
13555 use Venus::Cli;
13556  
13557 my $cli = Venus::Cli->new(name => 'mycli');
13558  
13559 $cli->argument('input', {
13560 type => 'string',
13561 });
13562  
13563 $cli->argument('output', {
13564 type => 'string',
13565 });
13566  
13567 my $usage_arguments = $cli->usage_arguments;
13568  
13569 # Arguments:
13570 # [<input>]
13571 # Expects a string value
13572 # (optional)
13573 # [<output>]
13574 # Expects a string value
13575 # (optional)
13576  
13577 =back
13578  
13579 =over 4
13580  
13581 =item usage_arguments example 2
13582  
13583 package main;
13584  
13585 use Venus::Cli;
13586  
13587 my $cli = Venus::Cli->new(name => 'mycli');
13588  
13589 $cli->argument('input', {
13590 required => true,
13591 type => 'string',
13592 });
13593  
13594 $cli->argument('output', {
13595 required => true,
13596 type => 'string',
13597 });
13598  
13599 my $usage_arguments = $cli->usage_arguments;
13600  
13601 # Arguments:
13602 # <input>
13603 # Expects a string value
13604 # (required)
13605 # <output>
13606 # Expects a string value
13607 # (required)
13608  
13609 =back
13610  
13611 =cut
13612  
13613 =head2 usage_choice_help
13614  
13615 usage_choice_help(string $name) (string)
13616  
13617 The usage_choice_help method renders the C<help> configuration value for the
13618 named choice for use in the CLI L</usage> text.
13619  
13620 I<Since C<4.15>>
13621  
13622 =over 4
13623  
13624 =item usage_choice_help example 1
13625  
13626 package main;
13627  
13628 use Venus::Cli;
13629  
13630 my $cli = Venus::Cli->new(name => 'mycli');
13631  
13632 my $usage_choice_help = $cli->usage_choice_help;
13633  
13634 # ""
13635  
13636 =back
13637  
13638 =over 4
13639  
13640 =item usage_choice_help example 2
13641  
13642 package main;
13643  
13644 use Venus::Cli;
13645  
13646 my $cli = Venus::Cli->new(name => 'mycli');
13647  
13648 $cli->argument('input', {
13649 help => 'Example help',
13650 });
13651  
13652 $cli->choice('stdin', {
13653 argument => 'input',
13654 });
13655  
13656 my $usage_choice_help = $cli->usage_choice_help('stdin');
13657  
13658 # "Expects a string value"
13659  
13660 =back
13661  
13662 =over 4
13663  
13664 =item usage_choice_help example 3
13665  
13666 package main;
13667  
13668 use Venus::Cli;
13669  
13670 my $cli = Venus::Cli->new(name => 'mycli');
13671  
13672 $cli->argument('input', {
13673 help => 'Example help',
13674 });
13675  
13676 $cli->choice('stdin', {
13677 argument => 'input',
13678 help => 'Example help',
13679 });
13680  
13681 my $usage_choice_help = $cli->usage_choice_help('stdin');
13682  
13683 # "Example help"
13684  
13685 =back
13686  
13687 =cut
13688  
13689 =head2 usage_choice_label
13690  
13691 usage_choice_label(string $name) (string)
13692  
13693 The usage_choice_label method renders the C<label> configuration value for the
13694 named choice for use in the CLI L</usage> text.
13695  
13696 I<Since C<4.15>>
13697  
13698 =over 4
13699  
13700 =item usage_choice_label example 1
13701  
13702 package main;
13703  
13704 use Venus::Cli;
13705  
13706 my $cli = Venus::Cli->new(name => 'mycli');
13707  
13708 my $usage_choice_label = $cli->usage_choice_label;
13709  
13710 # ""
13711  
13712 =back
13713  
13714 =over 4
13715  
13716 =item usage_choice_label example 2
13717  
13718 package main;
13719  
13720 use Venus::Cli;
13721  
13722 my $cli = Venus::Cli->new(name => 'mycli');
13723  
13724 $cli->argument('input', {
13725 label => 'Input.',
13726 type => 'string',
13727 });
13728  
13729 $cli->choice('stdin', {
13730 argument => 'input',
13731 });
13732  
13733 my $usage_choice_label = $cli->usage_choice_label('stdin');
13734  
13735 # "stdin"
13736  
13737 =back
13738  
13739 =over 4
13740  
13741 =item usage_choice_label example 3
13742  
13743 package main;
13744  
13745 use Venus::Cli;
13746  
13747 my $cli = Venus::Cli->new(name => 'mycli');
13748  
13749 $cli->argument('input', {
13750 label => 'Input.',
13751 type => 'string',
13752 });
13753  
13754 $cli->choice('stdin', {
13755 label => 'Stdin',
13756 argument => 'input',
13757 });
13758  
13759 my $usage_choice_label = $cli->usage_choice_label('stdin');
13760  
13761 # "Stdin"
13762  
13763 =back
13764  
13765 =cut
13766  
13767 =head2 usage_choice_required
13768  
13769 usage_choice_required(string $name) (string)
13770  
13771 The usage_choice_required method renders the C<required> configuration value
13772 for the named choice for use in the CLI L</usage> text.
13773  
13774 I<Since C<4.15>>
13775  
13776 =over 4
13777  
13778 =item usage_choice_required example 1
13779  
13780 package main;
13781  
13782 use Venus::Cli;
13783  
13784 my $cli = Venus::Cli->new(name => 'mycli');
13785  
13786 my $usage_choice_required = $cli->usage_choice_required;
13787  
13788 # ""
13789  
13790 =back
13791  
13792 =over 4
13793  
13794 =item usage_choice_required example 2
13795  
13796 package main;
13797  
13798 use Venus::Cli;
13799  
13800 my $cli = Venus::Cli->new(name => 'mycli');
13801  
13802 $cli->argument('input', {
13803 required => true,
13804 });
13805  
13806 $cli->choice('stdin', {
13807 argument => 'input',
13808 });
13809  
13810 my $usage_choice_required = $cli->usage_choice_required('stdin');
13811  
13812 # "<input>"
13813  
13814 =back
13815  
13816 =over 4
13817  
13818 =item usage_choice_required example 3
13819  
13820 package main;
13821  
13822 use Venus::Cli;
13823  
13824 my $cli = Venus::Cli->new(name => 'mycli');
13825  
13826 $cli->argument('input', {
13827 required => false,
13828 });
13829  
13830 $cli->choice('stdin', {
13831 argument => 'input',
13832 });
13833  
13834 my $usage_choice_required = $cli->usage_choice_required('stdin');
13835  
13836 # "[<input>]"
13837  
13838 =back
13839  
13840 =cut
13841  
13842 =head2 usage_choices
13843  
13844 usage_choices() (string)
13845  
13846 The usage_choices method renders all registered choices for use in the CLI
13847 L</usage> text.
13848  
13849 I<Since C<4.15>>
13850  
13851 =over 4
13852  
13853 =item usage_choices example 1
13854  
13855 package main;
13856  
13857 use Venus::Cli;
13858  
13859 my $cli = Venus::Cli->new(name => 'mycli');
13860  
13861 $cli->argument('input', {
13862 type => 'string',
13863 });
13864  
13865 $cli->choice('stdin', {
13866 argument => 'input',
13867 });
13868  
13869 $cli->argument('output', {
13870 type => 'string',
13871 });
13872  
13873 $cli->choice('stdout', {
13874 argument => 'output',
13875 });
13876  
13877 my $usage_choices = $cli->usage_choices;
13878  
13879 # Choices for [<input>]:
13880 # stdin
13881 # Expects a string value
13882 # [<input>]
13883 #
13884 # Choices for [<output>]:
13885 # stdout
13886 # Expects a string value
13887 # [<output>]
13888  
13889 =back
13890  
13891 =over 4
13892  
13893 =item usage_choices example 2
13894  
13895 package main;
13896  
13897 use Venus::Cli;
13898  
13899 my $cli = Venus::Cli->new(name => 'mycli');
13900  
13901 $cli->argument('input', {
13902 required => true,
13903 });
13904  
13905 $cli->choice('stdin', {
13906 argument => 'input',
13907 help => 'Use STDIN',
13908 });
13909  
13910 $cli->argument('output', {
13911 default => 'stdout',
13912 });
13913  
13914 $cli->choice('stdout', {
13915 argument => 'output',
13916 help => 'Use STDOUT',
13917 });
13918  
13919 my $usage_choices = $cli->usage_choices;
13920  
13921 # Choices for <input>:
13922 # stdin
13923 # Use STDIN
13924 # <input>
13925 #
13926 # Choices for [<output>]:
13927 # stdout
13928 # Use STDOUT
13929 # [<output>]
13930  
13931 =back
13932  
13933 =cut
13934  
13935 =head2 usage_description
13936  
13937 usage_description() (string)
13938  
13939 The usage_description method renders the description for use in the CLI
13940 L</usage> text.
13941  
13942 I<Since C<4.15>>
13943  
13944 =over 4
13945  
13946 =item usage_description example 1
13947  
13948 package main;
13949  
13950 use Venus::Cli;
13951  
13952 my $cli = Venus::Cli->new(name => 'mycli');
13953  
13954 my $description = $cli->description('Example description');
13955  
13956 my $usage_description = $cli->usage_description;
13957  
13958 # "Example description"
13959  
13960 =back
13961  
13962 =cut
13963  
13964 =head2 usage_footer
13965  
13966 usage_footer() (string)
13967  
13968 The usage_footer method renders the footer for use in the CLI L</usage> text.
13969  
13970 I<Since C<4.15>>
13971  
13972 =over 4
13973  
13974 =item usage_footer example 1
13975  
13976 package main;
13977  
13978 use Venus::Cli;
13979  
13980 my $cli = Venus::Cli->new(name => 'mycli');
13981  
13982 my $footer = $cli->footer('Example footer');
13983  
13984 my $usage_footer = $cli->usage_footer;
13985  
13986 # "Example footer"
13987  
13988 =back
13989  
13990 =cut
13991  
13992 =head2 usage_gist
13993  
13994 usage_gist() (string)
13995  
13996 The usage_gist method renders the CLI top-line describing the name, version,
13997 and/or summary.
13998  
13999 I<Since C<4.15>>
14000  
14001 =over 4
14002  
14003 =item usage_gist example 1
14004  
14005 package main;
14006  
14007 use Venus::Cli;
14008  
14009 my $cli = Venus::Cli->new(name => 'mycli');
14010  
14011 my $usage_gist = $cli->usage_gist;
14012  
14013 # ""
14014  
14015 =back
14016  
14017 =over 4
14018  
14019 =item usage_gist example 2
14020  
14021 package main;
14022  
14023 use Venus::Cli;
14024  
14025 my $cli = Venus::Cli->new(name => 'mycli');
14026  
14027 $cli->version('0.0.1');
14028  
14029 my $usage_gist = $cli->usage_gist;
14030  
14031 # "mycli version 0.0.1"
14032  
14033 =back
14034  
14035 =over 4
14036  
14037 =item usage_gist example 3
14038  
14039 package main;
14040  
14041 use Venus::Cli;
14042  
14043 my $cli = Venus::Cli->new(name => 'mycli');
14044  
14045 $cli->summary('Example summary');
14046  
14047 my $usage_gist = $cli->usage_gist;
14048  
14049 # "mycli - Example summary"
14050  
14051 =back
14052  
14053 =over 4
14054  
14055 =item usage_gist example 4
14056  
14057 package main;
14058  
14059 use Venus::Cli;
14060  
14061 my $cli = Venus::Cli->new(name => 'mycli');
14062  
14063 $cli->version('0.0.1');
14064  
14065 $cli->summary('Example summary');
14066  
14067 my $usage_gist = $cli->usage_gist;
14068  
14069 # "mycli version 0.0.1 - Example summary"
14070  
14071 =back
14072  
14073 =cut
14074  
14075 =head2 usage_header
14076  
14077 usage_header() (string)
14078  
14079 The usage_header method renders the header for use in the CLI L</usage> text.
14080  
14081 I<Since C<4.15>>
14082  
14083 =over 4
14084  
14085 =item usage_header example 1
14086  
14087 package main;
14088  
14089 use Venus::Cli;
14090  
14091 my $cli = Venus::Cli->new(name => 'mycli');
14092  
14093 my $header = $cli->header('Example header');
14094  
14095 my $usage_header = $cli->usage_header;
14096  
14097 # "Example header"
14098  
14099 =back
14100  
14101 =cut
14102  
14103 =head2 usage_line
14104  
14105 usage_line() (string)
14106  
14107 The usage_line method renders the CLI usage line for use in the CLI L</usage>
14108 text.
14109  
14110 I<Since C<4.15>>
14111  
14112 =over 4
14113  
14114 =item usage_line example 1
14115  
14116 package main;
14117  
14118 use Venus::Cli;
14119  
14120 my $cli = Venus::Cli->new(name => 'mycli');
14121  
14122 my $usage_line = $cli->usage_line;
14123  
14124 # "Usage: mycli"
14125  
14126 =back
14127  
14128 =over 4
14129  
14130 =item usage_line example 2
14131  
14132 package main;
14133  
14134 use Venus::Cli;
14135  
14136 my $cli = Venus::Cli->new(name => 'mycli');
14137  
14138 $cli->argument('input', {
14139 type => 'string',
14140 });
14141  
14142 my $usage_line = $cli->usage_line;
14143  
14144 # "Usage: mycli [<input>]"
14145  
14146 =back
14147  
14148 =over 4
14149  
14150 =item usage_line example 3
14151  
14152 package main;
14153  
14154 use Venus::Cli;
14155  
14156 my $cli = Venus::Cli->new(name => 'mycli');
14157  
14158 $cli->argument('input', {
14159 type => 'string',
14160 });
14161  
14162 $cli->argument('output', {
14163 type => 'string',
14164 });
14165  
14166 my $usage_line = $cli->usage_line;
14167  
14168 # "Usage: mycli [<input>] [<output>]"
14169  
14170 =back
14171  
14172 =over 4
14173  
14174 =item usage_line example 4
14175  
14176 package main;
14177  
14178 use Venus::Cli;
14179  
14180 my $cli = Venus::Cli->new(name => 'mycli');
14181  
14182 $cli->argument('input', {
14183 required => true,
14184 type => 'string',
14185 });
14186  
14187 $cli->argument('output', {
14188 required => true,
14189 type => 'string',
14190 });
14191  
14192 my $usage_line = $cli->usage_line;
14193  
14194 # "Usage: mycli <input> <output>"
14195  
14196 =back
14197  
14198 =over 4
14199  
14200 =item usage_line example 5
14201  
14202 package main;
14203  
14204 use Venus::Cli;
14205  
14206 my $cli = Venus::Cli->new(name => 'mycli');
14207  
14208 $cli->argument('input', {
14209 required => true,
14210 type => 'string',
14211 });
14212  
14213 $cli->argument('output', {
14214 multiples => true,
14215 required => false,
14216 type => 'string',
14217 });
14218  
14219 my $usage_line = $cli->usage_line;
14220  
14221 # "Usage: mycli <input> [<output> ...]"
14222  
14223 =back
14224  
14225 =cut
14226  
14227 =head2 usage_name
14228  
14229 usage_name() (string)
14230  
14231 The usage_name method renders the CLI name for use in the CLI L</usage> text.
14232  
14233 I<Since C<4.15>>
14234  
14235 =over 4
14236  
14237 =item usage_name example 1
14238  
14239 package main;
14240  
14241 use Venus::Cli;
14242  
14243 my $cli = Venus::Cli->new;
14244  
14245 my $usage_name = $cli->usage_name;
14246  
14247 # ""
14248  
14249 =back
14250  
14251 =over 4
14252  
14253 =item usage_name example 2
14254  
14255 package main;
14256  
14257 use Venus::Cli;
14258  
14259 my $cli = Venus::Cli->new(name => 'mycli');
14260  
14261 my $usage_name = $cli->usage_name;
14262  
14263 # "mycli"
14264  
14265 =back
14266  
14267 =cut
14268  
14269 =head2 usage_option_default
14270  
14271 usage_option_default(string $name) (string)
14272  
14273 The usage_option_default method renders the C<default> configuration value for
14274 the named option for use in the CLI L</usage> text.
14275  
14276 I<Since C<4.15>>
14277  
14278 =over 4
14279  
14280 =item usage_option_default example 1
14281  
14282 package main;
14283  
14284 use Venus::Cli;
14285  
14286 my $cli = Venus::Cli->new(name => 'mycli');
14287  
14288 my $usage_option_default = $cli->usage_option_default;
14289  
14290 # ""
14291  
14292 =back
14293  
14294 =over 4
14295  
14296 =item usage_option_default example 2
14297  
14298 package main;
14299  
14300 use Venus::Cli;
14301  
14302 my $cli = Venus::Cli->new(name => 'mycli');
14303  
14304 $cli->option('input', {
14305 default => 'stdin',
14306 });
14307  
14308 my $usage_option_default = $cli->usage_option_default('input');
14309  
14310 # "Default: stdin"
14311  
14312 =back
14313  
14314 =over 4
14315  
14316 =item usage_option_default example 3
14317  
14318 package main;
14319  
14320 use Venus::Cli;
14321  
14322 my $cli = Venus::Cli->new(name => 'mycli');
14323  
14324 $cli->option('input', {
14325 default => ['stdin', 'file'],
14326 });
14327  
14328 my $usage_option_default = $cli->usage_option_default('input');
14329  
14330 # "Default: stdin, file"
14331  
14332 =back
14333  
14334 =cut
14335  
14336 =head2 usage_option_help
14337  
14338 usage_option_help(string $name) (string)
14339  
14340 The usage_option_help method renders the C<help> configuration value for the
14341 named option for use in the CLI L</usage> text.
14342  
14343 I<Since C<4.15>>
14344  
14345 =over 4
14346  
14347 =item usage_option_help example 1
14348  
14349 package main;
14350  
14351 use Venus::Cli;
14352  
14353 my $cli = Venus::Cli->new(name => 'mycli');
14354  
14355 my $usage_option_help = $cli->usage_option_help;
14356  
14357 # ""
14358  
14359 =back
14360  
14361 =over 4
14362  
14363 =item usage_option_help example 2
14364  
14365 package main;
14366  
14367 use Venus::Cli;
14368  
14369 my $cli = Venus::Cli->new(name => 'mycli');
14370  
14371 $cli->option('input', {
14372 help => 'Example help',
14373 });
14374  
14375 my $usage_option_help = $cli->usage_option_help('input');
14376  
14377 # "Example help"
14378  
14379 =back
14380  
14381 =cut
14382  
14383 =head2 usage_option_label
14384  
14385 usage_option_label(string $name) (string)
14386  
14387 The usage_option_label method renders the C<label> configuration value for the
14388 named option for use in the CLI L</usage> text.
14389  
14390 I<Since C<4.15>>
14391  
14392 =over 4
14393  
14394 =item usage_option_label example 1
14395  
14396 package main;
14397  
14398 use Venus::Cli;
14399  
14400 my $cli = Venus::Cli->new(name => 'mycli');
14401  
14402 my $usage_option_label = $cli->usage_option_label;
14403  
14404 # ""
14405  
14406 =back
14407  
14408 =over 4
14409  
14410 =item usage_option_label example 2
14411  
14412 package main;
14413  
14414 use Venus::Cli;
14415  
14416 my $cli = Venus::Cli->new(name => 'mycli');
14417  
14418 $cli->option('input', {
14419 required => true,
14420 });
14421  
14422 my $usage_option_label = $cli->usage_option_label('input');
14423  
14424 # "--input=<string>"
14425  
14426 =back
14427  
14428 =over 4
14429  
14430 =item usage_option_label example 3
14431  
14432 package main;
14433  
14434 use Venus::Cli;
14435  
14436 my $cli = Venus::Cli->new(name => 'mycli');
14437  
14438 $cli->option('input', {
14439 multiples => true,
14440 required => true,
14441 });
14442  
14443 my $usage_option_label = $cli->usage_option_label('input');
14444  
14445 # "--input=<string> ..."
14446  
14447 =back
14448  
14449 =over 4
14450  
14451 =item usage_option_label example 4
14452  
14453 package main;
14454  
14455 use Venus::Cli;
14456  
14457 my $cli = Venus::Cli->new(name => 'mycli');
14458  
14459 $cli->option('input', {
14460 multiples => true,
14461 required => true,
14462 type => 'number',
14463 });
14464  
14465 my $usage_option_label = $cli->usage_option_label('input');
14466  
14467 # "--input=<number> ..."
14468  
14469 =back
14470  
14471 =over 4
14472  
14473 =item usage_option_label example 5
14474  
14475 package main;
14476  
14477 use Venus::Cli;
14478  
14479 my $cli = Venus::Cli->new(name => 'mycli');
14480  
14481 $cli->option('input', {
14482 multiples => true,
14483 required => true,
14484 type => 'number',
14485 wants => 'input',
14486 });
14487  
14488 my $usage_option_label = $cli->usage_option_label('input');
14489  
14490 # "--input=<input> ..."
14491  
14492 =back
14493  
14494 =over 4
14495  
14496 =item usage_option_label example 6
14497  
14498 package main;
14499  
14500 use Venus::Cli;
14501  
14502 my $cli = Venus::Cli->new(name => 'mycli');
14503  
14504 $cli->option('input', {
14505 required => false,
14506 });
14507  
14508 my $usage_option_label = $cli->usage_option_label('input');
14509  
14510 # "[--input=<string>]"
14511  
14512 =back
14513  
14514 =over 4
14515  
14516 =item usage_option_label example 7
14517  
14518 package main;
14519  
14520 use Venus::Cli;
14521  
14522 my $cli = Venus::Cli->new(name => 'mycli');
14523  
14524 $cli->option('input', {
14525 multiples => true,
14526 required => false,
14527 });
14528  
14529 my $usage_option_label = $cli->usage_option_label('input');
14530  
14531 # "[--input=<string> ...]"
14532  
14533 =back
14534  
14535 =over 4
14536  
14537 =item usage_option_label example 8
14538  
14539 package main;
14540  
14541 use Venus::Cli;
14542  
14543 my $cli = Venus::Cli->new(name => 'mycli');
14544  
14545 $cli->option('input', {
14546 multiples => true,
14547 required => false,
14548 type => 'number',
14549 });
14550  
14551 my $usage_option_label = $cli->usage_option_label('input');
14552  
14553 # "[--input=<number> ...]"
14554  
14555 =back
14556  
14557 =over 4
14558  
14559 =item usage_option_label example 9
14560  
14561 package main;
14562  
14563 use Venus::Cli;
14564  
14565 my $cli = Venus::Cli->new(name => 'mycli');
14566  
14567 $cli->option('input', {
14568 multiples => true,
14569 required => false,
14570 type => 'number',
14571 wants => 'input',
14572 });
14573  
14574 my $usage_option_label = $cli->usage_option_label('input');
14575  
14576 # "[--input=<input> ...]"
14577  
14578 =back
14579  
14580 =over 4
14581  
14582 =item usage_option_label example 10
14583  
14584 package main;
14585  
14586 use Venus::Cli;
14587  
14588 my $cli = Venus::Cli->new(name => 'mycli');
14589  
14590 $cli->option('input', {
14591 multiples => true,
14592 required => false,
14593 type => 'boolean',
14594 wants => undef,
14595 });
14596  
14597 my $usage_option_label = $cli->usage_option_label('input');
14598  
14599 # "[--input ...]"
14600  
14601 =back
14602  
14603 =cut
14604  
14605 =head2 usage_option_required
14606  
14607 usage_option_required(string $name) (string)
14608  
14609 The usage_option_required method renders the C<required> configuration value
14610 for the named option for use in the CLI L</usage> text.
14611  
14612 I<Since C<4.15>>
14613  
14614 =over 4
14615  
14616 =item usage_option_required example 1
14617  
14618 package main;
14619  
14620 use Venus::Cli;
14621  
14622 my $cli = Venus::Cli->new(name => 'mycli');
14623  
14624 my $usage_option_required = $cli->usage_option_required;
14625  
14626 # "(optional)"
14627  
14628 =back
14629  
14630 =over 4
14631  
14632 =item usage_option_required example 2
14633  
14634 package main;
14635  
14636 use Venus::Cli;
14637  
14638 my $cli = Venus::Cli->new(name => 'mycli');
14639  
14640 $cli->option('input', {
14641 required => true,
14642 });
14643  
14644 my $usage_option_required = $cli->usage_option_required('input');
14645  
14646 # "(required)"
14647  
14648 =back
14649  
14650 =over 4
14651  
14652 =item usage_option_required example 3
14653  
14654 package main;
14655  
14656 use Venus::Cli;
14657  
14658 my $cli = Venus::Cli->new(name => 'mycli');
14659  
14660 $cli->option('input', {
14661 required => false,
14662 });
14663  
14664 my $usage_option_required = $cli->usage_option_required('input');
14665  
14666 # "(optional)"
14667  
14668 =back
14669  
14670 =cut
14671  
14672 =head2 usage_option_token
14673  
14674 usage_option_token(string $name) (string)
14675  
14676 The usage_option_token method renders the C<token> configuration value for the
14677 named option for use in the CLI L</usage> text.
14678  
14679 I<Since C<4.15>>
14680  
14681 =over 4
14682  
14683 =item usage_option_token example 1
14684  
14685 package main;
14686  
14687 use Venus::Cli;
14688  
14689 my $cli = Venus::Cli->new(name => 'mycli');
14690  
14691 my $usage_option_token = $cli->usage_option_token;
14692  
14693 # ""
14694  
14695 =back
14696  
14697 =over 4
14698  
14699 =item usage_option_token example 2
14700  
14701 package main;
14702  
14703 use Venus::Cli;
14704  
14705 my $cli = Venus::Cli->new(name => 'mycli');
14706  
14707 $cli->option('input', {
14708 required => true,
14709 });
14710  
14711 my $usage_option_token = $cli->usage_option_token('input');
14712  
14713 # "--input"
14714  
14715 =back
14716  
14717 =over 4
14718  
14719 =item usage_option_token example 3
14720  
14721 package main;
14722  
14723 use Venus::Cli;
14724  
14725 my $cli = Venus::Cli->new(name => 'mycli');
14726  
14727 $cli->option('input', {
14728 multiples => true,
14729 required => true,
14730 });
14731  
14732 my $usage_option_token = $cli->usage_option_token('input');
14733  
14734 # "--input ..."
14735  
14736 =back
14737  
14738 =over 4
14739  
14740 =item usage_option_token example 4
14741  
14742 package main;
14743  
14744 use Venus::Cli;
14745  
14746 my $cli = Venus::Cli->new(name => 'mycli');
14747  
14748 $cli->option('input', {
14749 required => false,
14750 });
14751  
14752 my $usage_option_token = $cli->usage_option_token('input');
14753  
14754 # "[--input]"
14755  
14756 =back
14757  
14758 =over 4
14759  
14760 =item usage_option_token example 5
14761  
14762 package main;
14763  
14764 use Venus::Cli;
14765  
14766 my $cli = Venus::Cli->new(name => 'mycli');
14767  
14768 $cli->option('input', {
14769 multiples => true,
14770 required => false,
14771 });
14772  
14773 my $usage_option_token = $cli->usage_option_token('input');
14774  
14775 # "[--input ...]"
14776  
14777 =back
14778  
14779 =cut
14780  
14781 =head2 usage_options
14782  
14783 usage_options() (string)
14784  
14785 The usage_options method renders all registered options for use in the CLI
14786 L</usage> text.
14787  
14788 I<Since C<4.15>>
14789  
14790 =over 4
14791  
14792 =item usage_options example 1
14793  
14794 package main;
14795  
14796 use Venus::Cli;
14797  
14798 my $cli = Venus::Cli->new(name => 'mycli');
14799  
14800 $cli->option('input', {
14801 type => 'string',
14802 });
14803  
14804 $cli->option('output', {
14805 type => 'string',
14806 });
14807  
14808 my $usage_options = $cli->usage_options;
14809  
14810 # Options:
14811 # [--input=<string>]
14812 # Expects a string value
14813 # (optional)
14814 # [--output=<string>]
14815 # Expects a string value
14816 # (optional)
14817  
14818 =back
14819  
14820 =over 4
14821  
14822 =item usage_options example 2
14823  
14824 package main;
14825  
14826 use Venus::Cli;
14827  
14828 my $cli = Venus::Cli->new(name => 'mycli');
14829  
14830 $cli->option('input', {
14831 required => true,
14832 type => 'string',
14833 });
14834  
14835 $cli->option('output', {
14836 required => true,
14837 type => 'string',
14838 });
14839  
14840 my $usage_options = $cli->usage_options;
14841  
14842 # Options:
14843 # --input=<string>
14844 # Expects a string value
14845 # (required)
14846 # --output=<string>
14847 # Expects a string value
14848 # (required)
14849  
14850 =back
14851  
14852 =cut
14853  
14854 =head2 usage_summary
14855  
14856 usage_summary() (string)
14857  
14858 The usage_summary method renders the summary for use in the CLI L</usage> text.
14859  
14860 I<Since C<4.15>>
14861  
14862 =over 4
14863  
14864 =item usage_summary example 1
14865  
14866 package main;
14867  
14868 use Venus::Cli;
14869  
14870 my $cli = Venus::Cli->new(name => 'mycli');
14871  
14872 my $summary = $cli->summary('Example summary');
14873  
14874 my $usage_summary = $cli->usage_summary;
14875  
14876 # "Example summary"
14877  
14878 =back
14879  
14880 =cut
14881  
14882 =head2 usage_version
14883  
14884 usage_version() (string)
14885  
14886 The usage_version method renders the description for use in the CLI L</usage>
14887 text.
14888  
14889 I<Since C<4.15>>
14890  
14891 =over 4
14892  
14893 =item usage_version example 1
14894  
14895 package main;
14896  
14897 use Venus::Cli;
14898  
14899 my $cli = Venus::Cli->new(name => 'mycli');
14900  
14901 my $version = $cli->version('0.0.1');
14902  
14903 my $usage_version = $cli->usage_version;
14904  
14905 # "0.0.1"
14906  
14907 =back
14908  
14909 =cut
14910  
14911 =head2 vars
14912  
14913 vars() (Venus::Vars)
14914  
14915 The vars method returns the list of parsed command-line options as a
14916 L<Venus::Vars> object.
14917  
14918 I<Since C<4.15>>
14919  
14920 =over 4
14921  
14922 =item vars example 1
14923  
14924 # given: synopsis
14925  
14926 package main;
14927  
14928 my $vars = $cli->vars;
14929  
14930 # bless(..., "Venus::Vars")
14931  
14932 =back
14933  
14934 =cut
14935  
14936 =head2 yesno
14937  
14938 yesno(string $method, any @args) (any)
14939  
14940 The yesno method is a configuration dispatcher and shorthand for C<{'type',
14941 'yesno'}>. It returns the data or dispatches to the next configuration
14942 dispatcher based on the name provided and merges the configurations produced.
14943  
14944 I<Since C<4.15>>
14945  
14946 =over 4
14947  
14948 =item yesno example 1
14949  
14950 # given: synopsis
14951  
14952 package main;
14953  
14954 my $yesno = $cli->yesno;
14955  
14956 # {type => 'yesno'}
14957  
14958 =back
14959  
14960 =over 4
14961  
14962 =item yesno example 2
14963  
14964 # given: synopsis
14965  
14966 package main;
14967  
14968 my $yesno = $cli->yesno(undef, {required => true});
14969  
14970 # {type => 'yesno', required => true}
14971  
14972 =back
14973  
14974 =over 4
14975  
14976 =item yesno example 3
14977  
14978 # given: synopsis
14979  
14980 package main;
14981  
14982 my $yesno = $cli->yesno('option', 'example');
14983  
14984 # {
14985 # name => 'example',
14986 # label => undef,
14987 # help => 'Expects a yesno value',
14988 # default => undef,
14989 # aliases => [],
14990 # multiples => 0,
14991 # prompt => undef,
14992 # range => undef,
14993 # required => 1,
14994 # type => 'yesno',
14995 # index => 0,
14996 # wants => 'yesno',
14997 # }
14998  
14999 =back
15000  
15001 =cut
15002  
15003 =head1 AUTHORS
15004  
15005 Awncorp, C<awncorp@cpan.org>
15006  
15007 =cut
15008  
15009 =head1 LICENSE
15010  
15011 Copyright (C) 2022, Awncorp, C<awncorp@cpan.org>.
15012  
15013 This program is free software, you can redistribute it and/or modify it under
15014 the terms of the Apache license version 2.0.
15015  
15016 =cut
« blib/lib/Venus/Schema.pm ↑ Summary blib/lib/Venus/Collect.pm »