| 1 | package Config::Maker::Encode; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 9 | ▶ | use utf8; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | 9 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | |||||||||||||||
| 7 | 9 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 9 | ▶ | use Exporter; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 9 | our @ISA = qw(Exporter); | |||||||||||||
| 11 | 9 | our @EXPORT = qw(encode decode encmode $utf8); | |||||||||||||
| 12 | 9 | our @EXPORT_OK = @EXPORT; | |||||||||||||
| 13 | |||||||||||||||
| 14 | sub encode($$;$); | ||||||||||||||
| 15 | sub decode($$;$); | ||||||||||||||
| 16 | sub encmode(*$); | ||||||||||||||
| 17 | |||||||||||||||
| 18 | 9 | our $utf8; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 0 | ▶ | sub _encode_only_system($$;$) { | ||||||||||||
|
Subroutine
_encode_only_system: not called CC=3 SCAR=24.8
| |||||||||||||||
| 21 | 0 | my ($enc, $text, $check) = @_; | |||||||||||||
| 22 | 0 | ▶ | unless($enc eq 'system') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | 0 | ▶ | if($check == 1) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 24 | 0 | croak "Encoding not available. Can't convert encoding $enc"; | |||||||||||||
| 25 | } else { | ||||||||||||||
| 26 | 0 | carp "Encoding not available. Can't convert encoding $enc"; | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | } | ||||||||||||||
| 29 | 0 | return $text; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | |||||||||||||||
| 32 | 0 | ▶ | sub _binmode_only_system(*$) { | ||||||||||||
|
Subroutine
_binmode_only_system: not called CC=2 SCAR=17.9
| |||||||||||||||
| 33 | 0 | my ($handle, $enc) = @_; | |||||||||||||
| 34 | 0 | ▶ | unless($enc eq 'system') { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | 0 | carp "Encoding not available. Can't set encoding to $enc"; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 45 | ▶ | sub _binmode_encoding(*$) { | ||||||||||||
|
Subroutine
_binmode_encoding: called CC=1 SCAR=0.0
| |||||||||||||||
| 40 | 45 | my ($handle, $enc) = @_; | |||||||||||||
| 41 | 45 | binmode $handle, ":encoding($enc)"; | |||||||||||||
| 42 | } | ||||||||||||||
| 43 | |||||||||||||||
| 44 | 9 | eval { | |||||||||||||
| 45 | 9 | require I18N::Langinfo; | |||||||||||||
| 46 | 9 | require Encode; | |||||||||||||
| 47 | 9 | require Encode::Alias; | |||||||||||||
| 48 | 9 | require PerlIO::encoding; | |||||||||||||
| 49 | 9 | $::ENCODING = I18N::Langinfo::langinfo(&I18N::Langinfo::CODESET); | |||||||||||||
| 50 | 9 | ▶ | if(!$::ENCODING) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 51 | 0 | $::ENCODING_LOG = "Can't get your locale encoding! Assuming ASCII."; | |||||||||||||
| 52 | 0 | ▶ | Encode::find_encoding($::ENCODING = 'ascii') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | or die "Can't get ascii codec!"; | ||||||||||||||
| 54 | } elsif(!Encode::find_encoding($::ENCODING)) { | ||||||||||||||
| 55 | 0 | $::ENCODING_LOG = "Your locale encoding `$::ENCODING' it's not supported by Encode!"; | |||||||||||||
| 56 | 0 | ▶ | Encode::find_encoding($::ENCODING = 'ascii') | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 57 | or die "Can't get ascii codec!"; | ||||||||||||||
| 58 | } | ||||||||||||||
| 59 | 9 | Encode::Alias::define_alias('system' => $::ENCODING); | |||||||||||||
| 60 | }; | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 9 | ▶ | if($@) { # Encoding stuff not available! | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 63 | 0 | undef $::ENCODING; | |||||||||||||
| 64 | 0 | *encode = \&_encode_only_system; | |||||||||||||
| 65 | 0 | *decode = \&_encode_only_system; | |||||||||||||
| 66 | 0 | *encmode = \&_binmode_only_system; | |||||||||||||
| 67 | 0 | $utf8 = ''; | |||||||||||||
| 68 | } else { # Wow! Encoding is available! | ||||||||||||||
| 69 | 9 | *encode = \&Encode::encode; | |||||||||||||
| 70 | 9 | *decode = \&Encode::decode; | |||||||||||||
| 71 | 9 | *encmode = \&_binmode_encoding; | |||||||||||||
| 72 | 9 | $utf8 = ':utf8'; | |||||||||||||
| 73 | 9 | binmode STDERR, ':encoding(system)'; | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | |||||||||||||||
| 76 | 9 | 1; | |||||||||||||
| 77 | |||||||||||||||
| 78 | __END__ | ||||||||||||||