blib/lib/usw.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 2 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 59 CC 5 SCAR 21.6
CC
5
Cov
0%
import
20.0
_redecode
6.0
BEGIN
2.0
CRAP 8.7
1 package usw;
2 use 5.012005;
3  
4 our $VERSION = "0.04";
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 my $out = first { $_ =~ /^cp\d+$/ } @_;
18 $out ||= 'UTF-8';
19 binmode \*STDIN, ":encoding($out)";
20 binmode \*STDOUT, ":encoding($out)";
21 binmode \*STDERR, ":encoding($out)";
22 return unless @_;
23  
24 $SIG{__WARN__} = \&_redecode if first { $_ eq 'warn' } @_;
25 $SIG{__DIE__} = sub { die _redecode(@_) }
26 if first { $_ eq 'die' } @_;
27  
28 return;
29 }
30  
31 sub _redecode {
32 $_[0] =~ /^(.+) at (.+) line (\d+)\.$/;
33 my @texts = split $2, $_[0];
34 return is_utf8($1)
35 ? $texts[0] . decode_utf8 $2. $texts[1]
36 : decode_utf8 $_[0];
37 }
38  
39 1;
40  
41 __END__