| line | stmt | bran | cond | sub | pod | time | code | 
| 1 | 9 |  |  | 9 |  | 5852 | use strict; | 
|  | 9 |  |  |  |  | 22 |  | 
|  | 9 |  |  |  |  | 316 |  | 
| 2 | 9 |  |  | 9 |  | 45 | use warnings; | 
|  | 9 |  |  |  |  | 19 |  | 
|  | 9 |  |  |  |  | 351 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 |  |  |  |  |  |  | package App::Cmd::Command::commands 0.336; | 
| 5 |  |  |  |  |  |  |  | 
| 6 | 9 |  |  | 9 |  | 54 | use App::Cmd::Command; | 
|  | 9 |  |  |  |  | 18 |  | 
|  | 9 |  |  |  |  | 404 |  | 
| 7 | 9 |  |  | 9 |  | 4853 | BEGIN { our @ISA = 'App::Cmd::Command' }; | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | # ABSTRACT: list the application's commands | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | #pod =head1 DESCRIPTION | 
| 12 |  |  |  |  |  |  | #pod | 
| 13 |  |  |  |  |  |  | #pod This command will list all of the application commands available and their | 
| 14 |  |  |  |  |  |  | #pod abstracts. | 
| 15 |  |  |  |  |  |  | #pod | 
| 16 |  |  |  |  |  |  | #pod =method execute | 
| 17 |  |  |  |  |  |  | #pod | 
| 18 |  |  |  |  |  |  | #pod This is the command's primary method and raison d'etre.  It prints the | 
| 19 |  |  |  |  |  |  | #pod application's usage text (if any) followed by a sorted listing of the | 
| 20 |  |  |  |  |  |  | #pod application's commands and their abstracts. | 
| 21 |  |  |  |  |  |  | #pod | 
| 22 |  |  |  |  |  |  | #pod The commands are printed in sorted groups (created by C); each | 
| 23 |  |  |  |  |  |  | #pod group is set off by blank lines. | 
| 24 |  |  |  |  |  |  | #pod | 
| 25 |  |  |  |  |  |  | #pod =cut | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | sub execute { | 
| 28 | 4 |  |  | 4 | 1 | 10 | my ($self, $opt, $args) = @_; | 
| 29 |  |  |  |  |  |  |  | 
| 30 | 4 | 100 |  |  |  | 12 | my $target = $opt->stderr ? *STDERR : *STDOUT; | 
| 31 |  |  |  |  |  |  |  | 
| 32 | 4 |  |  |  |  | 44 | my @cmd_groups = $self->app->command_groups; | 
| 33 | 4 | 0 |  |  |  | 9 | my @primary_commands = map { @$_ if ref $_ } @cmd_groups; | 
|  | 0 |  |  |  |  | 0 |  | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 4 | 50 |  |  |  | 23 | if (!@cmd_groups) { | 
| 36 |  |  |  |  |  |  | @primary_commands = | 
| 37 | 32 | 100 |  |  |  | 96 | grep { $_ ne 'version' or $self->app->{show_version} } | 
| 38 | 4 |  |  |  |  | 11 | map { ($_->command_names)[0] } | 
|  | 32 |  |  |  |  | 144 |  | 
| 39 |  |  |  |  |  |  | $self->app->command_plugins; | 
| 40 |  |  |  |  |  |  |  | 
| 41 | 4 |  |  |  |  | 16 | @cmd_groups = $self->sort_commands(@primary_commands); | 
| 42 |  |  |  |  |  |  | } | 
| 43 |  |  |  |  |  |  |  | 
| 44 | 4 |  |  |  |  | 8 | my $fmt_width = 0; | 
| 45 | 4 | 100 |  |  |  | 9 | for (@primary_commands) { $fmt_width = length if length > $fmt_width } | 
|  | 29 |  |  |  |  | 56 |  | 
| 46 | 4 |  |  |  |  | 29 | $fmt_width += 2; # pretty | 
| 47 |  |  |  |  |  |  |  | 
| 48 | 4 |  |  |  |  | 9 | foreach my $cmd_set (@cmd_groups) { | 
| 49 | 8 | 50 |  |  |  | 68 | if (!ref $cmd_set) { | 
| 50 | 0 |  |  |  |  | 0 | print { $target } "$cmd_set:\n"; | 
|  | 0 |  |  |  |  | 0 |  | 
| 51 | 0 |  |  |  |  | 0 | next; | 
| 52 |  |  |  |  |  |  | } | 
| 53 | 8 |  |  |  |  | 13 | for my $command (@$cmd_set) { | 
| 54 | 29 |  |  |  |  | 582 | my $abstract = $self->app->plugin_for($command)->abstract; | 
| 55 | 29 |  |  |  |  | 82 | printf { $target } "%${fmt_width}s: %s\n", $command, $abstract; | 
|  | 29 |  |  |  |  | 176 |  | 
| 56 |  |  |  |  |  |  | } | 
| 57 | 8 |  |  |  |  | 187 | print { $target } "\n"; | 
|  | 8 |  |  |  |  | 27 |  | 
| 58 |  |  |  |  |  |  | } | 
| 59 |  |  |  |  |  |  | } | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | #pod =method C | 
| 62 |  |  |  |  |  |  | #pod | 
| 63 |  |  |  |  |  |  | #pod   my @sorted = $cmd->sort_commands(@unsorted); | 
| 64 |  |  |  |  |  |  | #pod | 
| 65 |  |  |  |  |  |  | #pod This method orders the list of commands into groups which it returns as a list of | 
| 66 |  |  |  |  |  |  | #pod arrayrefs, and optional group header strings. | 
| 67 |  |  |  |  |  |  | #pod | 
| 68 |  |  |  |  |  |  | #pod By default, the first group is for the "help" and "commands" commands, and all | 
| 69 |  |  |  |  |  |  | #pod other commands are in the second group. | 
| 70 |  |  |  |  |  |  | #pod | 
| 71 |  |  |  |  |  |  | #pod This method can be overridden by implementing the C method in | 
| 72 |  |  |  |  |  |  | #pod your application base clase. | 
| 73 |  |  |  |  |  |  | #pod | 
| 74 |  |  |  |  |  |  | #pod =cut | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub sort_commands { | 
| 77 | 4 |  |  | 4 | 1 | 13 | my ($self, @commands) = @_; | 
| 78 |  |  |  |  |  |  |  | 
| 79 | 4 |  |  |  |  | 20 | my $float = qr/^(?:help|commands)$/; | 
| 80 |  |  |  |  |  |  |  | 
| 81 | 4 |  |  |  |  | 7 | my @head = sort grep { $_ =~ $float } @commands; | 
|  | 29 |  |  |  |  | 109 |  | 
| 82 | 4 |  |  |  |  | 11 | my @tail = sort grep { $_ !~ $float } @commands; | 
|  | 29 |  |  |  |  | 95 |  | 
| 83 |  |  |  |  |  |  |  | 
| 84 | 4 |  |  |  |  | 18 | return (\@head, \@tail); | 
| 85 |  |  |  |  |  |  | } | 
| 86 |  |  |  |  |  |  |  | 
| 87 |  |  |  |  |  |  | sub opt_spec { | 
| 88 |  |  |  |  |  |  | return ( | 
| 89 | 6 |  |  | 6 | 1 | 33 | [ 'stderr' => 'hidden' ], | 
| 90 |  |  |  |  |  |  | ); | 
| 91 |  |  |  |  |  |  | } | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | 1; | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | __END__ |