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

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 76 CC 7 SCAR 25.7
CC
7
Cov
0%
wpprint
20.0
run
20.0
BEGIN
2.0
CRAP 13.1
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org>
3  
4 use warnings;
5 use rlib '../../../../..';
6  
7 package Devel::Trepan::CmdProcessor::Command::Info::Watch;
8 use Devel::Trepan::CmdProcessor::Command::Subcmd::Core;
9  
10 @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd);
11 # Values inherited from parent
12 use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS;
13  
14 unless (@ISA) {
15 eval <<"EOE";
16 use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited.
17 EOE
18 }
19  
20 our $CMD = 'info watch';
21 =pod
22  
23 =head2 Synopsis:
24  
25 =cut
26  
27 our $HELP = <<'HELP';
28 =pod
29  
30 B<info watch> [I<watchpoint1> I<watchpoint2> ...]
31  
32 List watch information. If watchpoints are specified, only information
33 about them is shown. If no watchpoints are specified, show information
34 about all watchpoints.
35  
36 =head2 See also:
37  
38 L<C<watch>|<Devel::Trepan::CmdProcessor::Command::Watch>
39  
40 =cut
41 HELP
42  
43 our $MIN_ABBREV = length('wa');
44 our $SHORT_HELP = "Show watchpoint information";
45  
46 no warnings 'redefine';
47 # sub complete($$) {
48 # {
49 # my ($self, $prefix) = @_;
50 # my @cmds = sort keys %{$proc->{macros}};
51 # Trepan::Complete.complete_token(@cmds, $prefix);
52 # }
53  
54 # sub save_command($)
55 # {
56 # my $self = shift;
57 # my $proc = $self->{proc};
58 # my $wpmgr = $proc->{dbgr}{watch};
59 # my @res = ();
60 # for my $bp ($wpmgr->list) {
61 # push @res, "watch ${loc}";
62 # }
63 # return @res;
64 # }
65  
66 sub wpprint($$;$)
67 {
68 my ($self, $wp, $verbose) = @_;
69 my $proc = $self->{proc};
70 my $disp = $wp->enabled ? 'y ' : 'n ';
71  
72 my $mess = sprintf('%-4dwatchpoint %s %s', $wp->id, $disp, $wp->expr);
73 $proc->msg($mess);
74  
75 if ($wp->hits > 0) {
76 my $ss = ($wp->hits > 1) ? 's' : '';
77 my $msg = sprintf("\twatchpoint already hit %d time%s",
78 $wp->hits, $ss);
79 $proc->msg($msg);
80 }
81 }
82  
83 sub run($$) {
84 my ($self, $args) = @_;
85 my $proc = $self->{proc};
86 my $watchmgr = $proc->{dbgr}{watch};
87 my @args = @$args;
88 if (scalar(@args) > 2) {
89 shift @args; shift @args;
90 for my $wp_name (@args) {
91 if ($watchmgr->find_by_name({$wp_name})) {
92 $self->wpprint($wp_name);
93 } else {
94 $proc->msg("$wp_name is not a defined watchpoint");
95 }
96 }
97 } else {
98 my @watchpoints = $watchmgr->list;
99 if (scalar @watchpoints == 0) {
100 $proc->msg("No watch expressions defined.");
101 } else {
102 # There's at least one
103 $proc->section("Num Type Enb Expression");
104 for my $wp (@watchpoints) {
105 $self->wpprint($wp);
106 }
107 }
108 }
109 }
110  
111 unless(caller) {
112 # Demo it.
113 # require_relative '../../mock';
114 # my $cmd = MockDebugger::sub_setup(__PACKAGE__);
115 # my $cmd->run($cmd->{prefix} + %w(u foo));
116 }
117  
118 1;