6 use overload '""' => \&to_string;
10 # use Moose; ## Haha, if only.
13 sub message { shift->{message}; }
14 sub stacktrace { shift->{stacktrace}; }
16 # Builder for stacktrace
17 sub _build_stacktrace {
18 shift->{stacktrace} = Devel::StackTrace->new(ignore_class => __PACKAGE__);
26 while (my $frame = $self->{stacktrace}->next_frame) {
29 # message at foo.pl line 1
30 push @lines, sprintf("%s at %s line %s", $self->message, $frame->filename, $frame->line);
32 my @args = map { ref $_ ? "$_" : "'$_'" } $frame->args;
33 # main::foo called at foo.pl line 1
34 push @lines, sprintf("\t%s(%s) called at %s line %s", $frame->subroutine, join(", ", @args), $frame->filename, $frame->line);
42 my ($class, %kwargs) = @_;
43 $class = ref $class if ref $class; # Also take another exception object, if we must.
44 my $message = $kwargs{message} || ''; # Default to no error message
47 my $self = bless {message => $message}, $class;
48 $self->_build_stacktrace;