Re: patch to DT::F::Builder

2004-02-01 Thread Yitzchak Scott-Thoennes
On Thu, Jan 29, 2004 at 04:41:41PM -0800, Daisuke Maki [EMAIL PROTECTED] wrote:
 
 It was really annoying me that parsers based on DT::F::Builder would by
 default report a parse failure as being in DT::F::B::Parser.
 
 I'd like the error message to tell me where in the calling script it
 failed, so I'd like to introduce this patch.
 
 Index: lib/DateTime/Format/Builder.pm
 ===
 RCS file:
 /cvsroot/perl-date-time/modules/DateTime-Format-Builder/lib/DateTime/F
 ormat/Builder.pm,v
 retrieving revision 1.35
 diff -d -u -r1.35 Builder.pm
 --- lib/DateTime/Format/Builder.pm  26 Jan 2004 18:46:45 -  1.35
 +++ lib/DateTime/Format/Builder.pm  30 Jan 2004 00:37:34 -
 @@ -200,6 +200,13 @@
  sub on_fail
  {
  my ($class, $input) = @_;
 +
 +my $i = 0;
 +while (my ($pkg) = caller($i++)) {
 +last if ($pkg ne 'DateTime::Format::Builder' 
 +$pkg !~ /^DateTime::Format::Builder::Parser/);
 +}
 +local $Carp::CarpLevel = $i;
  croak Invalid date format: $input;
  }
 

CarpLevel is (at least semi-) deprecated.  Consider using @CARP_NOT.


Re: patch to DT::F::Builder

2004-02-01 Thread Yitzchak Scott-Thoennes
On Fri, Jan 30, 2004 at 12:18:51AM -0600, Dave Rolsky [EMAIL PROTECTED] wrote:
 On Thu, 29 Jan 2004, Daisuke Maki wrote:
 
   Can't this be done with the @CARP_NOT variable?
 
  Hmmm, I was trying to do this:
 
 sub on_fail {
my($class, $input) = @_;
local @Carp::CARP_NOT = qw( PKGS ... );
croak $input;
 }
 
  But somehow the messages where unaltered, so now I look at Carp.pm from
  my perl 5.8.3, and I see the following:
 
 sub shortmess { # Short-circuit longmess if called via multiple packages
   { local $@; require Carp::Heavy; }  # XXX fix require to not clear [EMAIL 
  PROTECTED]
   # Icky backwards compatibility wrapper. :-(
   my $call_pack = caller();
   local @CARP_NOT = caller(); #  RIGHT HERE
   shortmess_heavy(@_);
 }
 
  Hmph. local @CARP_NOT = caller()?
  It's overriding @CARP_NOT regardless of what the caller has done...?
 
  Dave, mind if I just fall back to what I initially proposed?
 
 Sure, that's fine.  Looks like Carp is a bit broken.

That bit sets @Carp::CARP_NOT.  In your code you should be setting
@Your::Module::CARP_NOT.  It's intended to be set just once, like
@ISA, not just before calling carp.