Devel-Trepan
view release on metacpan or search on metacpan
lib/Devel/Trepan/CmdProcessor/Command/Set_Subcmd/Variable.pm view on Meta::CPAN
# -*- coding: utf-8 -*-
# Copyright (C) 2011-2012, 2014-215 Rocky Bernstein <rocky@cpan.org>
use warnings; no warnings 'redefine';
use rlib '../../../../..';
package Devel::Trepan::CmdProcessor::Command::Set::Variable;
use Devel::Trepan::CmdProcessor::Command::Subcmd::Core;
use PadWalker qw(peek_our peek_my);
use strict;
use vars qw(@ISA @SUBCMD_VARS);
@ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd);
# Values inherited from parent
use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS;
## FIXME: do automatically.
our $CMD = "set variable";
=pod
=head2 Synopsis:
=cut
our $HELP = <<'HELP';
=pod
B<set variable> I<variable-name> = I<value>
Set a I<my> or I<our> variable; I<value> must be a constant.
=head2 Examples:
set variable $foo = 20
set variable @ARY = (1,2,3)
=head2 See also:
L<C<eval>|Devel::Trepan::CmdProcessor::Command::Eval>
=cut
HELP
our $SHORT_HELP = "Set a 'my' or 'our' variable";
our $MIN_ABBREV = length('var');
our $MIN_ARGS = 2;
our $MAX_ARGS = undef;
our $NEED_STACK = 1;
sub set_var($$$)
{
my ($var_name, $ref, $value) = @_;
my $type = substr($var_name, 1, 1);
if ('$' eq $type) {
${$ref->{$var_name}} = $value;
} elsif ('@' eq $type) {
@{$ref->{$var_name}} = @{$value};
} elsif ('%' eq $type) {
%{$ref->{$var_name}} = %{$value};
} else {
${$ref->{$var_name}} = $value;
}
}
sub run($$)
{
my ($self, $args) = @_;
my $proc = $self->{proc};
( run in 1.036 second using v1.01-cache-2.11-cpan-c966e8aa7e8 )