Skip to content

Commit

Permalink
Use the object names in traces
Browse files Browse the repository at this point in the history
  • Loading branch information
gisle committed Jan 2, 2009
1 parent 293c0b7 commit f63a7d6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions lib/Data/Dump/Trace.pm
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ our @EXPORT_OK = qw(call mcall wrap);
use Data::Dump qw(dump);
use Term::ANSIColor qw(YELLOW CYAN RESET);
use Carp qw(croak);
use overload ();

my %obj_name;

Expand All @@ -33,8 +34,13 @@ sub wrap {
call($name, $func, @_);
} if $func;

my $obj = $arg{obj};
return bless { name => $name, obj => $obj }, "Data::Dump::Trace::Wrapper" if $obj;
if (my $obj = $arg{obj}) {
$obj_name{overload::StrVal($obj)} = $name;
return bless {
name => $name,
obj => $obj,
}, "Data::Dump::Trace::Wrapper";
}

croak("Either the 'func' or 'obj' option must be given");
}
Expand Down Expand Up @@ -62,7 +68,7 @@ sub call {
sub mcall {
my $o = shift;
my $method = shift;
my $oname = ref($o) ? "\$o" : $o;
my $oname = ref($o) ? $obj_name{overload::StrVal($o)} || "\$o" : $o;
print YELLOW, $oname, "->", $method, dumpav(@_), RESET;
if (!defined wantarray) {
print "\n";
Expand Down

0 comments on commit f63a7d6

Please sign in to comment.