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() as of Perl 5.6.0 though this module still
36 works with 5.00503.
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
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 {
52 bar();
53 }
54
55 sub bar
56 {
57 Devel::StackTrace->new; # top frame is here.
58 }
59
61 * Devel::StackTrace->new(%named_params)
62 Returns a new Devel::StackTrace object.
63
64 Takes the following parameters:
65
66 * ignore_package => $package_name OR \@package_names
67 Any frames where the package is one of these packages will
68 not be on the stack.
69
70 * ignore_class => $package_name OR \@package_names
71 Any frames where the package is a subclass of one of these
72 packages (or is the same package) will not be on the stack.
73
74 Devel::StackTrace internally adds itself to the
75 'ignore_package' parameter, meaning that the Devel::Stack‐
76 Trace package is ALWAYS ignored. However, if you create a
77 subclass of Devel::StackTrace it will not be ignored.
78
79 * no_refs => $boolean
80 If this parameter is true, then Devel::StackTrace will not
81 store references internally when generating stacktrace
82 frames. This lets your objects go out of scope.
83
84 Devel::StackTrace replaces any references with their
85 stringified representation.
86
87 * respect_overload => $boolean
88 By default, Devel::StackTrace will call "overload::Str‐
89 Val()" to get the underlying string representation of an
90 object, instead of respecting the object's stringification
91 overloading. If you would prefer to see the overloaded
92 representation of objects in stack traces, then set this
93 parameter to true.
94
95 * $trace->next_frame
96 Returns the next Devel::StackTraceFrame object down on the stack.
97 If it hasn't been called before it returns the first frame. It
98 returns undef when it reaches the bottom of the stack and then
99 resets its pointer so the next call to "next_frame" or "prev_frame"
100 will work properly.
101
102 * $trace->prev_frame
103 Returns the next Devel::StackTraceFrame object up on the stack. If
104 it hasn't been called before it returns the last frame. It returns
105 undef when it reaches the top of the stack and then resets its
106 pointer so pointer so the next call to "next_frame" or "prev_frame"
107 will work properly.
108
109 * $trace->reset_pointer
110 Resets the pointer so that the next call "next_frame" or
111 "prev_frame" will start at the top or bottom of the stack, as
112 appropriate.
113
114 * $trace->frames
115 Returns a list of Devel::StackTraceFrame objects. The order they
116 are returned is from top (most recent) to bottom.
117
118 * $trace->frame ($index)
119 Given an index, returns the relevant frame or undef if there is not
120 frame at that index. The index is exactly like a Perl array. The
121 first frame is 0 and negative indexes are allowed.
122
123 * $trace->frame_count
124 Returns the number of frames in the trace object.
125
126 * $trace->as_string
127 Calls as_string on each frame from top to bottom, producing output
128 quite similar to the Carp module's cluck/confess methods.
129
131 See the caller documentation for more information on what these methods
132 return.
133
134 * $frame->package
135 * $frame->filename
136 * $frame->line
137 * $frame->subroutine
138 * $frame->hasargs
139 * $frame->wantarray
140 * $frame->evaltext
141 Returns undef if the frame was not part of an eval.
142
143 * $frame->is_require
144 Returns undef if the frame was not part of a require.
145
146 * $frame->args
147 Returns the arguments passed to the frame. Note that any arguments
148 that are references are returned as references, not copies.
149
150 These only contain data as of Perl 5.6.0 or later
151
152 * $frame->hints
153 * $frame->bitmask
154
156 Please submit bugs to the CPAN RT system at
157 http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Devel%3A%3AStackTrace or
158 via email at bug-devel-stacktrace@rt.cpan.org.
159
161 Dave Rolsky, <autarch@urth.org>
162
164 Copyright (c) 2000-2006 David Rolsky. All rights reserved. This pro‐
165 gram is free software; you can redistribute it and/or modify it under
166 the same terms as Perl itself.
167
168 The full text of the license can be found in the LICENSE file included
169 with this module.
170
171
172
173perl v5.8.8 2007-04-28 Devel::StackTrace(3)