perldoc > Devel::StackTrace

πŸ“› NAME

Devel::StackTrace - An object representing a stack trace

πŸš€ Quick Reference

Use CaseCommandDescription
Create a tracemy $trace = Devel::StackTrace->new;Instantiate a new stack trace object
Get full trace as string$trace->as_string;Returns formatted trace like Carp confess
Iterate top to bottomwhile (my $frame = $trace->next_frame) { ... }Walk frames from most recent to oldest
Iterate bottom to topwhile (my $frame = $trace->prev_frame) { ... }Walk frames in reverse order
Filter framesnew( frame_filter => sub { ... } )Provide a subroutine to include/exclude frames
Ignore packagesnew( ignore_package => ['Foo','Bar'] )Exclude frames from specified packages
Skip top framesnew( skip_frames => 2 )Omit the most recent N frames from the trace
Count frames$trace->frame_countReturn total number of captured frames

🏷️ VERSION

version 2.04

πŸ“‹ 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 retrieved via Perl's "caller" function, as well as providing 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".

This code was created to support my Exception::Class::Base class (part of Exception::Class) but may be useful in other contexts.

πŸ”½ '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.

Here's an example:

foo();  # bottom frame is here

sub foo {
   bar();
}

sub bar {
   Devel::StackTrace->new;  # top frame is here.
}

πŸ“¦ METHODS

This class provide the following methods:

πŸ”§ Devel::StackTrace->new(%named_params)

Returns a new Devel::StackTrace object.

Takes the following parameters:

πŸ”½ $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.

πŸ“‹ $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.

πŸ”’ $trace->frame_count

Returns the number of frames in the trace object.

πŸ“ $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".

πŸ’¬ $trace->message

Returns the message passed to the constructor. If this wasn't passed then this method returns "undef".

πŸ†˜ SUPPORT

Bugs may be submitted at <https://github.com/houseabsolute/Devel-StackTrace/issues>.

I am also usually active on IRC as 'autarch' on "irc://irc.perl.org".

πŸ“‚ SOURCE

The source code repository for Devel-StackTrace can be found at <https://github.com/houseabsolute/Devel-StackTrace>.

πŸ’° 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 AT urth.org, or use the button at <http://www.urth.org/~autarch/fs-donation.html>.

πŸ‘€ AUTHOR

Dave Rolsky <autarch AT urth.org>

🀝 CONTRIBUTORS

βš–οΈ COPYRIGHT AND LICENSE

This software is Copyright (c) 2000 - 2019 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.

Devel::StackTrace
πŸ“› NAME πŸš€ Quick Reference 🏷️ VERSION πŸ“‹ SYNOPSIS πŸ“– DESCRIPTION
πŸ”½ 'TOP' AND 'BOTTOM' OF THE STACK
πŸ“¦ METHODS
πŸ”§ Devel::StackTrace->new(%named_params) πŸ”½ $trace->next_frame πŸ”Ό $trace->prev_frame πŸ”„ $trace->reset_pointer πŸ“‹ $trace->frames πŸ”’ $trace->frame($index) πŸ”’ $trace->frame_count πŸ“ $trace->as_string(\%p) πŸ’¬ $trace->message
πŸ†˜ SUPPORT πŸ“‚ SOURCE πŸ’° DONATIONS πŸ‘€ AUTHOR 🀝 CONTRIBUTORS βš–οΈ COPYRIGHT AND LICENSE

Generated by phpman v4.9.26-5-g7740029 · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-08-13 01:18 @216.73.217.60
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!

^_top_^