diff options
author | Zefram <zefram@fysh.org> | 2013-08-21 23:43:20 +0100 |
---|---|---|
committer | Zefram <zefram@fysh.org> | 2013-08-21 23:49:48 +0100 |
commit | d5dcec3a2d59e371062ff5b9430ca9be9eaf3b66 (patch) | |
tree | 341324e385ee623fe0687f686c730046e44b7f00 /dist | |
parent | ed3803055ee53367e2749347d7516245e1944e20 (diff) | |
download | perl-d5dcec3a2d59e371062ff5b9430ca9be9eaf3b66.tar.gz |
avoid Unicode warnings in Carp
Only affects operation on old Perl versions. Some special-case hackery
required for compatibility with old warnings.pm that eagerly loads Carp.
Diffstat (limited to 'dist')
-rw-r--r-- | dist/Carp/lib/Carp.pm | 23 | ||||
-rw-r--r-- | dist/Carp/lib/Carp/Heavy.pm | 2 | ||||
-rw-r--r-- | dist/Carp/t/baduni.t | 14 | ||||
-rw-r--r-- | dist/Carp/t/baduni_warnings.t | 15 |
4 files changed, 52 insertions, 2 deletions
diff --git a/dist/Carp/lib/Carp.pm b/dist/Carp/lib/Carp.pm index 5ca5e521bc..6ed248f12a 100644 --- a/dist/Carp/lib/Carp.pm +++ b/dist/Carp/lib/Carp.pm @@ -3,6 +3,27 @@ package Carp; { use 5.006; } use strict; use warnings; +BEGIN { + # Very old versions of warnings.pm load Carp. This can go wrong due + # to the circular dependency. If warnings is invoked before Carp, + # then warnings starts by loading Carp, then Carp (above) tries to + # invoke warnings, and gets nothing because warnings is in the process + # of loading and hasn't defined its import method yet. If we were + # only turning on warnings ("use warnings" above) this wouldn't be too + # bad, because Carp would just gets the state of the -w switch and so + # might not get some warnings that it wanted. The real problem is + # that we then want to turn off Unicode warnings, but "no warnings + # 'utf8'" won't be effective if we're in this circular-dependency + # situation. So, if warnings.pm is an affected version, we turn + # off all warnings ourselves by directly setting ${^WARNING_BITS}. + # On unaffected versions, we turn off just Unicode warnings, via + # the proper API. + if(!defined($warnings::VERSION) || eval($warnings::VERSION) < 1.06) { + ${^WARNING_BITS} = ""; + } else { + "warnings"->unimport("utf8"); + } +} BEGIN { no strict "refs"; @@ -24,7 +45,7 @@ BEGIN { } } -our $VERSION = '1.31'; +our $VERSION = '1.32'; our $MaxEvalLen = 0; our $Verbose = 0; diff --git a/dist/Carp/lib/Carp/Heavy.pm b/dist/Carp/lib/Carp/Heavy.pm index a7a3327387..f0de26373a 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.31'; +our $VERSION = '1.32'; 1; diff --git a/dist/Carp/t/baduni.t b/dist/Carp/t/baduni.t new file mode 100644 index 0000000000..f2ec055866 --- /dev/null +++ b/dist/Carp/t/baduni.t @@ -0,0 +1,14 @@ +BEGIN { print "1..1\n"; } + +BEGIN { $^W = 1; } +BEGIN { $SIG{__WARN__} = sub { die "WARNING: $_[0]" }; } + +use Carp (); + +my $badstr = do { no warnings "utf8"; "\x{ffff}" }; +sub dd { Carp::longmess() } +dd($badstr); + +print "ok 1\n"; + +1; diff --git a/dist/Carp/t/baduni_warnings.t b/dist/Carp/t/baduni_warnings.t new file mode 100644 index 0000000000..c5c876ce4b --- /dev/null +++ b/dist/Carp/t/baduni_warnings.t @@ -0,0 +1,15 @@ +BEGIN { print "1..1\n"; } + +BEGIN { $^W = 1; } +BEGIN { $SIG{__WARN__} = sub { die "WARNING: $_[0]" }; } + +use warnings; # this may load Carp +use Carp (); + +my $badstr = do { no warnings "utf8"; "\x{ffff}" }; +sub dd { Carp::longmess() } +dd($badstr); + +print "ok 1\n"; + +1; |