File Coverage

blib/lib/Devel/StackTrace/WithLexicals.pm
Criterion Covered Total %
statement 60 60 100.0
branch 13 20 65.0
condition 5 14 35.7
subroutine 10 10 100.0
pod n/a
total 88 104 84.6


line stmt bran cond sub pod time code
1             package Devel::StackTrace::WithLexicals;
2 6     6   109820 use strict;
  6         10  
  6         226  
3 6     6   27 use warnings;
  6         7  
  6         142  
4 6     6   109 use 5.008001;
  6         23  
  6         184  
5 6     6   23 use base 'Devel::StackTrace';
  6         7  
  6         3104  
6              
7 6     6   24638 use Devel::StackTrace::WithLexicals::Frame;
  6         12  
  6         178  
8              
9 6     6   2546 use PadWalker 'peek_my';
  6         3532  
  6         3097  
10              
11             our $VERSION = '2.00';
12              
13             # mostly copied from Devel::StackTrace 2.00
14             sub _record_caller_data {
15 8     8   236 my $self = shift;
16              
17 8   33     315 my $filter = $self->{filter_frames_early} && $self->_make_frame_filter();
18              
19             # We exclude this method by starting at least one frame back.
20 8   50     51 my $x = 1 + ( $self->{skip_frames} || 0 );
21              
22             # PadWalker ignores eval block and eval string, so we have to keep
23             # a different frame count for it
24 8         12 my $walker = 0;
25 8         23 for my $caller_count (0..$x) {
26 16         80 my $sub = (caller($caller_count))[3];
27 16 50       82 ++$walker unless $sub eq '(eval)';
28             }
29              
30 8 50       31 while (
31             my @c
32             = $self->{no_args}
33             ? caller( $x++ )
34             : do {
35             package # the newline keeps dzil from adding a version here
36             DB;
37 23         34 @DB::args = ();
38 23         151 caller( $x++ );
39             }
40             ) {
41              
42 15         15 my @args;
43              
44 15 50       43 @args = $self->{no_args} ? () : @DB::args;
45              
46 15         41 my $raw = {
47             caller => \@c,
48             args => \@args,
49             };
50              
51 15         21 my $sub = $c[3];
52 15 100       36 if ($sub ne '(eval)') {
53 14         977 $raw->{lexicals} = peek_my($walker++);
54             }
55              
56 15 50 33     74 next if $filter && !$filter->($raw);
57              
58 15 100       492 unless ( $self->{unsafe_ref_capture} ) {
59 11 50       467 $raw->{args} = [ map { ref $_ ? $self->_ref_to_string($_) : $_ }
  4         10  
60 4         6 @{ $raw->{args} } ];
61 4         6 for (values %{ $raw->{lexicals} }) {
  4         15  
62 6 100       48 $_ = $$_ if ref($_) eq 'REF';
63 6         18 $_ = $self->_ref_to_string($_);
64             }
65             }
66              
67 15         26 push @{ $self->{raw} }, $raw;
  15         55  
68             }
69             }
70              
71 15     15   104 sub _frame_class { "Devel::StackTrace::WithLexicals::Frame" }
72              
73             sub _make_frames {
74 8     8   192 my $self = shift;
75              
76 8   33     57 my $filter = !$self->{filter_frames_early} && $self->_make_frame_filter();
77              
78 8         257 my $raw = delete $self->{raw};
79 8         476 for my $r ( @{$raw} ) {
  8         22  
80 15 50 33     83 next if $filter && !$filter->($r);
81              
82 15         208 $self->_add_frame( $r->{caller}, $r->{args}, $r->{lexicals} );
83             }
84             }
85              
86             sub _add_frame {
87 15     15   16 my $self = shift;
88 15         12 my $c = shift;
89 15         21 my $p = shift;
90 15         12 my $lexicals = shift;
91              
92             # eval and is_require are only returned when applicable under 5.00503.
93 15 50       33 push @$c, ( undef, undef ) if scalar @$c == 6;
94              
95 15         17 push @{ $self->{frames} },
  15         443  
96             $self->_frame_class->new(
97             $c,
98             $p,
99             $self->{respect_overload},
100             $self->{max_arg_length},
101             $self->{message},
102             $self->{indent},
103             $lexicals,
104             );
105             }
106              
107              
108             1;
109              
110             __END__