Skip to content

Commit

Permalink
Merge pull request #39 from dolmen/encoding-pm/more-inlining
Browse files Browse the repository at this point in the history
encoding.pm: more inlining
  • Loading branch information
dankogai committed Mar 30, 2015
2 parents 5ac0595 + 5d76b1d commit 49d1f8b
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions encoding.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ use Encode;
use strict;
use warnings;

use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};
use constant {
DEBUG => !!$ENV{PERL_ENCODE_DEBUG},
HAS_PERLIO => eval { require PerlIO::encoding; PerlIO::encoding->VERSION(0.02) },
PERL_5_21_7 => $^V && $^V ge v5.21.7,
};

BEGIN {
if ( ord("A") == 193 ) {
Expand All @@ -15,12 +19,6 @@ BEGIN {
}
}

our $HAS_PERLIO = 0;
eval { require PerlIO::encoding };
unless ($@) {
$HAS_PERLIO = ( PerlIO::encoding->VERSION >= 0.02 );
}

sub _exception {
my $name = shift;
$] > 5.008 and return 0; # 5.8.1 or higher then no
Expand Down Expand Up @@ -132,7 +130,7 @@ sub import {
unless ( $arg{Filter} ) {
DEBUG and warn "_exception($name) = ", _exception($name);
if (! _exception($name)) {
if (!$^V || $^V lt v5.21.7) {
if (!PERL_5_21_7) {
${^ENCODING} = $enc;
}
else {
Expand All @@ -143,11 +141,11 @@ sub import {
${^E_NCODING} = $enc;
}
}
$HAS_PERLIO or return 1;
HAS_PERLIO or return 1;
}
else {
defined( ${^ENCODING} ) and undef ${^ENCODING};
undef ${^E_NCODING} if $^V && $^V ge v5.21.7;
undef ${^E_NCODING} if PERL_5_21_7;

# implicitly 'use utf8'
require utf8; # to fetch $utf8::hint_bits;
Expand Down Expand Up @@ -197,8 +195,8 @@ sub import {
sub unimport {
no warnings;
undef ${^ENCODING};
undef ${^E_NCODING} if $^V && $^V ge v5.21.7;
if ($HAS_PERLIO) {
undef ${^E_NCODING} if PERL_5_21_7;
if (HAS_PERLIO) {
binmode( STDIN, ":raw" );
binmode( STDOUT, ":raw" );
}
Expand Down

0 comments on commit 49d1f8b

Please sign in to comment.