blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Display.pm untested

filter: Statementstmt 0.0% 0 / 68 Branchbran 0.0% 0 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 100 CC 9 SCAR 29.1
CC
9
Cov
0%
run
42.0
display_print
20.0
complete
2.0
CRAP 18.4
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2015 Rocky Bernstein <rocky@cpan.org>
3 use warnings; use utf8;
4 use rlib '../../../../..';
5  
6 package Devel::Trepan::CmdProcessor::Command::Info::Display;
7 use Devel::Trepan::CmdProcessor::Command::Subcmd::Core;
8  
9 use strict;
10 use vars qw(@ISA @SUBCMD_VARS);
11 @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd);
12 # Values inherited from parent
13 use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS;
14  
15 our $SHORT_HELP = 'List display information';
16  
17 ## FIXME: do automatically.
18 our $CMD = "info display";
19  
20 our $HELP = <<'HELP';
21 =pod
22  
23 B<info display> [I<num1> ...] [B<verbose>]
24  
25 Show status of user-settable display. If no display numbers are
26 given, the show all displays. Otherwise only those displays
27 listed are shown and the order given. If B<verbose> is given, more
28 information provided about each breakpoint.
29  
30 =head2 Examples:
31  
32 trepanpl: info display
33 Num Type Disp Enb Where
34 1 breakpoint keep y at gcd.pl:8
35 breakpoint already hit 1 time
36 No actions.
37 No watch expressions defined.
38  
39 The I<Disp> column contains one of I<keep>, I<del>, the disposition of
40 the breakpoint after it gets hit.
41  
42 The I<Enb> column indicates whether the breakpoint is enabled.
43  
44 The I<Where> column indicates where the breakpoint is located.
45  
46 =head2 See also:
47  
48 L<C<display>|Devel::Trepan::CmdProcessor::Command::Display>, and
49 L<C<undisplay>|Devel::Trepan::CmdProcessor::Command::Undisplay>
50  
51 =cut
52 HELP
53  
54 our $MIN_ABBREV = length('di');
55  
56 no warnings 'redefine';
57 sub complete($$)
58 {
59 my ($self, $prefix) = @_;
60 my @displays = @{$self->{proc}{displays}{list}};
61 my @completions = map $_->number, @displays;
62 Devel::Trepan::Complete::complete_token(\@completions, $prefix);
63 }
64  
65 sub display_print($$)
66 {
67 my ($self, $display) = @_;
68 my $proc = $self->{proc};
69  
70 my $rt = defined($display->return_type) ? $display->return_type : '?';
71 my $fmt = defined($display->fmt) ? $display->fmt : '?';
72 my $enabled .= $display->enabled ? 'y ' : 'n ';
73 my $mess = sprintf("%-3d: %s %s %s %s", $display->number,
74 $rt, $fmt, $enabled, $display->arg);
75 $proc->msg($mess);
76 }
77  
78 # sub save_command($)
79 # {
80 # my $self = shift;
81 # my $proc = $self->{proc};
82 # my $displays = $proc->{displays};
83 # my @res = ();
84 # for my $display ($display->list) {
85 # push @res, "break ${loc}";
86 # }
87 # return @res;
88 # }
89  
90 sub run($$) {
91 my ($self, $args) = @_;
92 my $verbose = 0;
93 my $proc = $self->{proc};
94 my @args = ();
95 if (scalar @{$args} > 2) {
96 @args = splice(@{$args}, 2);
97 @args = $proc->get_int_list(\@args);
98 }
99  
100 my @displays = @{$proc->{displays}{list}};
101 if (0 == scalar @displays) {
102 $proc->msg('No Displays.');
103 } else {
104 # There's at least one
105 $proc->section("Num Type Fmt En? Value");
106 if (scalar(@args) == 0) {
107 for my $display (@displays) {
108 $self->display_print($display);
109 }
110 } else {
111 my @not_found = ();
112 for my $display_num (@args) {
113 my $display = $proc->{displays}->find($display_num);
114 if (defined($display)) {
115 $self->display_print($display, $verbose);
116 } else {
117 push @not_found, $display_num;
118 }
119 }
120 if (scalar @not_found) {
121 my $msg = sprintf("No display number(s) %s.\n",
122 join(', ', @not_found));
123 $proc->errmsg($msg);
124 }
125 }
126 }
127 }
128  
129 if (caller) {
130 # Demo it.
131 # use rlib '../../mock'
132 # name = File.basename(__FILE__, '.rb')
133 # dbgr, cmd = MockDebugger::setup('info')
134 # subcommand = Trepan::Subcommand::InfoBreakpoints.new(cmd)
135  
136 # print '-' * 20
137 # subcommand.run(%w(info break))
138 # print '-' * 20
139 # subcommand.summary_help(name)
140 # print
141 # print '-' * 20
142  
143 # require 'thread_frame'
144 # tf = RubyVM::ThreadFrame.current
145 # pc_offset = tf.pc_offset
146 # sub foo
147 # 5
148 # end
149  
150 # brk_cmd = dbgr.core.processor.commands['break']
151 # brk_cmd.run(['break', "O${pc_offset}"])
152 # cmd.run(%w(info break))
153 # print '-' * 20
154 # brk_cmd.run(['break', 'foo'])
155 # subcommand.run(%w(info break))
156 # print '-' * 20
157 # print subcommand.save_command
158 }
159  
160 1;