1Devel::StackTrace(3) User Contributed Perl Documentation Devel::StackTrace(3)
2
3
4
6 Devel::StackTrace - Stack trace and stack trace frame objects
7
9 use Devel::StackTrace;
10
11 my $trace = Devel::StackTrace->new;
12
13 print $trace->as_string; # like carp
14
15 # from top (most recent) of stack to bottom.
16 while (my $frame = $trace->next_frame)
17 {
18 print "Has args\n" if $frame->hasargs;
19 }
20
21 # from bottom (least recent) of stack to top.
22 while (my $frame = $trace->prev_frame)
23 {
24 print "Sub: ", $frame->subroutine, "\n";
25 }
26
28 The Devel::StackTrace module contains two classes, Devel::StackTrace
29 and Devel::StackTraceFrame. The goal of this object is to encapsulate
30 the information that can found through using the caller() function, as
31 well as providing a simple interface to this data.
32
33 The Devel::StackTrace object contains a set of Devel::StackTraceFrame
34 objects, one for each level of the stack. The frames contain all the
35 data available from "caller()".
36
37 This code was created to support my Exception::Class::Base class (part
38 of Exception::Class) but may be useful in other contexts.
39
41 When describing the methods of the trace object, I use the words 'top'
42 and 'bottom'. In this context, the 'top' frame on the stack is the
43 most recent frame and the 'bottom' is the least recent.
44
45 Here's an example:
46
47 foo(); # bottom frame is here
48
49 sub foo
50 {
51 bar();
52 }
53
54 sub bar
55 {
56 Devel::StackTrace->new; # top frame is here.
57 }
58
60 · Devel::StackTrace->new(%named_params)
61
62 Returns a new Devel::StackTrace object.
63
64 Takes the following parameters:
65
66 · frame_filter => $sub
67
68 By default, Devel::StackTrace will include all stack frames
69 before the call to its its constructor.
70
71 However, you may want to filter out some frames with more
72 granularity than 'ignore_package' or 'ignore_class' allow.
73
74 You can provide a subroutine which is called with the raw
75 frame data for each frame. This is a hash reference with
76 two keys, "caller", and "args", both of which are array
77 references. The "caller" key is the raw data as returned by
78 Perl's "caller()" function, and the "args" key are the
79 subroutine arguments found in @DB::args.
80
81 The filter should return true if the frame should be
82 included, or false if it should be skipped.
83
84 · ignore_package => $package_name OR \@package_names
85
86 Any frames where the package is one of these packages will
87 not be on the stack.
88
89 · ignore_class => $package_name OR \@package_names
90
91 Any frames where the package is a subclass of one of these
92 packages (or is the same package) will not be on the stack.
93
94 Devel::StackTrace internally adds itself to the
95 'ignore_package' parameter, meaning that the
96 Devel::StackTrace package is ALWAYS ignored. However, if
97 you create a subclass of Devel::StackTrace it will not be
98 ignored.
99
100 · no_refs => $boolean
101
102 If this parameter is true, then Devel::StackTrace will not
103 store references internally when generating stacktrace
104 frames. This lets your objects go out of scope.
105
106 Devel::StackTrace replaces any references with their
107 stringified representation.
108
109 · respect_overload => $boolean
110
111 By default, Devel::StackTrace will call
112 "overload::AddrRef()" to get the underlying string
113 representation of an object, instead of respecting the
114 object's stringification overloading. If you would prefer
115 to see the overloaded representation of objects in stack
116 traces, then set this parameter to true.
117
118 · max_arg_length => $integer
119
120 By default, Devel::StackTrace will display the entire
121 argument for each subroutine call. Setting this parameter
122 causes it to truncate the argument's string representation
123 if it is longer than this number of characters.
124
125 · $trace->next_frame
126
127 Returns the next Devel::StackTraceFrame object down on the stack.
128 If it hasn't been called before it returns the first frame. It
129 returns undef when it reaches the bottom of the stack and then
130 resets its pointer so the next call to "next_frame" or "prev_frame"
131 will work properly.
132
133 · $trace->prev_frame
134
135 Returns the next Devel::StackTraceFrame object up on the stack. If
136 it hasn't been called before it returns the last frame. It returns
137 undef when it reaches the top of the stack and then resets its
138 pointer so pointer so the next call to "next_frame" or "prev_frame"
139 will work properly.
140
141 · $trace->reset_pointer
142
143 Resets the pointer so that the next call "next_frame" or
144 "prev_frame" will start at the top or bottom of the stack, as
145 appropriate.
146
147 · $trace->frames
148
149 Returns a list of Devel::StackTraceFrame objects. The order they
150 are returned is from top (most recent) to bottom.
151
152 · $trace->frame ($index)
153
154 Given an index, returns the relevant frame or undef if there is not
155 frame at that index. The index is exactly like a Perl array. The
156 first frame is 0 and negative indexes are allowed.
157
158 · $trace->frame_count
159
160 Returns the number of frames in the trace object.
161
162 · $trace->as_string
163
164 Calls as_string on each frame from top to bottom, producing output
165 quite similar to the Carp module's cluck/confess methods.
166
168 See the caller documentation for more information on what these methods
169 return.
170
171 · $frame->package
172
173 · $frame->filename
174
175 · $frame->line
176
177 · $frame->subroutine
178
179 · $frame->hasargs
180
181 · $frame->wantarray
182
183 · $frame->evaltext
184
185 Returns undef if the frame was not part of an eval.
186
187 · $frame->is_require
188
189 Returns undef if the frame was not part of a require.
190
191 · $frame->args
192
193 Returns the arguments passed to the frame. Note that any arguments
194 that are references are returned as references, not copies.
195
196 · $frame->hints
197
198 · $frame->bitmask
199
201 Please submit bugs to the CPAN RT system at
202 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel%3A%3AStackTrace or
203 via email at bug-devel-stacktrace@rt.cpan.org.
204
206 Dave Rolsky, <autarch@urth.org>
207
209 Copyright (c) 2000-2006 David Rolsky. All rights reserved. This
210 program is free software; you can redistribute it and/or modify it
211 under the same terms as Perl itself.
212
213 The full text of the license can be found in the LICENSE file included
214 with this module.
215
216
217
218perl v5.10.1 2009-07-15 Devel::StackTrace(3)