New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Fix RTCPAN#107225 : Carp::longmess() returns "1" when passed a reference and called in scalar context #15217
Comments
From @shlomifHi all, these two patches [against bleadperl] fix As usual, I hereby disclaim any explicit or implict ownership of my changes and They can also be found here: https://github.com/shlomif/perl5/tree/shlomif--Carp.pm-improvements Regards, Shlomi Fish |
From @shlomif0001-Fix-RTCPAN-107225-longmess-returns-1-on-ref.patchFrom bed5a3a3196a6af7e372496c96b105fbf572ccd5 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 6 Mar 2016 20:37:25 +0200
Subject: [PATCH 1/2] Fix RTCPAN#107225 : longmess returns 1 on ref.
See: https://rt.cpan.org/Public/Bug/Display.html?id=107225 . Also
discovered as a bug in perl -d by me (= Shlomi Fish) and reported
after the original report. longmess() returns "1" when called in scalar
context if passed a reference.
---
dist/Carp/lib/Carp.pm | 6 ++++--
dist/Carp/lib/Carp/Heavy.pm | 2 +-
dist/Carp/t/Carp.t | 20 +++++++++++++++++++-
3 files changed, 24 insertions(+), 4 deletions(-)
diff --git a/dist/Carp/lib/Carp.pm b/dist/Carp/lib/Carp.pm
index 9421c74..9a29872 100644
--- a/dist/Carp/lib/Carp.pm
+++ b/dist/Carp/lib/Carp.pm
@@ -87,7 +87,7 @@ BEGIN {
}
}
-our $VERSION = '1.38';
+our $VERSION = '1.38_01';
$VERSION =~ tr/_//d;
our $MaxEvalLen = 0;
@@ -445,7 +445,9 @@ sub long_error_loc {
}
sub longmess_heavy {
- return @_ if ref( $_[0] ); # don't break references as exceptions
+ if ( ref( $_[0] ) ) { # don't break references as exceptions
+ return wantarray ? @_ : $_[0];
+ }
my $i = long_error_loc();
return ret_backtrace( $i, @_ );
}
diff --git a/dist/Carp/lib/Carp/Heavy.pm b/dist/Carp/lib/Carp/Heavy.pm
index 91a42d1..1a2ff3a 100644
--- a/dist/Carp/lib/Carp/Heavy.pm
+++ b/dist/Carp/lib/Carp/Heavy.pm
@@ -2,7 +2,7 @@ package Carp::Heavy;
use Carp ();
-our $VERSION = '1.38';
+our $VERSION = '1.38_01';
$VERSION =~ tr/_//d;
# Carp::Heavy was merged into Carp in version 1.12. Any mismatched versions
diff --git a/dist/Carp/t/Carp.t b/dist/Carp/t/Carp.t
index a18e3b4..9ecdf88 100644
--- a/dist/Carp/t/Carp.t
+++ b/dist/Carp/t/Carp.t
@@ -3,7 +3,7 @@ no warnings "once";
use Config;
use IPC::Open3 1.0103 qw(open3);
-use Test::More tests => 65;
+use Test::More tests => 66;
sub runperl {
my(%args) = @_;
@@ -39,6 +39,24 @@ BEGIN {
);
}
+package MyClass;
+
+sub new { return bless +{ field => ['value1', 'SecondVal'] }; }
+
+package main;
+
+{
+ my $err = Carp::longmess(MyClass->new);
+
+ # See:
+ # https://rt.cpan.org/Public/Bug/Display.html?id=107225
+ is_deeply(
+ $err->{field},
+ ['value1', 'SecondVal',],
+ "longmess returns sth meaningful in scalar context when passed a ref.",
+ );
+}
+
{
local $SIG{__WARN__} = sub {
like $_[0], qr/ok (\d+)\n at.+\b(?i:carp\.t) line \d+\.$/, 'ok 2\n';
--
2.7.2
|
From @shlomif0002-Document-the-previous-commit-in-Carp-s-Changes.patchFrom a6e6148720e7165a2ef5997944f88581c984e9b1 Mon Sep 17 00:00:00 2001
From: Shlomi Fish <shlomif@shlomifish.org>
Date: Sun, 6 Mar 2016 20:52:03 +0200
Subject: [PATCH 2/2] Document the previous commit in Carp's Changes.
---
dist/Carp/Changes | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/dist/Carp/Changes b/dist/Carp/Changes
index b55b49f..24c0447 100644
--- a/dist/Carp/Changes
+++ b/dist/Carp/Changes
@@ -1,4 +1,8 @@
+version 1.38_01; 2016-03-06
+ * bugfix: longmess() should return the error in scalar context
+ (CPANRT#107225)
+
version 1.38; 2015-11-06
* stable release of changes since v1.36
--
2.7.2
|
From @tonycozOn Sun Mar 06 11:12:08 2016, shlomif@shlomifish.org wrote:
Applied as 6ca94a7 and 999ef43. I changed the version number to 1.39. Tony |
The RT System itself - Status changed from 'new' to 'open' |
@tonycoz - Status changed from 'open' to 'pending release' |
From @shlomifOn Sun, 6 Mar 2016 20:47:00 -0800
Thanks, Tony! Regards, Shlomi Fish
-- Shlomi Fish http://www.shlomifish.org/ Well, one thing I can tell you about parenthood is that such things Please reply to list if it's a mailing list post - http://shlom.in/reply . |
From @khwilliamsonThank you for submitting this report. You have helped make Perl better. Perl 5.24.0 may be downloaded via https://metacpan.org/release/RJBS/perl-5.24.0 |
@khwilliamson - Status changed from 'pending release' to 'resolved' |
Migrated from rt.perl.org#127664 (status was 'resolved')
Searchable as RT127664$
The text was updated successfully, but these errors were encountered: