1 package StackTrace::Auto;
3 # ABSTRACT: a role for generating stack traces during instantiation
7 First, include StackTrace::Auto in a Moose class...
11 with 'StackTrace::Auto';
13 ...then create an object of that class...
15 my $obj = Some::Class->new;
17 ...and now you have a stack trace for the object's creation.
19 print $obj->stack_trace->as_string;
23 This attribute will contain an object representing the stack at the point when
24 the error was generated and thrown. It must be an object performing the
27 =attr stack_trace_class
29 This attribute may be provided to use an alternate class for stack traces. The
30 default is L<Devel::StackTrace|Devel::StackTrace>.
32 In general, you will not need to think about this attribute.
37 use Moose::Util::TypeConstraints;
41 isa => duck_type([ qw(as_string) ]),
42 builder => '_build_stack_trace',
46 my $tc = subtype as 'ClassName';
47 coerce $tc, from 'Str', via { Class::MOP::load_class($_); $_ };
49 has stack_trace_class => (
54 builder => '_build_stack_trace_class',
57 no Moose::Util::TypeConstraints;
60 =attr stack_trace_args
62 This attribute is an arrayref of arguments to pass when building the stack
63 trace. In general, you will not need to think about it.
67 has stack_trace_args => (
71 builder => '_build_stack_trace_args',
74 sub _build_stack_trace_class {
75 return 'Devel::StackTrace';
78 sub _build_stack_trace_args {
81 my $uplevel = 3; # number of *raw* frames to go up after we found the marker
86 return 1 unless $uplevel;
90 $found_mark = scalar $raw->{caller}->[3] =~ /__stack_marker$/;
97 sub _build_stack_trace {
99 return $self->stack_trace_class->new(
100 @{ $self->stack_trace_args },
107 return $self->__stack_marker($next, @_);
113 return $self->$next(@_);