| 1 | # -*- coding: utf-8 -*- | ||||||||||||||||||||||
| 2 | # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org> | ||||||||||||||||||||||
| 3 | |||||||||||||||||||||||
| 4 | 12 | ▶ | use warnings; no warnings 'redefine'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 5 | 12 | ▶ | use rlib '../../../..'; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | |||||||||||||||||||||||
| 7 | package Devel::Trepan::CmdProcessor::Command::Alias; | ||||||||||||||||||||||
| 8 | 12 | ▶ | use if !@ISA, Devel::Trepan::CmdProcessor::Command ; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 9 | |||||||||||||||||||||||
| 10 | 1 | ▶ | unless (@ISA) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 11 | 0 | ▶ | eval <<"EOE"; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 12 | use constant CATEGORY => 'support'; | ||||||||||||||||||||||
| 13 | use constant SHORT_HELP => 'Add an alias for a debugger command'; | ||||||||||||||||||||||
| 14 | use constant MIN_ARGS => 0; # Need at least this many | ||||||||||||||||||||||
| 15 | use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited. | ||||||||||||||||||||||
| 16 | EOE | ||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||
| 18 | |||||||||||||||||||||||
| 19 | |||||||||||||||||||||||
| 20 | 12 | ▶ | use strict; use vars qw(@ISA); @ISA = @CMD_ISA; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 21 | 12 | ▶ | use vars @CMD_VARS; # Value inherited from parent | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | 1 | our $NAME = set_name(); | |||||||||||||||||||||
| 24 | =pod | ||||||||||||||||||||||
| 25 | |||||||||||||||||||||||
| 26 | =head2 Synopsis: | ||||||||||||||||||||||
| 27 | |||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||
| 29 | 1 | our $HELP = <<'HELP'; | |||||||||||||||||||||
| 30 | =pod | ||||||||||||||||||||||
| 31 | |||||||||||||||||||||||
| 32 | B<alias> I<alias> I<command> | ||||||||||||||||||||||
| 33 | |||||||||||||||||||||||
| 34 | Add alias I<alias> for a debugger command I<command>. | ||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | Add an alias when you want to use a command abbreviation for a command | ||||||||||||||||||||||
| 37 | that would otherwise be ambigous. For example, by default we make C<s> | ||||||||||||||||||||||
| 38 | be an alias of C<step> to force it to be used. Without the alias, C<s> | ||||||||||||||||||||||
| 39 | might be C<step>, C<show>, or C<set>, among others. | ||||||||||||||||||||||
| 40 | |||||||||||||||||||||||
| 41 | =head2 Examples: | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | alias cat list # "cat file.pl" is the same as "list file.pl" | ||||||||||||||||||||||
| 44 | alias s step # "s" is now an alias for "step". | ||||||||||||||||||||||
| 45 | # The above "s" alias is initially set up, by | ||||||||||||||||||||||
| 46 | # default. But you can change or remove it. | ||||||||||||||||||||||
| 47 | |||||||||||||||||||||||
| 48 | =head2 See also: | ||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | L<C<macro>|Devel::Trepan::CmdProcessor::Command::Macro> E<mdash> more complex definitions, | ||||||||||||||||||||||
| 51 | L<C<unalias>|Devel::Trepan::CmdProcessor::Command::Unalias>, and | ||||||||||||||||||||||
| 52 | L<C<show aliases>|Devel::Trepan::CmdProcessor::Command::Show::Aliases> | ||||||||||||||||||||||
| 53 | |||||||||||||||||||||||
| 54 | =cut | ||||||||||||||||||||||
| 55 | HELP | ||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | # Run command. | ||||||||||||||||||||||
| 58 | 0 | ▶ | sub run($$) { | ||||||||||||||||||||
|
Subroutine
run: not called CC=5 SCAR=28.9
Subroutine
run: not called CC=5 SCAR=28.9
Pod
undocumented
Pod
undocumented
| |||||||||||||||||||||||
| 59 | 0 | my ($self, $args) = @_; | |||||||||||||||||||||
| 60 | 0 | my $proc = $self->{proc}; | |||||||||||||||||||||
| 61 | 0 | ▶ | if (scalar @$args == 1) { | ||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||
| 62 | 0 | $proc->{commands}->{show}->run(['show', ${NAME}]); | |||||||||||||||||||||
| 63 | } elsif (scalar @$args == 2) { | ||||||||||||||||||||||
| 64 | 0 | $proc->{commands}->{show}->run(['show', ${NAME}, $args->[1]]); | |||||||||||||||||||||
| 65 | } else { | ||||||||||||||||||||||
| 66 | 0 | my ($junk, $al, $command, @rest) = @$args; | |||||||||||||||||||||
| 67 | 0 | my $old_command = $proc->{aliases}{$al}; | |||||||||||||||||||||
| 68 | 0 | ▶ | if (exists $proc->{commands}{$command}) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 69 | 0 | my $cmd_str = join(' ', ($command, @rest)); | |||||||||||||||||||||
| 70 | 0 | $proc->add_alias($command, $al, $cmd_str); | |||||||||||||||||||||
| 71 | 0 | ▶ | if ($old_command) { | ||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||
| 72 | 0 | $proc->remove_alias($old_command); | |||||||||||||||||||||
| 73 | 0 | $self->msg("Alias '${al}' for command string '${cmd_str}' replaced old " . | |||||||||||||||||||||
| 74 | "alias for '${old_command}'."); | ||||||||||||||||||||||
| 75 | } else { | ||||||||||||||||||||||
| 76 | 0 | $self->msg("New alias '${al}' for command string '${cmd_str}' created."); | |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | } else { | ||||||||||||||||||||||
| 79 | 0 | $self->errmsg("You must alias to a command name, and '${command}' isn't one."); | |||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||
| 83 | |||||||||||||||||||||||
| 84 | 1 | ▶ | unless (caller) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 85 | # Demo it. | ||||||||||||||||||||||
| 86 | 0 | require Devel::Trepan::CmdProcessor::Mock; | |||||||||||||||||||||
| 87 | 0 | my $proc = Devel::Trepan::CmdProcessor::Mock::setup(); | |||||||||||||||||||||
| 88 | 0 | my $cmd = __PACKAGE__->new($proc); | |||||||||||||||||||||
| 89 | 0 | $cmd->run([$NAME, 'yy', 'foo']); | |||||||||||||||||||||
| 90 | 0 | $cmd->run([$NAME, 'yy', 'step']); | |||||||||||||||||||||
| 91 | 0 | $cmd->run([$NAME]); | |||||||||||||||||||||
| 92 | 0 | $cmd->run([$NAME, 'yy', 'next']); | |||||||||||||||||||||
| 93 | 0 | $cmd->run([$NAME, 'evd', 'show', 'evaldisplay']); | |||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||
| 95 | |||||||||||||||||||||||
| 96 | 1 | 1; | |||||||||||||||||||||