« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Return.pm
↑ Summary
lib/Devel/Trepan/CmdProcessor/Msg.pm »
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # Copyright (C) 2011-2012, 2014-2015 Rocky Bernstein <rocky@cpan.org> | ||
| 3 | use warnings; no warnings 'redefine'; | ||
| 4 | use rlib '../../../../..'; | ||
| 5 | |||
| 6 | package Devel::Trepan::CmdProcessor::Command::Set::Return; | ||
| 7 | |||
| 8 | use Devel::Trepan::CmdProcessor::Command::Subcmd::Core; | ||
| 9 | |||
| 10 | use strict; | ||
| 11 | use vars qw(@ISA @SUBCMD_VARS); | ||
| 12 | @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd); | ||
| 13 | # Values inherited from parent | ||
| 14 | use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS; | ||
| 15 | |||
| 16 | ## FIXME: do automatically. | ||
| 17 | our $CMD = "set return"; | ||
| 18 | |||
| 19 | =pod | ||
| 20 | |||
| 21 | =head2 Synopsis: | ||
| 22 | |||
| 23 | =cut | ||
| 24 | our $HELP = <<'HELP'; | ||
| 25 | =pod | ||
| 26 | |||
| 27 | B<set return> I<return value> | ||
| 28 | |||
| 29 | Set the value about to be returned. This only works if you are stopped | ||
| 30 | at a return event. | ||
| 31 | |||
| 32 | =head2 See also: | ||
| 33 | |||
| 34 | L<C<show return>|Devel::Trepan::CmdProcessor::Command::Show::Return> | ||
| 35 | |||
| 36 | =cut | ||
| 37 | |||
| 38 | HELP | ||
| 39 | |||
| 40 | our $SHORT_HELP = "Set the value about to be returned"; | ||
| 41 | |||
| 42 | our $MIN_ABBREV = length('ret'); | ||
| 43 | our $MIN_ARGS = 1; | ||
| 44 | our $MAX_ARGS = 1; | ||
| 45 | our $NEED_STACK = 1; | ||
| 46 | |||
| 47 | use Data::Dumper; | ||
| 48 | |||
| 49 | sub run($$) | ||
| 50 | { | ||
| 51 | my ($self, $args) = @_; | ||
| 52 | my $proc = $self->{proc}; | ||
| 53 | my @args = @$args; | ||
| 54 | shift @args; | ||
| 55 | no warnings 'once'; | ||
| 56 | unless ($DB::event eq 'return') { | ||
| 57 | $proc->errmsg("We are not stopped at a return"); | ||
| 58 | return; | ||
| 59 | } | ||
| 60 | my $ret_type = $proc->{dbgr}->return_type(); | ||
| 61 | if ('undef' eq $ret_type) { | ||
| 62 | $proc->msg("Return value is <undef>"); | ||
| 63 | } elsif ('array' eq $ret_type) { | ||
| 64 | # Not quite right, but we'll use this for now. | ||
| 65 | my @new_value = eval(join(' ', @args)); | ||
| 66 | @DB::return_value = @new_value; | ||
| 67 | $proc->msg("Return array value set to:"); | ||
| 68 | $proc->msg(Dumper(@new_value)); | ||
| 69 | } elsif ('scalar' eq $ret_type) { | ||
| 70 | my $new_value = eval(join(' ', @args)); | ||
| 71 | $DB::return_value = $new_value; | ||
| 72 | $proc->msg("Return value set to: $new_value"); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | |||
| 76 | unless (caller) { | ||
| 77 | # Demo it. | ||
| 78 | # FIXME: DRY with other subcommand manager demo code. | ||
| 79 | require Devel::Trepan::CmdProcessor::Mock; | ||
| 80 | my ($proc, $cmd) = | ||
| 81 | Devel::Trepan::CmdProcessor::Mock::subcmd_setup(); | ||
| 82 | Devel::Trepan::CmdProcessor::Mock::subcmd_demo_info($proc, $cmd); | ||
| 83 | } | ||
| 84 | |||
| 85 | # Suppress a "used-once" warning; | ||
| 86 | $HELP || scalar @SUBCMD_VARS; |