File Coverage

blib/lib/usw.pm
Criterion Covered Total %
statement 24 24 100.0
branch 3 4 75.0
condition 1 2 50.0
subroutine 7 7 100.0
pod n/a
total 35 37 94.5


line stmt bran cond sub pod time code
1             package usw;
2 14     14   1126995 use 5.012005;
  14         153  
3 14     14   5873 use parent qw(utf8 strict warnings);
  14         3901  
  14         78  
4 14     14   8518 use Encode qw(is_utf8 encode_utf8 decode_utf8);
  14         42950  
  14         5474  
5              
6             our $VERSION = "0.11";
7             my $enc;
8 1     1   388638 sub _get_encoding {$enc}
9              
10             sub import {
11 15     15   442 $_->import for qw( utf8 strict warnings ); # borrowed from https://metacpan.org/pod/Mojo::Base
12 15         7490 require encoding;
13 15         35195 my $cp = encoding::_get_locale_encoding(); # borrowed from https://metacpan.org/pod/open
14 15 50       22239 $enc = $cp =~ /^utf-8/ ? 'UTF-8' : $cp;
15              
16 15         48 $| = 1; # is this irrelevant?
17 15         311 binmode \*STDIN => ":encoding($enc)";
18 15         561 binmode \*STDOUT => ":encoding($enc)";
19 15         417 binmode \*STDERR => ":encoding($enc)";
20              
21 15         320 $SIG{__WARN__} = \&_redecode;
22 15     14   118 $SIG{__DIE__} = sub { die _redecode(@_) };
  14         36877  
23 15         10410 return;
24             }
25              
26             sub _redecode {
27 108     108   4454 $_[0] =~ /^(.+) at (.+) line (\d+)\.$/;
28 108         1658 my @texts = split $2, $_[0];
29 108 100 50     133807 return is_utf8($1)
30             ? $texts[0] || '' . decode_utf8($2) . $texts[1] || ''
31             : decode_utf8 $_[0];
32             }
33              
34             1;
35              
36             __END__