develooper Front page | perl.perl5.porters | Postings from April 2003

[PATCH 5.8.0 LIB] Carp does not always correctly honour trailing newlines

Thread Next
From:
Steve Hay
Date:
April 28, 2003 01:12
Subject:
[PATCH 5.8.0 LIB] Carp does not always correctly honour trailing newlines
Message ID:
3EACE277.4060101@uk.radan.com
The attached patch fixes a bug in the Carp module regarding the 
interpretation of trailing newlines in strings passed to carp() and croak().

These functions are supposed to behave the same way as warn() and die() 
in this regard, namely, that if the string passed to them ends with a 
newline then " at <file> line <line>." should not be appended.

This suppression does not work properly when carp() or croak() is called 
from another package/file than main.  To see this, put the following 
code into two files, test.pl and Foo.pm, respectively:

test.pl
-------
use Carp;
use Foo;
print "From main::\n";
warn("warn\n");
carp("carp\n");
print "From Foo::\n";
Foo::foo();

Foo.pm
------
package Foo;
use Carp;
sub foo {
    warn("warn\n");
    carp("carp\n");
}
1;

Now when you run test.pl the output is:

 From main::
warn
carp
 From Foo::
warn
carp
 at test.pl line 7

The last line here is wrong: " at test.pl line 7" should have been 
suppressed.

The patch fixes this by applying the same trailing newline test in 
ret_summary() as is applied already in ret_backtrace().  (I've also 
deleted an unused lexical variable.)

I submitted a patch for this bug once before and it was applied as 
#12496.  I don't know why it got lost.  Was it deliberately backed out, 
or did it just get lost in the re-write of Carp/Heavy.pm that seems to 
have taken place since then?

Cheers,

Steve

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