| 1 | package usw; | ||
| 2 | use 5.012005; | ||
| 3 | |||
| 4 | our $VERSION = "0.06"; | ||
| 5 | |||
| 6 | use Encode qw(is_utf8 encode_utf8 decode_utf8); | ||
| 7 | use utf8(); | ||
| 8 | use strict(); | ||
| 9 | use warnings(); | ||
| 10 | use List::Util qw(first); | ||
| 11 | |||
| 12 | sub import { | ||
| 13 | utf8->import; | ||
| 14 | strict->import; | ||
| 15 | warnings->import( 'all', FATAL => 'recursion' ); | ||
| 16 | |||
| 17 | #binmode \*STDIN, ":encoding(UTF-8)"; | ||
| 18 | binmode \*STDOUT, ":encoding(UTF-8)"; | ||
| 19 | binmode \*STDERR, ":encoding(UTF-8)"; | ||
| 20 | return unless @_; | ||
| 21 | |||
| 22 | $SIG{__WARN__} = \&_redecode if first { $_ eq 'warn' } @_; | ||
| 23 | $SIG{__DIE__} = sub { die _redecode(@_) } | ||
| 24 | if first { $_ eq 'die' } @_; | ||
| 25 | |||
| 26 | return; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub _redecode { | ||
| 30 | $_[0] =~ /^(.+) at (.+) line (\d+)\.$/; | ||
| 31 | my @texts = split $2, $_[0]; | ||
| 32 | return is_utf8($1) | ||
| 33 | ? $texts[0] . decode_utf8 $2. $texts[1] | ||
| 34 | : decode_utf8 $_[0]; | ||
| 35 | } | ||
| 36 | |||
| 37 | 1; | ||
| 38 | |||
| 39 | __END__ |