File Coverage

lib/Devel/Trepan/CmdProcessor/Command/Action.pm
Criterion Covered Total %
statement 72 110 65.4
branch 0 16 0.0
condition n/a
subroutine 24 26 92.3
pod 0 2 0.0
total 96 154 62.3


line stmt bran cond sub pod time code
1             # -*- coding: utf-8 -*-
2             # Copyright (C) 2011-2014 Rocky Bernstein <rocky@cpan.org>
3 12     12   155 use warnings; no warnings 'redefine';
  12     12   39  
  12     1   654  
  12     1   134  
  12         32  
  12         637  
  1         14  
  1         6  
  1         56  
  1         11  
  1         5  
  1         69  
4 12     12   86 use rlib '../../../..';
  12     1   32  
  12         147  
  1         11  
  1         5  
  1         16  
5              
6             package Devel::Trepan::CmdProcessor::Command::Action;
7 12     12   5223 use English qw( -no_match_vars );
  12     1   38  
  12         143  
  1         721  
  1         6  
  1         14  
8              
9 12     12   6024 use if !@ISA, Devel::Trepan::Condition ;
  12     1   32  
  12         146  
  1         426  
  1         3  
  1         9  
10 12     12   1093 use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
  12     1   37  
  12         84  
  1         44  
  1         2  
  1         5  
11              
12             unless (@ISA) {
13 12     12   85 eval <<"EOE";
  12     12   32  
  12     12   838  
  12     12   79  
  12     12   36  
  12     12   575  
  12         74  
  12         30  
  12         588  
  12         66  
  12         31  
  12         506  
  12         74  
  12         36  
  12         494  
  12         66  
  12         26  
  12         418  
14             use constant ALIASES => qw(a);
15             use constant CATEGORY => 'breakpoints';
16             use constant NEED_STACK => 0;
17             use constant MIN_ARGS => 2; # Need at least this many
18             use constant MAX_ARGS => undef; # Need at most this many - undef -> unlimited.
19             use constant SHORT_HELP =>
20             'Set an action to be done before the line is executed.';
21             EOE
22             }
23              
24 12     12   2288 use strict; use vars qw(@ISA); @ISA = @CMD_ISA;
  12     12   34  
  12     1   281  
  12     1   65  
  12         33  
  12         542  
  1         61  
  1         4  
  1         27  
  1         6  
  1         2  
  1         59  
25 12     12   68 use vars @CMD_VARS; # Value inherited from parent
  12     1   32  
  12         4427  
  1         5  
  1         2  
  1         344  
26              
27             our $NAME = set_name();
28             =pod
29              
30             =head2 Synopsis:
31              
32             =cut
33             our $HELP = <<'HELP';
34             =pod
35              
36             B<action> I<position> I<Perl-statement>
37              
38             Set an action to be done before the line is executed. If line is
39             C<.>, set an action on the line about to be executed. The sequence
40             of steps taken by the debugger is:
41              
42             =over
43              
44             =item 1.
45             check for a breakpoint at this line
46              
47             =item 2.
48             print the line if necessary (tracing)
49              
50             =item 3.
51             do any actions associated with that line
52              
53             =item 4.
54             prompt user if at a breakpoint or in single-step
55              
56             =item 5.
57             evaluate line
58              
59             =back
60              
61             For example, this will print out the value of C<$foo> every time line
62             53 is passed:
63              
64             =head2 Examples:
65              
66             action 53 print "DB FOUND $foo\n"
67              
68             =head2 See also:
69              
70             C<help breakpoints>
71              
72             =cut
73             HELP
74              
75             # This method runs the command
76             sub run($$) {
77 0     0 0   my ($self, $args) = @_;
  0     0 0    
78 0           my $proc = $self->{proc};
  0            
79 0           my $frame = $proc->{frame};
  0            
80 0           my @args = @$args;
  0            
81 0           shift @args;
  0            
82              
83 0           my ($filename, $lineno, $fn, $gobble_count, $rest) =
  0            
84             $proc->parse_position(\@args, 0); # should be: , 1);
85 0 0         shift @args if $gobble_count-- > 0;
  0 0          
86 0 0         shift @args if $gobble_count-- > 0;
  0 0          
87             # error should have been shown previously
88              
89 0           my $action_expression = join(' ', @args);
  0            
90 0 0         unless (is_valid_condition($action_expression)) {
  0 0          
91 0           $proc->errmsg("Invalid action: $action_expression");
  0            
92             return
93 0           }
  0            
94 0           my $action = $self->{dbgr}->set_action($lineno, $filename,
  0            
95             $action_expression);
96 0 0         if ($action) {
  0 0          
97 0           my $id = $action->id;
  0            
98 0           my $filename = $proc->canonic_file($action->filename);
  0            
99 0           my $line_num = $action->line_num;
  0            
100 0           $proc->{actions}->add($action);
  0            
101 0           $proc->msg("Action $id set in $filename at line $line_num");
  0            
102              
103             }
104             }
105              
106             unless (caller) {
107             require Devel::Trepan::CmdProcessor::Mock;
108             my $proc = Devel::Trepan::CmdProcessor::Mock::setup();
109             # my $cmd = __PACKAGE__->new($proc);
110             # $cmd->run([$NAME]);
111             }
112              
113             1;