Skip to content

Commit

Permalink
Fix loading Encode::Alias before Encode
Browse files Browse the repository at this point in the history
Calling

  use Encode::Alias;

cased error:

  Undefined subroutine &Encode::define_alias called at lib/Encode.pm line 102.
  Compilation failed in require at lib/Encode/Alias.pm line 7.
  BEGIN failed--compilation aborted at lib/Encode/Alias.pm line 7.
  Compilation failed in require at -e line 1.
  BEGIN failed--compilation aborted at -e line 1.

Fixes dankogai#116
  • Loading branch information
pali committed Jul 17, 2017
1 parent f929414 commit 6d5e144
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
11 changes: 10 additions & 1 deletion Encode.pm
Expand Up @@ -49,7 +49,7 @@ our %EXPORT_TAGS = (

our $ON_EBCDIC = ( ord("A") == 193 );

use Encode::Alias;
use Encode::Alias ();
use Encode::MIME::Name;

use Storable;
Expand Down Expand Up @@ -138,6 +138,15 @@ sub getEncoding {
return;
}

# HACK: These two functions must be defined in Encode and because of
# cyclic dependency between Encode and Encode::Alias, Exporter does not work
sub find_alias {
goto &Encode::Alias::find_alias;
}
sub define_alias {
goto &Encode::Alias::define_alias;
}

sub find_encoding($;$) {
my ( $name, $skip_external ) = @_;
return __PACKAGE__->getEncoding( $name, $skip_external );
Expand Down
1 change: 1 addition & 0 deletions MANIFEST
Expand Up @@ -110,6 +110,7 @@ t/taint.t test script
t/truncated_utf8.t test script
t/undef.t test script
t/unibench.pl benchmark script
t/use-Encode-Alias.t test script
t/utf8messages.t test script
t/utf8ref.t test script
t/utf8strict.t test script
Expand Down
5 changes: 3 additions & 2 deletions lib/Encode/Alias.pm
Expand Up @@ -4,8 +4,6 @@ use warnings;
our $VERSION = do { my @r = ( q$Revision: 2.22 $ =~ /\d+/g ); sprintf "%d." . "%02d" x $#r, @r };
use constant DEBUG => !!$ENV{PERL_ENCODE_DEBUG};

use Encode ();

use Exporter 'import';

# Public, encouraged API is exported by default
Expand Down Expand Up @@ -109,6 +107,9 @@ sub define_alias {
}
}

# HACK: Encode must be used after define_alias is declarated as Encode calls define_alias
use Encode ();

# Allow latin-1 style names as well
# 0 1 2 3 4 5 6 7 8 9 10
our @Latin2iso = ( 0, 1, 2, 3, 4, 9, 10, 13, 14, 15, 16 );
Expand Down
8 changes: 8 additions & 0 deletions t/use-Encode-Alias.t
@@ -0,0 +1,8 @@
use strict;
use warnings;

use Encode::Alias;
use open ":std", ":locale";

print "1..1\n";
print "ok 1 - use Encode::Alias works\n";

0 comments on commit 6d5e144

Please sign in to comment.