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   129 use warnings; use utf8;
  12     12   28  
  12     1   367  
  12     1   65  
  12         24  
  12         97  
  1         6  
  1         2  
  1         21  
  1         5  
  1         2  
  1         7  
4 12     12   314 use rlib '../../../..';
  12     1   27  
  12         59  
  1         23  
  1         2  
  1         3  
5              
6             package Devel::Trepan::CmdProcessor::Command::Watch;
7 12     12   4584 use English qw( -no_match_vars );
  12     1   27  
  12         68  
  1         335  
  1         1  
  1         6  
8              
9 12     12   4208 use if !@ISA, Devel::Trepan::WatchMgr ;
  12     1   30  
  12         84  
  1         247  
  1         2  
  1         5  
10 12     12   35779 use if !@ISA, Devel::Trepan::Condition ;
  12     1   30  
  12         63  
  1         32  
  1         2  
  1         3  
11 12     12   916 use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
  12     1   29  
  12         74  
  1         40  
  1         1  
  1         4  
12              
13             unless (@ISA) {
14 12     12   75 eval <<'EOE';
  12     12   27  
  12     12   725  
  12     12   89  
  12     12   35  
  12         660  
  12         72  
  12         82  
  12         620  
  12         76  
  12         24  
  12         556  
  12         70  
  12         69  
  12         429  
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   1890 use strict; use vars qw(@ISA); @ISA = @CMD_ISA;
  12     12   30  
  12     1   244  
  12     1   57  
  12         53  
  12         585  
  1         57  
  1         3  
  1         20  
  1         4  
  1         2  
  1         52  
26 12     12   73 use vars @CMD_VARS; # Value inherited from parent
  12     1   28  
  12         1659  
  1         5  
  1         3  
  1         109  
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   80 no warnings 'redefine';
  12     1   39  
  12         2435  
  1         6  
  1         1  
  1         189  
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   113 no warnings 'once';
  12     1   35  
  12         1628  
  1         7  
  1         2  
  1         122  
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;