blib/lib/Devel/Trepan/CmdProcessor/Command/Info_Subcmd/Variables_Subcmd/Our.pm untested

filter: Statementstmt 0.0% 0 / 74 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 93 CC 2 SCAR 9.4
CC
2
Cov
0%
get_var_hash
6.0
create_frame
2.0
BEGIN
2.0
CRAP 2.6
1 # -*- coding: utf-8 -*-
2 # Copyright (C) 2011-2012, 2014 Rocky Bernstein <rocky@cpan.org>
3 use warnings; no warnings 'redefine'; no warnings 'once';
4 use rlib '../../../../../..';
5 package Devel::Trepan::CmdProcessor::Command::Info::Variables::Our;
6  
7 use vars qw(@ISA @SUBCMD_VARS);
8 use strict;
9 use Devel::Trepan::CmdProcessor::Command::Info_Subcmd::Variables_Subcmd::My;
10 use PadWalker qw(peek_our);
11  
12 our $CMD = "info variables our";
13 our @CMD = split(/ /, $CMD);
14 use constant MAX_ARGS => undef;
15 use constant NEED_STACK => 1;
16 =pod
17  
18 =head2 Synopsis:
19  
20 =cut
21 our $MIN_ABBREV = length('o');
22 our $HELP = <<'HELP';
23 =pod
24  
25 B<info variables our>
26  
27 B<info variables our -v>
28  
29 B<info variables our> I<var1> [I<var2>...]
30  
31 List C<our> variables at the current stack level. Use the
32 frame changing commands like C<up>, C<down> or C<frame> set the
33 current frame.
34  
35 In the first form, give a list of C<our> variable names only.
36 In the second form, list variable names and values In the third form,
37 list variable names and values of I<var1>, etc.
38  
39 =head2 See also:
40  
41 L<C<info variables
42 lexicals>|Devel::Trepan::CmdProcessor::Command::Info::Variables::Lexicals>,
43 L<C<info variables
44 my>|Devel::Trepan::CmdProcessor::Command::Info::Variables::My>, and
45 frame-changing commands
46  
47 =cut
48 HELP
49 our $SHORT_HELP = "Information about 'our' variables.";
50  
51 @ISA = qw(Devel::Trepan::CmdProcessor::Command::Info::Variables::My);
52  
53 sub get_var_hash($;$)
54 {
55 my ($self, $fixup_num) = @_;
56 # FIXME: combine with My.pm
57 my $i = 0;
58 while (my ($pkg, $file, $line, $fn) = caller($i++)) { ; };
59 my $diff = $i - $DB::stack_depth;
60  
61 # FIXME: 5 is a magic fixup constant, also found in DB::finish.
62 # Remove it.
63 $fixup_num = 5 unless defined($fixup_num);
64 peek_our($diff + $self->{proc}{frame_index} + $fixup_num);
65 }
66  
67 unless (caller) {
68 # Demo it.
69 require Devel::Trepan;
70 my $proc = Devel::Trepan::CmdProcessor->new;
71 my $grandparent =
72 Devel::Trepan::CmdProcessor::Command::Info->new($proc, 'info');
73 my $parent =
74 Devel::Trepan::CmdProcessor::Command::Info::Variables->new($grandparent,
75 'variables');
76 my $cmd = __PACKAGE__->new($parent, 'our');
77  
78 eval {
79 sub create_frame() {
80 my ($pkg, $file, $line, $fn) = caller(0);
81 $DB::package = $pkg;
82 return [
83 {
84 file => $file,
85 fn => $fn,
86 line => $line,
87 pkg => $pkg,
88 }];
89 }
90 };
91 my $frame_ary = create_frame();
92 $proc->frame_setup($frame_ary);
93  
94 $cmd->run($cmd->{prefix}, -2);
95 my @args = @{$cmd->{prefix}};
96 push @args, '$args';
97 print '-' x 40, "\n";
98 push @args, '@CMD';
99 print '-' x 40, "\n";
100 $cmd->run(\@args, -2);
101 print '-' x 40, "\n";
102 $cmd->run($cmd->{prefix}, -1);
103 print '-' x 40, "\n";
104 my @complete = $cmd->complete('', -1);
105 print join(', ', @complete), "\n";
106 print '-' x 40, "\n";
107 @complete = $cmd->complete('$p', -1);
108 print join(', ', @complete), "\n";
109 }
110  
111 1;