Skip Menu |

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

Report information
The Basics
Id: 16811
Status: resolved
Priority: 0/
Queue: Class-Delegator

People
Owner: Nobody in particular
Requestors: sterling [...] hanenkamp.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.04
Fixed in: 0.05



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(\@_) }"; } } }
From: David Wheeler <david [...] kineticode.com>
Subject: Re: [cpan #16811] Use #line to give better debugging information
Date: Fri, 30 Dec 2005 09:47:02 -0800
To: bug-Class-Delegator [...] rt.cpan.org
RT-Send-Cc:
On Dec 30, 2005, at 8:06 AM, via RT wrote: Show quoted text
> 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.
Hrm, great, thanks! I'm trying to add a test, now. Can you send me an short example that demonstrates the useless line number message? Thanks, David
From: David Wheeler <david [...] kineticode.com>
Subject: Re: [cpan #16811] Use #line to give better debugging information
Date: Fri, 30 Dec 2005 10:29:35 -0800
To: bug-Class-Delegator [...] rt.cpan.org
RT-Send-Cc:
On Dec 30, 2005, at 9:47 AM, David Wheeler via RT wrote: Show quoted text
> Hrm, great, thanks! I'm trying to add a test, now. Can you send me an > short example that demonstrates the useless line number message?
I added this to t/base.t: LINENOS: { package MyTest::LineNos; sub new { bless {} } sub try { die 'Ow' } use Class::Delegator send => 'hey', to => 'try' ; } ok my $try = MyTest::LineNos->new, 'Create new LineNos object'; use Carp; local $SIG{__DIE__} = \&confess; eval { $try->hey }; ok my $err = $@, 'Should Catch exception'; diag $err; my $file = __FILE__; like $err, qr/$file/, 'The exception should have this file name in it'; The diag outputs this error, regardless of whether I have the #line comment in the eval or not: # Ow at t/base.t line 245. # at t/base.t line 245 # MyTest::LineNos::try('MyTest::LineNos=HASH(0x184c9d4)') called at (eval 16) line 3 # Class::Delegator::__ANON__('MyTest::LineNos=HASH(0x184c9d4)') called at t/base.t line 256 # eval {...} called at t/base.t line 256 So I don't think it works. :-( Any ideas? Best, David
never mind, I figured it out. 0.05 is on its way to CPAN now. I also added names to the delegating methods, which is also useful for stack traces.