« blib/lib/Devel/Trepan/CmdProcessor/Command.pm
↑ Summary
blib/lib/Devel/Trepan/CmdProcessor/Command/Show_Subcmd/Highlight.pm »
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # Copyright (C) 2011-2012, 2013 Rocky Bernstein <rockbcpan.org> | ||
| 3 | |||
| 4 | use warnings; no warnings 'redefine'; no warnings 'once'; | ||
| 5 | use rlib '../../../../..'; | ||
| 6 | |||
| 7 | package Devel::Trepan::CmdProcessor::Command::Show::Aliases; | ||
| 8 | use Devel::Trepan::CmdProcessor::Command::Subcmd::Core; | ||
| 9 | |||
| 10 | @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd); | ||
| 11 | # Values inherited from parent | ||
| 12 | use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS; | ||
| 13 | |||
| 14 | =pod | ||
| 15 | |||
| 16 | =head2 Synopsis: | ||
| 17 | |||
| 18 | =cut | ||
| 19 | our $HELP = <<"EOH"; | ||
| 20 | =pod | ||
| 21 | |||
| 22 | B<show aliases> [I<alias> [I<alias> ...]] | ||
| 23 | |||
| 24 | If aliases names are given, show their definition. If left blank, show | ||
| 25 | all alias names. | ||
| 26 | |||
| 27 | =head2 See also: | ||
| 28 | |||
| 29 | L<C<alias>|Devel::Trepan::CmdProcessor::Command::Alias>, and | ||
| 30 | L<C<unalias>|Devel::Trepan::CmdProcessor::Command::Unalias>. | ||
| 31 | |||
| 32 | =cut | ||
| 33 | EOH | ||
| 34 | |||
| 35 | our $MIN_ABBREV = length('al'); | ||
| 36 | our $SHORT_HELP = "Show defined aliases"; | ||
| 37 | |||
| 38 | sub complete($$) | ||
| 39 | { | ||
| 40 | my ($self, $prefix) = @_; | ||
| 41 | my $proc = $self->{proc}; | ||
| 42 | my @candidates = keys %{$proc->{aliases}}; | ||
| 43 | my @matches = | ||
| 44 | Devel::Trepan::Complete::complete_token(\@candidates, $prefix); | ||
| 45 | sort @matches; | ||
| 46 | } | ||
| 47 | |||
| 48 | sub run($$) { | ||
| 49 | my ($self, $args) = @_; | ||
| 50 | my $proc = $self->{proc}; | ||
| 51 | my @args = @$args; | ||
| 52 | if (scalar(@args) > 2) { | ||
| 53 | shift @args; shift @args; | ||
| 54 | for my $alias_name (@args) { | ||
| 55 | if (exists $proc->{aliases}{$alias_name}) { | ||
| 56 | my $msg = sprintf "%s: %s", $alias_name, $proc->{aliases}{$alias_name}; | ||
| 57 | $proc->msg($msg); | ||
| 58 | } else { | ||
| 59 | $proc->msg("$alias_name is not a defined alias"); | ||
| 60 | } | ||
| 61 | } | ||
| 62 | } else { | ||
| 63 | my @aliases = keys %{$proc->{aliases}}; | ||
| 64 | if (scalar @aliases == 0) { | ||
| 65 | $proc->msg("No aliases defined."); | ||
| 66 | } else { | ||
| 67 | $proc->section("List of alias names currently defined:"); | ||
| 68 | my @cmds = sort @aliases; | ||
| 69 | $proc->msg($self->{cmd}->columnize_commands(\@cmds)); | ||
| 70 | } | ||
| 71 | } | ||
| 72 | } | ||
| 73 | |||
| 74 | unless(caller) { | ||
| 75 | # Demo it. | ||
| 76 | # require_relative '../../mock'; | ||
| 77 | # my $cmd = MockDebugger::sub_setup(__PACKAGE__); | ||
| 78 | # my $cmd->run($cmd->{prefix} + %w(u foo)); | ||
| 79 | } | ||
| 80 | |||
| 81 | 1; |