develooper Front page | perl.perl5.porters | Postings from August 2001

Re: [ID 20010826.005] Carp fails for overloaded object

Thread Previous | Thread Next
From:
Michael G Schwern
Date:
August 26, 2001 19:47
Subject:
Re: [ID 20010826.005] Carp fails for overloaded object
Message ID:
20010826224742.H579@blackrider
On Sun, Aug 26, 2001 at 07:09:42PM -0000, mjd@plover.com wrote:
> I have identified a minor bug in Carp::Heavy.pm.
> 
> If a class has overloaded the "" operator and it also uses Carp then
> when calling carp/croak the object reference will be stringified by
> carp.  This also can lead to deep recursion if the stringify routine
> also calls cluck/confess.

Looks like this has already been fixed in bleadperl.

# Transform an argument to a function into a string.
sub format_arg {
  my $arg = shift;
  if (not defined($arg)) {
    $arg = 'undef';
  }
  elsif (ref($arg)) {
      $arg = defined($overload::VERSION) ? overload::StrVal($arg) : "$arg";
  }
  $arg =~ s/'/\\'/g;
  $arg = str_len_trim($arg, $MaxLenArg);
  
  # Quote it?
  $arg = "'$arg'" unless $arg =~ /^-?[\d.]+\z/;

  # The following handling of "control chars" is direct from
  # the original code - I think it is broken on Unicode though.
  # Suggestions?
  $arg =~ s/([[:cntrl:]]|[[:^ascii:]])/sprintf("\\x{%x}",ord($1))/eg;
  return $arg;
}


> Obviously the problem is in line 90 of Carp\Heavy.pm (Neither Carp.pm
> or Carp\Heavy.pm have version numbers so thats all I can say)

That's been fixed, too. :)


> As a second point, I have often wondered why there arent published
> interfaces into Carp.pm so that we dont have to die/warn their
> results, but perhaps use them in some other way.

So's this.  shortmess and longmess are now published.


> I suppose that Carp::shortmess and Carp::longmess is ok, but I
> thought that perhaps 'chirp' and 'confide' might fit in with the 'c'
> word motif :-) chirp/carp/croak confide/cluck/confess better.

There was already an argument over the names a while back.  A bunch
were suggested, and even a patch put forth.  Noone could agree.  So it
looks like we're stuck with longmess() and shortmess() unless someone
wants to make an executive decision.

http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2001-06/msg01520.html


-- 

Michael G. Schwern   <schwern@pobox.com>    http://www.pobox.com/~schwern/
Perl6 Quality Assurance     <perl-qa@perl.org>	     Kwalitee Is Job One
If you have to shoot, shoot!  Don't talk.
		-- Tuco, "The Good, The Bad And The Ugly"

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About