blib/lib/Devel/Trepan/CmdProcessor/Command/Load_Subcmd/Subcmd.pm untested

filter: Statementstmt 0.0% 0 / 62 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 95 CC 6 SCAR 27.8
CC
6
Cov
0%
run
42.0
complete
2.0
BEGIN
2.0
CRAP 16.1
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2014 Rocky Bernstein <rocky@cpan.org>
3 use warnings; use utf8;
4 use rlib '../../../../..';
5  
6 package Devel::Trepan::CmdProcessor::Command::Load::Subcmd;
7 use Cwd 'abs_path';
8  
9 use Devel::Trepan::CmdProcessor::Command::Subcmd::Core;
10 use Devel::Trepan::DB::LineCache;
11  
12 use strict;
13 our (@ISA, @SUBCMD_VARS);
14 # Values inherited from parent
15 use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS;
16  
17 unless (@ISA) {
18 eval <<"EOE";
19 use constant MIN_ARGS => 1;
20 use constant MAX_ARGS => 2;
21 use constant NEED_STACK => 0;
22 EOE
23 }
24  
25 @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd);
26  
27 our $HELP = <<'HELP';
28 =pod
29  
30 B<load subcmd> I<command> [I<Trepan-subcmd-module>]
31  
32 Load debugger subcommands of command
33 I<command>. [I<Trepan-subcmd-module>] is the file name a Devel::Trepan
34 subcommand module. If not given, we'll reload all subcommands under
35 command. This may or not be in the directory you were expecting;
36 beware when reloading everything.
37  
38 This command is useful if you want to add, change, or fix a debugger
39 command while inside the debugger.
40 =cut
41 HELP
42  
43 our $SHORT_HELP = 'Load debugger sub-command(s)';
44 our $MIN_ABBREV = length('sub');
45  
46 no warnings 'redefine';
47  
48 sub complete($$)
49 {
50 my ($self, $prefix) = @_;
51 $self->{proc}->filename_complete($prefix);
52 }
53  
54 sub run($$)
55 {
56 my ($self, $args) = @_;
57 my $proc = $self->{proc};
58 my @args = @$args; shift @args; shift @args;
59 my $cmd_name = shift @args;
60 my $mgr = $proc->{commands}{$cmd_name};
61 if ($mgr) {
62 if ($mgr->can('load_debugger_subcommand')) {
63 if (scalar @args == 0) {
64 $mgr->load_debugger_subcommands();
65 $proc->msg("Subcommands of command '$cmd_name' reloaded");
66 } else {
67 my $trepan_subcmd_module = shift @args;
68 if (-r $trepan_subcmd_module) {
69 my $cmd="";
70 if ($mgr->load_debugger_subcommand(ucfirst
71 $cmd_name,
72 $trepan_subcmd_module)) {
73 my $msg = sprintf("File '%s' of command '%s' loaded",
74 $trepan_subcmd_module, $cmd_name);
75 $proc->msg($msg);
76 }
77 } else {
78 $proc->errmsg("File '$trepan_subcmd_module' is not readable")
79 }
80 }
81 } else {
82 $proc->errmsg("Command '$cmd_name' is does not have sub commands")
83 }
84 } else {
85 $proc->errmsg("Can't find debugger command: '$cmd_name'")
86 }
87 }
88  
89 unless (caller) {
90 require Devel::Trepan;
91 # Demo it.
92 # require_relative '../../mock'
93 # my($dbgr, $parent_cmd) = MockDebugger::setup('show');
94 # $cmd = __PACKAGE__->new(parent_cmd);
95 # $cmd->run(@$cmd->prefix);
96 }
97  
98 # Suppress a "used-once" warning;
99 $HELP || scalar @SUBCMD_VARS;