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

Re: [ID 20010826.005] Carp fails for overloaded object

Thread Previous | Thread Next
Michael G Schwern
August 26, 2001 19:47
Re: [ID 20010826.005] Carp fails for overloaded object
Message ID:
On Sun, Aug 26, 2001 at 07:09:42PM -0000, wrote:
> I have identified a minor bug in
> 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\ (Neither
> or Carp\ 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 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.


Michael G. Schwern   <>
Perl6 Quality Assurance     <>	     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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About