| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package usw; | 
| 2 | 14 |  |  | 14 |  | 1132720 | use 5.012005; | 
|  | 14 |  |  |  |  | 170 |  | 
| 3 | 14 |  |  | 14 |  | 6111 | use parent qw(utf8 strict warnings); | 
|  | 14 |  |  |  |  | 4042 |  | 
|  | 14 |  |  |  |  | 76 |  | 
| 4 | 14 |  |  | 14 |  | 8627 | use Encode qw(is_utf8 encode_utf8 decode_utf8); | 
|  | 14 |  |  |  |  | 42637 |  | 
|  | 14 |  |  |  |  | 6718 |  | 
| 5 |  |  |  |  |  |  |  | 
| 6 |  |  |  |  |  |  | our $VERSION = "0.12"; | 
| 7 |  |  |  |  |  |  | my $enc; | 
| 8 | 1 |  |  | 1 |  | 405949 | sub _get_encoding {$enc} | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | sub import { | 
| 11 | 17 |  |  | 17 |  | 458 | $_->import for qw( utf8 strict warnings );   # borrowed from https://metacpan.org/pod/Mojo::Base | 
| 12 | 17 |  |  |  |  | 8058 | require encoding; | 
| 13 | 17 |  |  |  |  | 37665 | my $cp = encoding::_get_locale_encoding();    # borrowed from https://metacpan.org/pod/open | 
| 14 | 17 | 50 |  |  |  | 24230 | $enc = $cp =~ /^utf-?8/i ? 'UTF-8' : $cp; | 
| 15 | 17 |  | 33 |  |  | 68 | $enc ||= ( split /\./, $ENV{LANG} )[-1];      # Cannot find encoding in some environment | 
| 16 |  |  |  |  |  |  |  | 
| 17 | 17 | 50 |  |  |  | 71 | if ($enc) { | 
| 18 | 17 |  |  |  |  | 51 | $| = 1; | 
| 19 | 17 |  |  |  |  | 399 | binmode \*STDIN  => ":encoding($enc)"; | 
| 20 | 17 |  |  |  |  | 627 | binmode \*STDOUT => ":encoding($enc)"; | 
| 21 | 17 |  |  |  |  | 488 | binmode \*STDERR => ":encoding($enc)"; | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 | 17 |  |  |  |  | 365 | $SIG{__WARN__} = \&_redecode; | 
| 25 | 17 |  |  | 18 |  | 111 | $SIG{__DIE__}  = sub { die _redecode(@_) }; | 
|  | 18 |  |  |  |  | 37281 |  | 
| 26 | 17 |  |  |  |  | 10464 | return; | 
| 27 |  |  |  |  |  |  | } | 
| 28 |  |  |  |  |  |  |  | 
| 29 |  |  |  |  |  |  | sub unimport { | 
| 30 | 2 |  |  | 2 |  | 1350 | require Carp; | 
| 31 | 2 |  |  |  |  | 376 | Carp::croak "$_[0] doesn't provide `no` pragma"; | 
| 32 |  |  |  |  |  |  | } | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | sub _redecode { | 
| 35 | 112 |  |  | 112 |  | 4837 | $_[0] =~ /^(.+) at (.+) line (\d+)\.$/; | 
| 36 | 112 |  |  |  |  | 2371 | my @texts = split $2, $_[0]; | 
| 37 | 112 | 100 | 50 |  |  | 135546 | return is_utf8($1) | 
| 38 |  |  |  |  |  |  | ? $texts[0] || '' . decode_utf8($2) . $texts[1] || '' | 
| 39 |  |  |  |  |  |  | : decode_utf8 $_[0]; | 
| 40 |  |  |  |  |  |  | } | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | 1; | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | __END__ |