Subject: | Use #line to give better debugging information |
If the interpreter snags inside one of the generated methods, I get a message like:
Can't call method "id" on an undefined value at (eval 137) line 1.
It would be nice if inside the call to eval, there was a #line comment containing the caller's file name and line number of the use Class::Delegator ( ... ) statement. I've attached a patch for Delegator.pm that does the job.
Cheers,
Sterling
--- Delegator.pm.orig 2005-12-30 09:56:45.000000000 -0600
+++ lib/Class/Delegator.pm 2005-12-30 10:03:09.000000000 -0600
@@ -194,7 +194,7 @@
sub import {
my $class = shift;
- my $caller = caller;
+ my ($caller, $filename, $line) = caller;
while (@_) {
my ($key, $send) = (shift, shift);
_die(qq{Expected "send => <method spec>" but found "$key => $send"})
@@ -219,6 +219,7 @@
}
my @lines = (
+ "#line $line $filename",
'sub { my ($self, @args) = @_;',
'my @ret;',
);
@@ -249,7 +250,8 @@
my $s = shift @$send;
my $m = shift @$as || $s;
no strict 'refs';
- *{"${caller}::$s"} = eval "sub { shift->$to->$m(\@_) }";
+ *{"${caller}::$s"}
+ = eval "#line $line $filename\nsub { shift->$to->$m(\@_) }";
}
}
}