Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Exception-Class CPAN distribution.

Report information
The Basics
Id: 51493
Status: resolved
Priority: 0/
Queue: Exception-Class

People
Owner: Nobody in particular
Requestors: shay [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.29
Fixed in: (no value)



Subject: Objects in trace() args() are stringified
When a method is called on an object the first argument to the method call is the object, but the argument returned via trace()->frame(1)->args() is a stringified representation of the object. The following program demonstrates the problem: use strict; use warnings; use Exception::Class qw(MyExceptionClass); package MyExceptionClass; sub full_message { my $self = shift; my $method = $self->trace()->frame(1)->subroutine(); my $object = ($self->trace()->frame(1)->args())[0]; my $class = ref $object; return "$method called on $object, an instance of $class"; } package MyClass; sub new { return bless {}, shift } sub boom { MyExceptionClass->throw() } package main; my $obj = MyClass->new(); eval { $obj->boom() }; print $@->as_string(); __END__ That outputs MyClass::boom called on MyClass=HASH(0x1824ac8), an instance of rather than the expected MyClass::boom called on MyClass=HASH(0x1824ac8), an instance of MyClass I believe this is a bug in Exception::Class rather than Devel::StackTrace because the following program using Devel::StackTrace directly works fine: use strict; use warnings; package MyClass; use Devel::StackTrace; sub new { return bless {}, shift } sub trace { my $self = shift; my $trace = Devel::StackTrace->new(); my $method = $trace->frame(1)->subroutine(); my $object = ($trace->frame(1)->args())[0]; my $class = ref $object; print "$method called on $object, an instance of $class"; } package main; my $obj = MyClass->new(); $obj->trace(); __END__ That outputs MyClass::trace called on MyClass=HASH(0x1824ac8), an instance of MyClass as expected.
This isn't a bug. By default, exception objects pass the "no_refs" option to Devel::StackTrace. This intentionally stringifies all references in the argument list. This prevents all sorts of weird memory leaks and delayed object destruction. See the docs for Exception::Class::Base, specifically for the "NoRefs" option. You can disable this on a per-exception class basis if you like. Please don't reply directly to this ticket, or it will be re-opened. Thanks, -dave