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

filter: Statementstmt 0.0% 0 / 72 Branchbran 0.0% 0 / 20 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 119 CC 9 SCAR 38.3
CC
9
Cov
0%
run
90.0
complete
2.0
BEGIN
2.0
CRAP 46.0
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org>
3 use warnings; use utf8;
4 use rlib '../../../../..';
5  
6 package Devel::Trepan::CmdProcessor::Command::Info::Frame;
7  
8 use Devel::Trepan::CmdProcessor::Command::Subcmd::Core;
9  
10 use strict;
11 our (@ISA, @SUBCMD_VARS);
12 # Values inherited from parent
13 use vars @Devel::Trepan::CmdProcessor::Command::Subcmd::SUBCMD_VARS;
14  
15 ## FIXME: do automatically.
16 our $CMD = "info frame";
17  
18 unless (@ISA) {
19 eval <<"EOE";
20 use constant MAX_ARGS => 1; # Need at most this many - undef -> unlimited.
21 EOE
22 }
23 @ISA = qw(Devel::Trepan::CmdProcessor::Command::Subcmd);
24  
25 =pod
26  
27 =head2 Synopsis:
28  
29 =cut
30  
31 our $HELP = <<"HELP";
32 =pod
33  
34 B<info frame> [I<frame-num>]
35  
36 Show information about I<frame-num>. If no frame number is given, use
37 the selected frame
38  
39 =head2 See also:
40  
41 L<C<info variables my>|Devel::Trepan::CmdProcessor::Command::Info::Variables::My>> and L<C<info variables our>|Devel::Trepan::CmdProcessor::Command::Info::::Variables::Our>.
42  
43 =cut
44 HELP
45  
46 our $SHORT_HELP = 'Show information about the selected frame';
47 our $MIN_ABBREV = length('fr');
48  
49 no warnings 'redefine';
50 sub complete($$)
51 {
52 my ($self, $prefix) = @_;
53 $self->{proc}->frame_complete($prefix, 1);
54 }
55  
56 sub run($$)
57 {
58 my ($self, $args) = @_;
59 my $proc = $self->{proc};
60 my ($frame, $frame_num);
61  
62 if (@$args == 3) {
63 my ($low, $high) = $proc->frame_low_high(0);
64 my $opts = {
65 min_value => $low,
66 max_value => $high
67 };
68 $frame_num = $proc->get_an_int($args->[2], $opts);
69 return unless defined $frame_num;
70 $frame_num += $proc->{stack_size} if $frame_num < 0;
71 $frame = $proc->{frames}[$frame_num];
72 } else {
73 $frame_num = $proc->{frame_index};
74 $frame = $proc->{frame};
75 }
76  
77 my $is_last = $frame_num == $proc->{stack_size}-1;
78 my $m = sprintf("Frame %2d", $frame_num);
79 $proc->section($m);
80 my @titles = qw(package function file line);
81 my $i=-1;
82 for my $field (qw(pkg fn file line)) {
83 $i++;
84 next unless exists $frame->{$field} && $frame->{$field};
85 next if $field eq 'fn' && $is_last;
86 $m = " ${titles[$i]}: " . $frame->{$field};
87 $proc->msg($m);
88 }
89 my $cop = Devel::Callsite::callsite($frame_num);
90 $proc->msg(sprintf " OP address: 0x%x.", $cop);
91 if ($is_last) {
92 $proc->msg(" Bottom-most (least recent) frame");
93 return
94 }
95 for my $field (qw(wantarray is_require)) {
96 next unless $frame->{$field};
97 $m = " ${field}: " . $frame->{$field};
98 $proc->msg($m);
99 }
100 my $args_ary = $frame->{args};
101 if ($args_ary) {
102 $m = sprintf " args: %s", join(', ', @$args_ary);
103 $proc->msg($m);
104 }
105 }
106  
107 unless (caller) {
108 require Devel::Trepan;
109 # Demo it.
110 # require_relative '../../mock'
111 # my($dbgr, $parent_cmd) = MockDebugger::setup('show');
112 # $cmd = __PACKAGE__->new(parent_cmd);
113 # $cmd->run(@$cmd->prefix);
114 }
115  
116 # Suppress a "used-once" warning;
117 $HELP || scalar @SUBCMD_VARS;