Devel:...exicals(3pm)

✨ NAME ✨

Devel::StackTrace::WithLexicals β€” it's literally Devel::StackTrace plus PadWalker, bestie πŸ’–


πŸŽ€ 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();

(yes she really does print 21, and yes that's the whole point 😌)


πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so. Story time. 🌸

Devel::StackTrace is pretty good at generating stack traces. Iconic. No notes.

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

Devel::StackTrace::WithLexicals is pretty good at generating stack traces with all your callers' lexical variables. It's giving collab of the century, fr fr. Two icons, one module. πŸ‘‘


πŸ’… METHODS πŸ’…

Every single method is the same as Devel::StackTrace β€” literally all of them, no cap. EXCEPT that frames (in class Devel::StackTrace::WithLexicals::Frame, iykyk) also have a lexicals method. ✨

That lexicals method returns the same hashref as returned by PadWalker. Same one. Identical.

BUT β€” and listen closely bestie β€” unless the unsafe_ref_capture option to Devel::StackTrace is used, then each reference is stringified. That can be useful to avoid leaking memory. 🫢

Simple, really. πŸ’β™€οΈ


πŸ‘‘ AUTHOR πŸ‘‘

Shawn M Moore, sartak@gmail.com


πŸ’€ BUGS πŸ’€

Not me having to copy and paste some code from Devel::StackTrace to achieve this 😭 (it's hard to subclass, okay??). There may be bugs lingering here. πŸ™ˆ

Lowkey a warning. Highkey also a confession.

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.


perl v5.36.0, dated 2022-10-14, page Devel:...exicals(3pm) β€” that's the whole vibe check, bestie, slay, periodt, go write some stack traces with lexicals πŸ’œπŸ¦‹βœ¨

πŸ“¦ where this page comes from