File Coverage

lib/Devel/Trepan/CmdProcessor/Command/Watch.pm
Criterion Covered Total %
statement 87 123 70.7
branch 0 8 0.0
condition n/a
subroutine 29 31 93.5
pod 0 2 0.0
total 116 164 70.7


line stmt bran cond sub pod time code
1             # -*- coding: utf-8 -*-
2             # Copyright (C) 2011-2012, 2014, 2016 Rocky Bernstein <rocky@cpan.org>
3 12     12   104 use warnings; use utf8;
  12     12   36  
  12     1   404  
  12     1   75  
  12         32  
  12         105  
  1         6  
  1         3  
  1         21  
  1         5  
  1         2  
  1         9  
4 12     12   314 use rlib '../../../..';
  12     1   32  
  12         74  
  1         21  
  1         3  
  1         5  
5              
6             package Devel::Trepan::CmdProcessor::Command::Watch;
7 12     12   4181 use English qw( -no_match_vars );
  12     1   29  
  12         84  
  1         307  
  1         3  
  1         6  
8              
9 12     12   4362 use if !@ISA, Devel::Trepan::WatchMgr ;
  12     1   31  
  12         80  
  1         248  
  1         3  
  1         7  
10 12     12   775 use if !@ISA, Devel::Trepan::Condition ;
  12     1   44  
  12         85  
  1         38  
  1         3  
  1         4  
11 12     12   1074 use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
  12     1   38  
  12         68  
  1         31  
  1         2  
  1         4  
12              
13             unless (@ISA) {
14 12     12   89 eval <<'EOE';
  12     12   33  
  12     12   839  
  12     12   84  
  12     12   45  
  12         748  
  12         103  
  12         40  
  12         612  
  12         86  
  12         33  
  12         577  
  12         78  
  12         34  
  12         426  
15             # eval "use constant ALIASES => qw(w);";
16             use constant CATEGORY => 'breakpoints';
17             use constant NEED_STACK => 0;
18             use constant SHORT_HELP =>
19             'Set to enter debugger when a watched expression changes';
20             use constant MIN_ARGS => 1; # Need at least this many
21             use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited.
22             EOE
23             }
24              
25 12     12   1946 use strict; use vars qw(@ISA); @ISA = @CMD_ISA;
  12     12   34  
  12     1   302  
  12     1   68  
  12         51  
  12         677  
  1         51  
  1         3  
  1         22  
  1         10  
  1         3  
  1         47  
26 12     12   98 use vars @CMD_VARS; # Value inherited from parent
  12     1   31  
  12         1456  
  1         6  
  1         2  
  1         96  
27              
28             our $NAME = set_name();
29             =pod
30              
31             =head2 Synopsis:
32              
33             =cut
34             our $HELP = <<'HELP';
35             =pod
36              
37             B<watch> I<Perl-expression>
38              
39             Stop every time I<Perl-expression> changes from its prior value.
40              
41             =head2 Examples:
42              
43             watch $a # enter debugger when the value of $a changes
44             watch scalar(@ARGV)) # enter debugger if size of @ARGV changes.
45              
46             =head2 See also
47              
48             L<C<delete>|Devel::Trepan::CmdProcessor::Command::Delete>,
49             L<C<enable>|Devel::Trepan::CmdProcessor::Command::Enable>,
50             L<C<disable>|Devel::Trepan::CmdProcessor::Command::Disable>, and
51             L<C<info watch>|Devel::Trepan::CmdProcessor::Command::Watch>.
52              
53             =cut
54             HELP
55              
56 12     12   85 no warnings 'redefine';
  12     1   31  
  12         2354  
  1         5  
  1         3  
  1         168  
57              
58             # This method runs the command
59             sub run($$) {
60 0     0 0   my ($self, $args) = @_;
  0     0 0    
61 0           my $proc = $self->{proc};
  0            
62 0           my $expr;
  0            
63 0           my @args = @{$args};
  0            
  0            
  0            
64 0           shift @args;
  0            
65              
66 0           $expr = join(' ', @args);
  0            
67 0 0         unless (is_valid_condition($expr)) {
  0 0          
68 0           $proc->errmsg("Invalid watch expression: $expr");
  0            
69             return
70 0           }
  0            
71 0           my $wp = $proc->{dbgr}->{watch}->add($expr);
  0            
72 0 0         if ($wp) {
  0 0          
73             # FIXME: handle someday...
74             # my $cmd_name = $args->[0];
75             # my $opts->{return_type} = parse_eval_suffix($cmd_name);
76 0           my $opts = {return_type => '$'};
  0            
77 0           my $mess = sprintf("Watch expression %d: %s set", $wp->id, $expr);
  0            
78 0           $proc->msg($mess);
  0            
79 0           $proc->eval($expr, $opts);
  0            
80 0           $proc->{set_wp} = $wp;
  0            
81              
82             # Without setting $DB::trace = 1, it is possible
83             # that a continue won't trigger calls to $DB::DB
84             # and therefore we won't check watch expressions.
85 12     12   99 no warnings 'once';
  12     1   38  
  12         1462  
  1         6  
  1         2  
  1         103  
86 0           $DB::trace = 1;
  0            
87             }
88             }
89              
90             unless (caller) {
91             require Devel::Trepan::CmdProcessor::Mock;
92             my $proc = Devel::Trepan::CmdProcessor::Mock::setup();
93             # my $cmd = __PACKAGE__->new($proc);
94             # $cmd->run([$NAME]);
95             }
96              
97             1;