1Devel::StackTrace(3)  User Contributed Perl Documentation Devel::StackTrace(3)
2
3
4

NAME

6       Devel::StackTrace - An object representing a stack trace
7

VERSION

9       version 1.27
10

SYNOPSIS

12         use Devel::StackTrace;
13
14         my $trace = Devel::StackTrace->new;
15
16         print $trace->as_string; # like carp
17
18         # from top (most recent) of stack to bottom.
19         while (my $frame = $trace->next_frame) {
20             print "Has args\n" if $frame->hasargs;
21         }
22
23         # from bottom (least recent) of stack to top.
24         while (my $frame = $trace->prev_frame) {
25             print "Sub: ", $frame->subroutine, "\n";
26         }
27

DESCRIPTION

29       The Devel::StackTrace module contains two classes, Devel::StackTrace
30       and Devel::StackTrace::Frame.  The goal of this object is to
31       encapsulate the information that can found through using the caller()
32       function, as well as providing a simple interface to this data.
33
34       The Devel::StackTrace object contains a set of Devel::StackTrace::Frame
35       objects, one for each level of the stack.  The frames contain all the
36       data available from "caller()".
37
38       This code was created to support my Exception::Class::Base class (part
39       of Exception::Class) but may be useful in other contexts.
40

'TOP' AND 'BOTTOM' OF THE STACK

42       When describing the methods of the trace object, I use the words 'top'
43       and 'bottom'.  In this context, the 'top' frame on the stack is the
44       most recent frame and the 'bottom' is the least recent.
45
46       Here's an example:
47
48         foo();  # bottom frame is here
49
50         sub foo {
51            bar();
52         }
53
54         sub bar {
55            Devel::StackTrace->new;  # top frame is here.
56         }
57

Devel::StackTrace METHODS

59       ·   Devel::StackTrace->new(%named_params)
60
61           Returns a new Devel::StackTrace object.
62
63           Takes the following parameters:
64
65           ·       frame_filter => $sub
66
67                   By default, Devel::StackTrace will include all stack frames
68                   before the call to its its constructor.
69
70                   However, you may want to filter out some frames with more
71                   granularity than 'ignore_package' or 'ignore_class' allow.
72
73                   You can provide a subroutine which is called with the raw
74                   frame data for each frame. This is a hash reference with
75                   two keys, "caller", and "args", both of which are array
76                   references. The "caller" key is the raw data as returned by
77                   Perl's "caller()" function, and the "args" key are the
78                   subroutine arguments found in @DB::args.
79
80                   The filter should return true if the frame should be
81                   included, or false if it should be skipped.
82
83           ·       ignore_package => $package_name OR \@package_names
84
85                   Any frames where the package is one of these packages will
86                   not be on the stack.
87
88           ·       ignore_class => $package_name OR \@package_names
89
90                   Any frames where the package is a subclass of one of these
91                   packages (or is the same package) will not be on the stack.
92
93                   Devel::StackTrace internally adds itself to the
94                   'ignore_package' parameter, meaning that the
95                   Devel::StackTrace package is ALWAYS ignored.  However, if
96                   you create a subclass of Devel::StackTrace it will not be
97                   ignored.
98
99           ·       no_refs => $boolean
100
101                   If this parameter is true, then Devel::StackTrace will not
102                   store references internally when generating stacktrace
103                   frames.  This lets your objects go out of scope.
104
105                   Devel::StackTrace replaces any references with their
106                   stringified representation.
107
108           ·       respect_overload => $boolean
109
110                   By default, Devel::StackTrace will call
111                   "overload::AddrRef()" to get the underlying string
112                   representation of an object, instead of respecting the
113                   object's stringification overloading.  If you would prefer
114                   to see the overloaded representation of objects in stack
115                   traces, then set this parameter to true.
116
117           ·       max_arg_length => $integer
118
119                   By default, Devel::StackTrace will display the entire
120                   argument for each subroutine call. Setting this parameter
121                   causes it to truncate the argument's string representation
122                   if it is longer than this number of characters.
123
124           ·       message => $string
125
126                   By default, Devel::StackTrace will use 'Trace begun' as the
127                   message for the first stack frame when you call
128                   "as_string". You can supply an alternative message using
129                   this option.
130
131           ·       indent => $boolean
132
133                   If this parameter is true, each stack frame after the first
134                   will start with a tab character, just like
135                   "Carp::confess()".
136
137       ·   $trace->next_frame
138
139           Returns the next Devel::StackTrace::Frame object down on the stack.
140           If it hasn't been called before it returns the first frame.  It
141           returns undef when it reaches the bottom of the stack and then
142           resets its pointer so the next call to "next_frame" or "prev_frame"
143           will work properly.
144
145       ·   $trace->prev_frame
146
147           Returns the next Devel::StackTrace::Frame object up on the stack.
148           If it hasn't been called before it returns the last frame.  It
149           returns undef when it reaches the top of the stack and then resets
150           its pointer so pointer so the next call to "next_frame" or
151           "prev_frame" will work properly.
152
153       ·   $trace->reset_pointer
154
155           Resets the pointer so that the next call "next_frame" or
156           "prev_frame" will start at the top or bottom of the stack, as
157           appropriate.
158
159       ·   $trace->frames
160
161           Returns a list of Devel::StackTrace::Frame objects.  The order they
162           are returned is from top (most recent) to bottom.
163
164       ·   $trace->frame ($index)
165
166           Given an index, returns the relevant frame or undef if there is not
167           frame at that index.  The index is exactly like a Perl array.  The
168           first frame is 0 and negative indexes are allowed.
169
170       ·   $trace->frame_count
171
172           Returns the number of frames in the trace object.
173
174       ·   $trace->as_string
175
176           Calls as_string on each frame from top to bottom, producing output
177           quite similar to the Carp module's cluck/confess methods.
178

SUPPORT

180       Please submit bugs to the CPAN RT system at
181       http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel%3A%3AStackTrace or
182       via email at bug-devel-stacktrace@rt.cpan.org.
183

AUTHOR

185       Dave Rolsky <autarch@urth.org>
186
188       This software is Copyright (c) 2011 by Dave Rolsky.
189
190       This is free software, licensed under:
191
192         The Artistic License 2.0 (GPL Compatible)
193
194
195
196perl v5.12.3                      2011-01-16              Devel::StackTrace(3)
Impressum