« blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Variables_Subcmd/Lexicals.pm
↑ Summary
lib/Devel/Trepan/CmdProcessor/Command/Undisplay.pm »
| 1 | # -*- coding: utf-8 -*- | ||
| 2 | # Copyright (C) 2012, 2014 Rocky Bernstein <rocky@cpan.org> | ||
| 3 | use warnings; no warnings 'redefine'; | ||
| 4 | use rlib '../../../../..'; | ||
| 5 | |||
| 6 | package Devel::Trepan::CmdProcessor::Command::Load::Module; | ||
| 7 | use Cwd 'abs_path'; | ||
| 8 | |||
| 9 | # FIXME: allow specifiying just the Perl module name, | ||
| 10 | # e.g. File::Basename. | ||
| 11 | |||
| 12 | use Devel::Trepan::CmdProcessor::Command::Subcmd::Core; | ||
| 13 | |||
| 14 | use strict; | ||
| 15 | our (@ISA, @SUBCMD_VARS); | ||
| 16 | # Values inherited from parent | ||
| 17 | use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS; | ||
| 18 | |||
| 19 | unless (@ISA) { | ||
| 20 | eval <<"EOE"; | ||
| 21 | use constant MAX_ARGS => 0; # Need at most this many - undef -> unlimited. | ||
| 22 | EOE | ||
| 23 | } | ||
| 24 | |||
| 25 | @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd); | ||
| 26 | |||
| 27 | =pod | ||
| 28 | |||
| 29 | =head2 Synopsis: | ||
| 30 | |||
| 31 | =cut | ||
| 32 | |||
| 33 | our $HELP = <<'HELP'; | ||
| 34 | =pod | ||
| 35 | |||
| 36 | B<load module> {I<Perl-module-file>} | ||
| 37 | |||
| 38 | Load or reload a Perl module. This is like I<require> with a file | ||
| 39 | name, but we force the load or reload. Use this if you change the Perl | ||
| 40 | module while you are debugging and it want those changes to take | ||
| 41 | effect in both the debugged program and inside the debugger. | ||
| 42 | |||
| 43 | Note however that any functions along the call stack will not be | ||
| 44 | changed. | ||
| 45 | =cut | ||
| 46 | HELP | ||
| 47 | |||
| 48 | our $SHORT_HELP = '(re)load Perl module file(s)'; | ||
| 49 | our $MIN_ABBREV = length('mo'); | ||
| 50 | |||
| 51 | sub complete($$) | ||
| 52 | { | ||
| 53 | my ($self, $prefix) = @_; | ||
| 54 | $self->{proc}->filename_complete($prefix); | ||
| 55 | } | ||
| 56 | |||
| 57 | sub run($$) | ||
| 58 | { | ||
| 59 | my ($self, $args) = @_; | ||
| 60 | my $proc = $self->{proc}; | ||
| 61 | my @args = @$args; shift @args; shift @args; | ||
| 62 | foreach my $module (@args) { | ||
| 63 | $module .= '.pm' unless -r $module || substr($module,-3,3) eq '.pm'; | ||
| 64 | if (-r $module) { | ||
| 65 | my $rc = do $module; | ||
| 66 | if ($rc) { | ||
| 67 | $proc->msg("Perl module file $module loaded"); | ||
| 68 | } else { | ||
| 69 | if ($@) { | ||
| 70 | $proc->errmsg("Trouble reading ${module}: $@"); | ||
| 71 | } else { | ||
| 72 | $proc->errmsg("Perl module ${module} gave invalid return"); | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | $proc->errmsg("Can't find Perl module file $module"); | ||
| 77 | } | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | unless (caller) { | ||
| 82 | require Devel::Trepan; | ||
| 83 | # Demo it. | ||
| 84 | # require_relative '../../mock' | ||
| 85 | # my($dbgr, $parent_cmd) = MockDebugger::setup('show'); | ||
| 86 | # $cmd = __PACKAGE__->new(parent_cmd); | ||
| 87 | # $cmd->run(@$cmd->prefix); | ||
| 88 | } | ||
| 89 | |||
| 90 | # Suppress a "used-once" warning; | ||
| 91 | $HELP || scalar @SUBCMD_VARS; |