Devel::StackTrace(3)
π Devel::StackTrace π
okay bestie, welcome to the Devel::StackTrace(3) manual page from the User Contributed Perl Documentation crew π this one is all about making stack traces make sense, and yes, it's giving iconic debugging energy.
π NAME π
Devel::StackTrace β An object representing a stack trace. Literally the whole vibe in one line. β¨
πΈ VERSION πΈ
version 2.05 β that's the version, bestie, no cap. π
π¦ SYNOPSIS π¦
use Devel::StackTrace;
my $trace = Devel::StackTrace->new;
print $trace->as_string; # like carp
# from top (most recent) of stack to bottom.
while ( my $frame = $trace->next_frame ) {
print "Has args\n" if $frame->hasargs;
}
# from bottom (least recent) of stack to top.
while ( my $frame = $trace->prev_frame ) {
print "Sub: ", $frame->subroutine, "\n";
}
π DESCRIPTION π
The Devel::StackTrace module contains two classes, Devel::StackTrace and Devel::StackTrace::Frame. These objects encapsulate the information that can be retrieved via Perl's caller function, and they give you a simple interface to this data. π
The Devel::StackTrace object contains a set of Devel::StackTrace::Frame objects, one for each level of the stack. The frames contain all the data available from caller. Obsessed with the completeness, honestly. π«Ά
This code was created to support my Exception::Class::Base class (part of Exception::Class) but may be useful in other contexts. Cute, useful, and not just for one thing β we love to see it. πΈ
π§ 'TOP' AND 'BOTTOM' OF THE STACK π§
When describing the methods of the trace object, I use the words 'top' and 'bottom'. In this context, the 'top' frame on the stack is the most recent frame and the 'bottom' is the least recent. Main character energy is at the top, bestie. π
Here's an example:
foo(); # bottom frame is here
sub foo {
bar();
}
sub bar {
Devel::StackTrace->new; # top frame is here.
}
π οΈ METHODS π οΈ
This class provides the following methods:
π Devel::StackTrace->new(%named_params)
Returns a new Devel::StackTrace object.
Takes the following parameters:
frame_filter => $subβ By default, Devel::StackTrace will include all stack frames before the call to its constructor. However, you may want to filter out some frames with more granularity than'ignore_package'or'ignore_class'allow. You can provide a subroutine which is called with the raw frame data for each frame. This is a hash reference with two keys,caller, andargs, both of which are array references. Thecallerkey is the raw data as returned by Perl'scallerfunction, and theargskey are the subroutine arguments found in@DB::args. The filter should return true if the frame should be included, or false if it should be skipped. πfilter_frames_early => $booleanβ If this parameter is true,frame_filterwill be called as soon as the stacktrace is created, and before refs are stringified (ifunsafe_ref_captureis not set), rather than being filtered lazily when Devel::StackTrace::Frame objects are first needed. This is useful if you want to filter based on the frame's arguments and want to be able to examine object properties, for example. β¨ignore_package => $package_name OR \@package_namesβ Any frames where the package is one of these packages will not be on the stack. Bye, frames. πignore_class => $package_name OR \@package_namesβ Any frames where the package is a subclass of one of these packages (or is the same package) will not be on the stack. Devel::StackTrace internally adds itself to the'ignore_package'parameter, meaning that the Devel::StackTrace package is ALWAYS ignored. However, if you create a subclass of Devel::StackTrace it will not be ignored. Rules are rules, but subclasses get a little loophole. πskip_frames => $integerβ This will cause this number of stack frames to be excluded from top of the stack trace. This prevents the frames from being captured at all, and applies before theframe_filter,ignore_package, orignore_classoptions, even withfilter_frames_early. It's giving "you don't even get captured," honestly. π«Άunsafe_ref_capture => $booleanβ If this parameter is true, then Devel::StackTrace will store references internally when generating stacktrace frames. This option is very dangerous, and should never be used with exception objects. Using this option will keep any objects or references alive past their normal lifetime, until the stack trace object goes out of scope. It can keep objects alive even after theirDESTROYsub is called, resulting in it being called multiple times on the same object. If not set, Devel::StackTrace replaces any references with their stringified representation. β οΈ bestie, this is the "do not touch the stove" option. Like fr fr dangerous. π₯no_args => $booleanβ If this parameter is true, then Devel::StackTrace will not store caller arguments in stack trace frames at all. Privacy era. πrespect_overload => $booleanβ By default, Devel::StackTrace will calloverload::AddrRefto get the underlying string representation of an object, instead of respecting the object's stringification overloading. If you would prefer to see the overloaded representation of objects in stack traces, then set this parameter to true. πmax_arg_length => $integerβ By default, Devel::StackTrace will display the entire argument for each subroutine call. Setting this parameter truncates each subroutine argument's string representation if it is longer than this number of characters. Cutting long arguments down to size, slay. βοΈmessage => $stringβ By default, Devel::StackTrace will use'Trace begun'as the message for the first stack frame when you callas_string. You can supply an alternative message using this option. πindent => $booleanβ If this parameter is true, each stack frame after the first will start with a tab character, just likeCarp::confess. Cute little tab, doing its thing. π
π« $trace->next_frame
Returns the next Devel::StackTrace::Frame object on the stack, going down. If this method hasn't been called before it returns the first frame. It returns undef when it reaches the bottom of the stack and then resets its pointer so the next call to $trace->next_frame or $trace->prev_frame will work properly. π¦
π¦ $trace->prev_frame
Returns the next Devel::StackTrace::Frame object on the stack, going up. If this method hasn't been called before it returns the last frame. It returns undef when it reaches the top of the stack and then resets its pointer so the next call to $trace->next_frame or $trace->prev_frame will work properly. π«
π― $trace->reset_pointer
Resets the pointer so that the next call to $trace->next_frame or $trace->prev_frame will start at the top or bottom of the stack, as appropriate. Fresh start, bestie. β¨
π§ $trace->frames
When this method is called with no arguments, it returns a list of Devel::StackTrace::Frame objects. They are returned in order from top (most recent) to bottom.
This method can also be used to set the object's frames if you pass it a list of Devel::StackTrace::Frame objects.
This is useful if you want to filter the list of frames in ways that are more complex than can be handled by the $trace->filter_frames method:
$stacktrace->frames( my_filter( $stacktrace->frames ) );
π’ $trace->frame($index)
Given an index, this method returns the relevant frame, or undef if there is no frame at that index. The index is exactly like a Perl array. The first frame is 0 and negative indexes are allowed. Array vibes, but make it frames. π
β $trace->frame_count
Returns the number of frames in the trace object. Literally just the count, bestie. π
π
$trace->as_string(\%p)
Calls $frame->as_string on each frame from top to bottom, producing output quite similar to the Carp module's cluck/confess methods.
The optional \%p parameter only has one option. The max_arg_length parameter truncates each subroutine argument's string representation if it is longer than this number of characters.
If all the frames in a trace are skipped then this just returns the message passed to the constructor or the string Trace begun. So even when the stack is quiet, you still get a little something. π
π $trace->message
Returns the message passed to the constructor. If this wasn't passed then this method returns undef. Short, sweet, to the point. πΈ
π«Ά SUPPORT π«Ά
Bugs may be submitted at https://github.com/houseabsolute/Devel-StackTrace/issues. Be chill and helpful, bestie. β¨
π SOURCE π
The source code repository for Devel-StackTrace can be found at https://github.com/houseabsolute/Devel-StackTrace. Go look, it's giving open source excellence. π
πΈ DONATIONS πΈ
If you'd like to thank me for the work I've done on this module, please consider making a "donation" to me via PayPal. I spend a lot of free time creating free software, and would appreciate any support you'd care to offer. π₯Ί
Please note that I am not suggesting that you must do this in order for me to continue working on this particular software. I will continue to do so, inasmuch as I have in the past, for as long as it interests me.
Similarly, a donation made in this way will probably not make me work on this software much more, unless I get so many donations that I can consider working on free software full time (let's all have a chuckle at that together). π
To donate, log into PayPal and send money to autarch@urth.org, or use the button at https://houseabsolute.com/foss-donations/. πΈ
π AUTHOR π
Dave Rolsky autarch@urth.org β absolute icon. π
π§ CONTRIBUTORS π§
- Dagfinn Ilmari MannsΓ₯ker
ilmari@ilmari.org - David Cantrell
david@cantrell.org.uk - Graham Knop
haarg@haarg.org - Ivan Bessarabov
ivan@bessarabov.ru - Mark Fowler
mark@twoshortplanks.com - Pali
pali@cpan.org - Ricardo Signes
rjbs@cpan.org
π COPYRIGHT AND LICENSE π
This software is Copyright (c) 2000 - 2024 by David Rolsky.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
The full text of the license can be found in the LICENSE file included with this distribution. π
okay that's the whole page, bestie! π
this footer energy came from perl v5.42.0, dated 2024-03-08, and it's the Devel::StackTrace(3) man page β mwah! ππ
π¦ where this page comes from
- opensuse-leap 16.0: perl-Devel-StackTrace 2.50.0-160000.2.2 Β· Artistic-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms