File Coverage

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   1132241 use 5.012005;
  14         146  
3 14     14   5711 use parent qw(utf8 strict warnings);
  14         3946  
  14         77  
4 14     14   8510 use Encode qw(is_utf8 encode_utf8 decode_utf8);
  14         41781  
  14         5494  
5              
6             our $VERSION = "0.10";
7             my $enc;
8 1     1   380602 sub _get_encoding {$enc}
9              
10             sub import {
11 15     15   393 $_->import for qw( utf8 strict warnings ); # borrowed from https://metacpan.org/pod/Mojo::Base
12 15         7612 require encoding;
13 15         35105 my $cp = encoding::_get_locale_encoding(); # borrowed from https://metacpan.org/pod/open
14 15 50       22636 $enc = $cp =~ /^utf-8/ ? 'UTF-8' : $cp;
15              
16 15         41 $| = 1; # is this irrelevant?
17 15         283 binmode \*STDIN => ":encoding($enc)";
18 15         589 binmode \*STDOUT => ":encoding($enc)";
19 15         408 binmode \*STDERR => ":encoding($enc)";
20              
21 15         303 $SIG{__WARN__} = \&_redecode;
22 15     14   94 $SIG{__DIE__} = sub { die _redecode(@_) };
  14         41424  
23 15         10515 return;
24             }
25              
26             sub _redecode {
27 108     108   4415 $_[0] =~ /^(.+) at (.+) line (\d+)\.$/;
28 108         1729 my @texts = split $2, $_[0];
29 108 100 50     132438 return is_utf8($1)
30             ? $texts[0] || '' . decode_utf8($2) . $texts[1] || ''
31             : decode_utf8 $_[0];
32             }
33              
34             1;
35              
36             __END__