Devel::StackTrace - Stack trace and stack trace frame objects


Devel::StackTrace - Stack trace and stack trace frame objects


  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";


The Devel::StackTrace module contains two classes, Devel::StackTrace and Devel::StackTraceFrame. The goal of this object is to encapsulate the information that can found through using the caller() function, as well as providing a simple interface to this data.

The Devel::StackTrace object contains a set of Devel::StackTraceFrame objects, one for each level of the stack. The frames contain all the data available from caller() as of Perl 5.6.0 though this module still works with 5.00503.

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


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
  sub bar
     Devel::StackTrace->new;  # top frame is here.

Devel::StackTrace METHODS

Devel::StackTraceFrame METHODS

See the caller documentation for more information on what these methods return.

These only contain data as of Perl 5.6.0 or later


Please submit bugs to the CPAN RT system at or via email at


Dave Rolsky, <>


Copyright (c) 2000-2006 David Rolsky. All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.

 Devel::StackTrace - Stack trace and stack trace frame objects