| 1 | package App::CLI::Command::Commands; | ||
| 2 | |||
| 3 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 1 | ▶ | use base qw/App::CLI::Command/; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | =head1 NAME | ||
| 9 | |||
| 10 | App::CLI::Command::Commands - Print a list of commands for your app | ||
| 11 | |||
| 12 | =head1 SYNOPSIS | ||
| 13 | |||
| 14 | package MyApp; | ||
| 15 | use base qw(App::CLI App::CLI::Command); | ||
| 16 | |||
| 17 | # Make your app get a list of commands | ||
| 18 | use constant alias => ( | ||
| 19 | commands => '+App::CLI::Command::Commands', | ||
| 20 | ); | ||
| 21 | |||
| 22 | 1; | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | Print a list of commands registered for your application; | ||
| 27 | |||
| 28 | =cut | ||
| 29 | |||
| 30 | 1 | ▶ | sub run { |
|
Subroutine
run: called CC=2 SCAR=7.0
Pod
undocumented
| |||
| 31 | 1 | my ($self) = shift; | |
| 32 | |||
| 33 | 0 | my ($longest) = sort { length($b) cmp length($a) } $self->app->commands; | |
| 34 | 1 | $longest = length $longest; | |
| 35 | |||
| 36 | 1 | foreach ( $self->app->commands ) { | |
| 37 | 1 | my $cmd = $self->app->get_cmd($_); | |
| 38 | 1 | my @components = split /::/, ref $cmd; | |
| 39 | 1 | my $name = lc pop @components; | |
| 40 | 1 | printf " %${longest}s\n", $name; | |
| 41 | } | ||
| 42 | } | ||
| 43 | |||
| 44 | 1 | 1; | |