File Coverage

blib/lib/App/CLI/Command/Commands.pm
Criterion Covered Total %
statement 17 18 94.4
branch n/a
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 21 23 91.3


line stmt bran cond sub pod time code
1             package App::CLI::Command::Commands;
2              
3 1     1   936 use strict;
  1         3  
  1         41  
4 1     1   8 use warnings;
  1         3  
  1         47  
5              
6 1     1   9 use base qw/App::CLI::Command/;
  1         3  
  1         368  
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             sub run {
31 1     1 0 3 my ($self) = shift;
32              
33 1         4 my ($longest) = sort { length($b) cmp length($a) } $self->app->commands;
  0         0  
34 1         5 $longest = length $longest;
35              
36 1         5 foreach ( $self->app->commands ) {
37 1         6 my $cmd = $self->app->get_cmd($_);
38 1         7 my @components = split /::/, ref $cmd;
39 1         4 my $name = lc pop @components;
40 1         81 printf " %${longest}s\n", $name;
41             }
42             }
43              
44             1;