| 1 | package App::Commando::Presenter; | ||||||||||
| 2 | |||||||||||
| 3 | 8 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 8 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 8 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 8 | ▶ | use Scalar::Util qw(refaddr); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 8 | has 'command' => ( is => 'rw' ); | |||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | sub BUILDARGS { | ||||||||
|
Subroutine
BUILDARGS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 12 | 3 | my ($class, $command) = @_; | |||||||||
| 13 | |||||||||||
| 14 | return { | ||||||||||
| 15 | 3 | command => $command, | |||||||||
| 16 | }; | ||||||||||
| 17 | } | ||||||||||
| 18 | |||||||||||
| 19 | 2 | ▶ | sub usage_presentation { | ||||||||
|
Subroutine
usage_presentation: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 20 | 2 | my ($self) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 2 | return ' ' . $self->command->syntax; | |||||||||
| 23 | } | ||||||||||
| 24 | |||||||||||
| 25 | 3 | ▶ | sub options_presentation { | ||||||||
|
Subroutine
options_presentation: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 26 | 3 | my ($self) = @_; | |||||||||
| 27 | |||||||||||
| 28 | 3 | ▶ | return if !@{$self->command->options}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | |||||||||||
| 30 | 2 | return join "\n", map { $_->as_string } @{$self->command->options}; | |||||||||
| 31 | } | ||||||||||
| 32 | |||||||||||
| 33 | 3 | ▶ | sub subcommands_presentation { | ||||||||
|
Subroutine
subcommands_presentation: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 34 | 3 | my ($self) = @_; | |||||||||
| 35 | |||||||||||
| 36 | 3 | ▶ | return if !%{$self->command->commands}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 37 | |||||||||||
| 38 | 2 | return join "\n", map { $_->summarize } | |||||||||
| 39 | # Remove duplicate commands | ||||||||||
| 40 | 2 | values %{{ | |||||||||
| 41 | 2 | map { refaddr($_) => $_ } values %{$self->command->commands} | |||||||||
| 42 | }}; | ||||||||||
| 43 | } | ||||||||||
| 44 | |||||||||||
| 45 | 2 | ▶ | sub command_header { | ||||||||
|
Subroutine
command_header: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 46 | 2 | my ($self) = @_; | |||||||||
| 47 | |||||||||||
| 48 | 2 | my $header = $self->command->identity; | |||||||||
| 49 | 2 | ▶ | $header .= " -- " . $self->command->description | ||||||||
|
Branch: 1 branch
| |||||||||||
| 50 | if $self->command->description; | ||||||||||
| 51 | |||||||||||
| 52 | 2 | return $header; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 2 | ▶ | sub command_presentation { | ||||||||
|
Subroutine
command_presentation: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||
| 56 | 2 | my ($self) = @_; | |||||||||
| 57 | |||||||||||
| 58 | 2 | my @msg = (); | |||||||||
| 59 | |||||||||||
| 60 | 2 | push @msg, | |||||||||
| 61 | $self->command_header, | ||||||||||
| 62 | 'Usage:', | ||||||||||
| 63 | $self->usage_presentation; | ||||||||||
| 64 | |||||||||||
| 65 | 2 | ▶ | if (my $options = $self->options_presentation) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 66 | 1 | push @msg, "Options:\n" . $options; | |||||||||
| 67 | } | ||||||||||
| 68 | |||||||||||
| 69 | 2 | ▶ | if (my $subcommands = $self->subcommands_presentation) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 70 | 1 | push @msg, "Subcommands:\n" . $subcommands; | |||||||||
| 71 | } | ||||||||||
| 72 | |||||||||||
| 73 | 2 | return join "\n\n", @msg; | |||||||||
| 74 | } | ||||||||||
| 75 | |||||||||||
| 76 | 8 | 1; | |||||||||
| 77 | |||||||||||
| 78 | __END__ | ||||||||||