This file is indexed.

/usr/share/perl5/Devel/StackTrace/WithLexicals.pm is in libdevel-stacktrace-withlexicals-perl 2.01-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package Devel::StackTrace::WithLexicals;
use strict;
use warnings;
use 5.008001;
use base 'Devel::StackTrace';

use Devel::StackTrace::WithLexicals::Frame;

use PadWalker 'peek_my';

our $VERSION = '2.01';

# mostly copied from Devel::StackTrace 2.00
sub _record_caller_data {
    my $self = shift;

    my $filter = $self->{filter_frames_early} && $self->_make_frame_filter();

    # We exclude this method by starting at least one frame back.
    my $x = 1 + ( $self->{skip_frames} || 0 );

    # PadWalker ignores eval block and eval string, so we have to keep
    # a different frame count for it
    my $walker = 0;
    for my $caller_count (0..$x) {
        my $sub = (caller($caller_count))[3];
        ++$walker unless $sub eq '(eval)';
    }

    while (
        my @c
        = $self->{no_args}
        ? caller( $x++ )
        : do {
            package    # the newline keeps dzil from adding a version here
                DB;
            @DB::args = ();
            caller( $x++ );
        }
        ) {

        my @args;

        @args = $self->{no_args} ? () : @DB::args;

        my $raw = {
            caller => \@c,
            args   => \@args,
        };

        my $sub = $c[3];
        if ($sub ne '(eval)') {
            $raw->{lexicals} = peek_my($walker++);
        }

        next if $filter && !$filter->($raw);

        unless ( $self->{unsafe_ref_capture} ) {
            $raw->{args} = [ map { ref $_ ? $self->_ref_to_string($_) : $_ }
                    @{ $raw->{args} } ];
            for (values %{ $raw->{lexicals} }) {
                $_ = $$_ if ref($_) eq 'REF';
                $_ = $self->_ref_to_string($_);
            }
        }

        push @{ $self->{raw} }, $raw;
    }
}

sub _frame_class { "Devel::StackTrace::WithLexicals::Frame" }

sub _make_frames {
    my $self = shift;

    my $filter = !$self->{filter_frames_early} && $self->_make_frame_filter();

    my $raw = delete $self->{raw};
    for my $r ( @{$raw} ) {
        next if $filter && !$filter->($r);

        $self->_add_frame( $r->{caller}, $r->{args}, $r->{lexicals} );
    }
}

sub _add_frame {
    my $self = shift;
    my $c    = shift;
    my $p    = shift;
    my $lexicals = shift;

    # eval and is_require are only returned when applicable under 5.00503.
    push @$c, ( undef, undef ) if scalar @$c == 6;

    push @{ $self->{frames} },
        $self->_frame_class->new(
        $c,
        $p,
        $self->{respect_overload},
        $self->{max_arg_length},
        $self->{message},
        $self->{indent},
        $lexicals,
        );
}


1;

__END__

=head1 NAME

Devel::StackTrace::WithLexicals - Devel::StackTrace + PadWalker

=head1 SYNOPSIS

    use Devel::StackTrace::WithLexicals;

    sub process_user {
        my $item_count = 20;
        price_items();
        print "$item_count\n";    # prints 21
    }

    sub price_items {
        my $trace = Devel::StackTrace::WithLexicals->new(
            unsafe_ref_capture => 1    # warning: can cause memory leak
        );
        while ( my $frame = $trace->next_frame() ) {
            my $item_count_ref = $frame->lexical('$item_count');
            ${$item_count_ref}++ if ref $item_count_ref eq 'SCALAR';
        }
    }

    process_user();

=head1 DESCRIPTION

L<Devel::StackTrace> is pretty good at generating stack traces.

L<PadWalker> is pretty good at the inspection and modification of your callers'
lexical variables.

L<Devel::StackTrace::WithLexicals> is pretty good at generating stack traces
with all your callers' lexical variables.

=head1 METHODS

All the same as L<Devel::StackTrace>, except that frames (in class
L<Devel::StackTrace::WithLexicals::Frame>) also have a C<lexicals> method. This
returns the same hashref as returned by L<PadWalker>.

Unless the C<unsafe_ref_capture> option to L<Devel::StackTrace> is
used, then each reference is stringified. This can be useful to avoid
leaking memory.

Simple, really.

=head1 AUTHOR

Shawn M Moore, C<sartak@gmail.com>

=head1 BUGS

I had to copy and paste some code from L<Devel::StackTrace> to achieve this
(it's hard to subclass). There may be bugs lingering here.

=head1 COPYRIGHT AND LICENSE

Copyright 2008-2009 Shawn M Moore.

Some portions written by Dave Rolsky, they belong to him.

This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.

=cut