File Coverage

lib/Devel/Trepan/CmdProcessor/Command/Finish.pm
Criterion Covered Total %
statement 66 98 67.3
branch 0 16 0.0
condition n/a
subroutine 22 24 91.6
pod 0 2 0.0
total 88 140 62.8


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   94 use warnings; use utf8;
  12     12   29  
  12     1   368  
  12     1   64  
  12         25  
  12         62  
  1         6  
  1         3  
  1         20  
  1         4  
  1         3  
  1         4  
4              
5 12     12   307 use rlib '../../../..';
  12     1   28  
  12         56  
  1         32  
  1         1  
  1         5  
6              
7             # rlib '../running'
8             # rlib '../../app/breakpoint' # FIXME: possibly temporary
9              
10             package Devel::Trepan::CmdProcessor::Command::Finish;
11              
12 12     12   4482 use if !@ISA, Devel::Trepan::CmdProcessor::Command ;
  12     1   26  
  12         64  
  1         379  
  1         2  
  1         4  
13 12     12   1630 use vars qw(@ISA);
  12     1   25  
  12         754  
  1         28  
  1         2  
  1         67  
14             unless (@ISA) {
15 12     12   72 eval <<'EOE';
  12     12   26  
  12     12   659  
  12     12   83  
  12     12   24  
  12     12   571  
  12         73  
  12         27  
  12         543  
  12         70  
  12         28  
  12         610  
  12         75  
  12         25  
  12         539  
  12         84  
  12         29  
  12         514  
16             use constant ALIASES => qw(fin);
17             use constant CATEGORY => 'running';
18             use constant SHORT_HELP => 'Step to end of current method (step out)';
19             use constant MIN_ARGS => 0; # Need at least this many
20             use constant MAX_ARGS => 1; # Need at most this many
21             use constant NEED_STACK => 1;
22             EOE
23             }
24              
25 12     12   82 use strict;
  12     1   25  
  12         503  
  1         6  
  1         3  
  1         36  
26             @ISA = @CMD_ISA;
27 12     12   65 use vars @CMD_VARS; # Value inherited from parent
  12     1   22  
  12         1383  
  1         6  
  1         2  
  1         95  
28              
29             our $NAME = set_name();
30             =pod
31              
32             =head2 Synopsis:
33              
34             =cut
35             our $HELP = <<'HELP';
36             =pod
37              
38             B<finish> [I<levels>]
39              
40             Continue execution until the program is about to leave the current
41             function. Sometimes this is called "step out".
42              
43             When integer I<levels> is specified, that many frame levels need to be
44             popped. The default is 1.
45              
46             =head2 See also:
47              
48             L<C<break>|Devel::Trepan::CmdProcessor::Command::Break>,
49             L<C<continue>|Devel::Trepan::CmdProcessor::Command::Continue>,
50             L<C<next> (step over)|Devel::Trepan::CmdProcessor::Command::Next>, and
51             L<C<step> (step into)|Devel::Trepan::CmdProcessor::Command::Step>.
52              
53             =cut
54             HELP
55              
56 12     12   86 no warnings 'redefine';
  12     1   30  
  12         3558  
  1         6  
  1         1  
  1         258  
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 $event = $proc->{event};
  0            
63 0 0         if ($event eq 'return') {
  0 0          
    0          
    0          
64 0           $proc->errmsg("Can't run ${NAME} while inside a return. Step and try again.");
  0            
65 0           return;
  0            
66             } elsif ($event eq 'call') {
67 0           $proc->errmsg("Can't run ${NAME} while inside a call. Step and try again.");
  0            
68 0           return;
  0            
69             }
70              
71 0           my ($opts, $level_count) = ({}, 1);
  0            
72 0 0         if (scalar @$args != 1) {
  0 0          
73             # Form is not "finish" which means "finish 1"
74 0           my $count_str = $args->[1];
  0            
75 0           $opts = {
  0            
76             msg_on_error =>
77             "The '${NAME}' command argument must eval to an integer. Got: ${count_str}",
78             min_value => 1
79             };
80 0           my $count = $proc->get_an_int($count_str, $opts);
  0            
81 0 0         return unless defined $count;
  0 0          
82 0           $level_count = $count;
  0            
83             }
84 0           $proc->finish($level_count);
  0            
85             }
86              
87             unless (caller) {
88             # require_relative '../mock'
89             # dbgr, cmd = MockDebugger::setup
90             # p cmd.run([cmd.name])
91             }
92              
93             1;