| 1 | package CLI::Framework::Command::Menu; | ||
| 2 | use base qw( CLI::Framework::Command::Meta ); | ||
| 3 | |||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | |||
| 7 | our $VERSION = 0.01; | ||
| 8 | |||
| 9 | #------- | ||
| 10 | |||
| 11 | sub usage_text { | ||
| 12 | q{ | ||
| 13 | menu: menu of available commands | ||
| 14 | } | ||
| 15 | } | ||
| 16 | |||
| 17 | sub run { | ||
| 18 | my ($self, $opts, @args) = @_; | ||
| 19 | |||
| 20 | return $self->menu_txt(); | ||
| 21 | } | ||
| 22 | |||
| 23 | sub menu_txt { | ||
| 24 | my ($self) = @_; | ||
| 25 | |||
| 26 | my $app = $self->get_app(); | ||
| 27 | |||
| 28 | # Build a numbered list of visible commands... | ||
| 29 | my @cmd = $app->get_interactive_commands(); | ||
| 30 | |||
| 31 | my $txt; | ||
| 32 | my %new_aliases = $app->command_alias(); | ||
| 33 | for my $i (0..$#cmd) { | ||
| 34 | my $alias = $i+1; | ||
| 35 | $txt .= $alias . ') ' . $cmd[$i] . "\n"; | ||
| 36 | $new_aliases{$alias} = $cmd[$i]; | ||
| 37 | } | ||
| 38 | # Add numerical aliases corresponding to menu options to the original | ||
| 39 | # command aliases defined by the application... | ||
| 40 | { | ||
| 41 | no strict 'refs'; no warnings; | ||
| 42 | *{ (ref $app).'::command_alias' } = sub { %new_aliases }; | ||
| 43 | return "\n".$txt; | ||
| 44 | } | ||
| 45 | } | ||
| 46 | |||
| 47 | sub line_count { | ||
| 48 | my ($self) = @_; | ||
| 49 | |||
| 50 | my $menu = $self->menu_txt(); | ||
| 51 | my $line_count = 0; | ||
| 52 | $line_count++ while $menu =~ /\n/g; | ||
| 53 | return $line_count; | ||
| 54 | } | ||
| 55 | |||
| 56 | #------- | ||
| 57 | 1; | ||
| 58 | |||
| 59 | __END__ |