Subject: | Some warnings will get lost |
Date: | Wed, 9 Sep 2020 07:34:27 +0000 |
To: | "bug-Warn-Colorful [...] rt.cpan.org" <bug-Warn-Colorful [...] rt.cpan.org> |
From: | Ludger Irsig <irsig [...] racyics.de> |
Testcase:
open(my $input_measure, "<", $path_to_file);
while (<$input_measure>) {
warn Test;
}
Instead of printing Test at file xyz line 123. we will only see at file
xyz line 123.
The cause is that the RegExp to match the warning is not generic enough.
Fixed it for me as follows:
$SIG{__WARN__} = sub {
my $msg = shift;
my $out;
my (undef, $file, $line) = caller;
#try to separate the warning by RegExp
my ($body,$tail) = $msg =~ /(.*) at ${file} line ${line}(, <\$.*> line
\d*)?\.\n$/;
if (defined $tail) {
$out = sprintf "%s %s %s%s.\n",
colored([$colors{body}], $body),
colored([$colors{file}], "at ${file}"),
colored([$colors{line}], "line ${line}"),
colored([$colors{line}], $tail);
} elsif (defined $body) {
$out = sprintf "%s %s %s.\n",
colored([$colors{body}], $body),
colored([$colors{file}], "at ${file}"),
colored([$colors{line}], "line ${line}");
} else {
$out = colored([$colors{body}], $msg);
}
print STDERR $out;
};
Ludger Irsig
Show quoted text
_______________________________________________________________
Racyics GmbH
Bergstraße 56 Phone +49 351 418872 53
D-01069 Dresden Fax +49 351 418872 99
Email irsig@racyics.de
<mailto:irsig@racyics.de>
WWW www.racyics.de
<http://www.racyics.de>
Handelsregistereintrag: Amtsgericht Dresden, HRB 28485
Geschäftsführer: Holger Eisenreich, Georg Ellguth,
Jens-Uwe Schlüßler, Jörg Schreiter
_______________________________________________________________
Message body not shown because it is not plain text.