Devel::StackTrace::WithLexicals(3pm)

Devel::StackTrace::WithLexicals3pm

Devel::stacktrace + padwalker

Usage

    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();

Overview

Devel::StackTrace is pretty good at generating stack traces.

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

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

Methods

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

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

Simple, really.

Releases

7 releases since Debian 7 (Wheezy); the text changed 3 times.

  1. 7–8
  2. 9
  3. 10–11
  4. 12–13

Author

Shawn M Moore, "[email protected]"

Bugs

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

From libdevel-stacktrace-withlexicals-perl 2.01-4 in Debian 13 (Trixie). Parsed by carta from the page's man source.