This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade to Encode 1.57, from Dan Kogai.
authorJarkko Hietaniemi <jhi@iki.fi>
Mon, 22 Apr 2002 19:48:20 +0000 (19:48 +0000)
committerJarkko Hietaniemi <jhi@iki.fi>
Mon, 22 Apr 2002 19:48:20 +0000 (19:48 +0000)
p4raw-id: //depot/perl@16085

12 files changed:
ext/Encode/Changes
ext/Encode/Encode.pm
ext/Encode/Encode.xs
ext/Encode/Unicode/Unicode.pm
ext/Encode/lib/Encode/CN/HZ.pm
ext/Encode/lib/Encode/Encoding.pm
ext/Encode/lib/Encode/JP/JIS7.pm
ext/Encode/lib/Encode/KR/2022_KR.pm
ext/Encode/t/JP.t
ext/Encode/t/KR.t
ext/Encode/t/jperl.t
ext/Encode/t/perlio.t

index d34ebce..46e2902 100644 (file)
@@ -1,9 +1,20 @@
 # Revision history for Perl extension Encode.
 #
-# $Id: Changes,v 1.56 2002/04/22 09:48:07 dankogai Exp dankogai $
+# $Id: Changes,v 1.57 2002/04/22 20:27:30 dankogai Exp dankogai $
 #
 
-$Revision: 1.56 $ $Date: 2002/04/22 09:48:07 $
+$Revision: 1.57 $ $Date: 2002/04/22 20:27:30 $
+! t/JP.t t/KR.t t/perlio.t
+  unless (find PerlIO::Layer 'perlio') ... line is back again.
+  t/JP.t and t/KR.t were supposed to work but maybe '>:utf8' lines
+  need PerlIO.  Sigh....
+! Encode.xs Unicode/Unicode.pm lib/Encode/JP/JIS7.pm t/perlio.t
+  ->perlio_ok now does eval{ require PerlIO::encoding } there so
+  it correctly returns 1 when PerlIO::encoding is yet loaded.
+! Encode.xs
+  perl-current patch #16072 reflected
+
+1.56 2002/04/22 09:48:07 
 ! Encode.pm encoding.pm t/perlio.t t/jperl.t
   New PerlIO::encoding 0.04 compliance met
 
@@ -443,7 +454,7 @@ $Revision: 1.56 $ $Date: 2002/04/22 09:48:07 $
   Typo fixes and improvements by jhi
   Message-Id: <200204010201.FAA03564@alpha.hut.fi>, et al.
 
-1.11  $Date: 2002/04/22 09:48:07 $
+1.11  $Date: 2002/04/22 20:27:30 $
 + t/encoding.t
 + t/jperl.t
 ! MANIFEST
index dbd7934..cb133e5 100644 (file)
@@ -1,6 +1,6 @@
 package Encode;
 use strict;
-our $VERSION = do { my @r = (q$Revision: 1.56 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.57 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
 our $DEBUG = 0;
 use XSLoader ();
 XSLoader::load 'Encode';
@@ -65,9 +65,8 @@ sub encodings
 }
 
 sub perlio_ok{
-    exists $INC{"PerlIO/encoding.pm"} or return 0;
     my $obj = ref($_[0]) ? $_[0] : find_encoding($_[0]);
-    $obj->can("perlio_ok") and return $obj->perlio_ok() unless $@;
+    $obj->can("perlio_ok") and return $obj->perlio_ok();
     return 0; # safety net
 }
 
index 886fb89..5602c70 100644 (file)
@@ -1,5 +1,5 @@
 /*
- $Id: Encode.xs,v 1.33 2002/04/22 03:43:05 dankogai Exp $
+ $Id: Encode.xs,v 1.34 2002/04/22 20:27:30 dankogai Exp dankogai $
  */
 
 #define PERL_NO_GET_CONTEXT
@@ -23,6 +23,7 @@
                         return (y)0; /* fool picky compilers */ \
                          }
 /**/
+
 UNIMPLEMENTED(_encoded_utf8_to_bytes, I32)
 UNIMPLEMENTED(_encoded_bytes_to_utf8, I32)
 
@@ -280,6 +281,7 @@ SV *        obj
 CODE:
 {
     encode_t *enc = INT2PTR(encode_t *, SvIV(SvRV(obj)));
+    require_pv(PERLIO_FILENAME);
     if (hv_exists(get_hv("INC", 0), 
                  PERLIO_FILENAME, strlen(PERLIO_FILENAME)))
     {
index fdf826e..bfe03bd 100644 (file)
@@ -3,7 +3,7 @@ package Encode::Unicode;
 use strict;
 use warnings;
 
-our $VERSION = do { my @r = (q$Revision: 1.34 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.35 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
 
 use XSLoader;
 XSLoader::load(__PACKAGE__,$VERSION);
@@ -50,8 +50,12 @@ sub new_sequence
 sub needs_lines { 0 };
 
 sub perlio_ok { 
-    exists $INC{"PerlIO/encoding.pm"} or return 0;
-    return 1;
+    eval{ require PerlIO::encoding };
+    if ($@){
+       return 0;
+    }else{
+       return 1;
+    }
 }
 
 
index 56a8acd..376300b 100644 (file)
@@ -3,7 +3,7 @@ package Encode::CN::HZ;
 use strict;
 
 use vars qw($VERSION);
-$VERSION = do { my @r = (q$Revision: 1.2 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+$VERSION = do { my @r = (q$Revision: 1.3 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
 
 use Encode ();
 use Encode::CN;
@@ -19,8 +19,6 @@ $obj->Define($canon);
 sub needs_lines  { 1 }
 
 sub perlio_ok { 
-    # exists $INC{"PerlIO/encoding.pm"} or return 0;
-    # PerlIO::encoding->VERSION >= 0.03 and return 1;
     return 0; # for the time being
 }
 
index 16a950a..12f0655 100644 (file)
@@ -1,7 +1,7 @@
 package Encode::Encoding;
 # Base class for classes which implement encodings
 use strict;
-our $VERSION = do { my @r = (q$Revision: 1.27 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.28 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
 
 sub Define
 {
@@ -127,7 +127,15 @@ If you want your encoding to work with PerlIO, you MUST define this
 method so that it returns 1 when PerlIO is enabled.  Here is an
 example;
 
- sub perlio_ok { exists $INC{"PerlIO/encoding.pm"} }
+ sub perlio_ok { 
+     eval { require PerlIO::encoding };
+     if ($@){
+        return 0;
+     }else{
+        return 1;
+     }
+  }
+
 
 By default, this method is defined as follows;
 
index e38747e..c0a0d06 100644 (file)
@@ -1,7 +1,7 @@
 package Encode::JP::JIS7;
 use strict;
 
-our $VERSION = do { my @r = (q$Revision: 1.5 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.6 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
 
 use Encode qw(:fallbacks);
 
@@ -24,9 +24,12 @@ sub new_sequence { $_[0] }
 sub needs_lines { 1 }
 
 sub perlio_ok { 
-    exists $INC{"PerlIO/encoding.pm"} or return 0;
-    PerlIO::encoding->VERSION >= 0.03 and return 1;
-    return 0;
+    eval{ require PerlIO::encoding };
+    if ($@){
+        return 0;
+    }else{
+        return (PerlIO::encoding->VERSION >= 0.03);
+    }
 }
 
 use Encode::CJKConstants qw(:all);
index b6a65b7..da3b84c 100644 (file)
@@ -4,7 +4,7 @@ use base 'Encode::Encoding';
 
 use strict;
 
-our $VERSION = do { my @r = (q$Revision: 1.3 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+our $VERSION = do { my @r = (q$Revision: 1.4 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
 
 
 my $canon = 'iso-2022-kr';
@@ -16,8 +16,6 @@ sub name { return $_[0]->{name}; }
 sub needs_lines { 1 }
 
 sub perlio_ok { 
-    #exists $INC{"PerlIO/encoding.pm"} or return 0;
-    #PerlIO::encoding->VERSION >= 0.03 and return 1;
     return 0; # for the time being
 }
 
index 43517f3..6a65e15 100644 (file)
@@ -12,6 +12,10 @@ BEGIN {
        print "1..0 # Skip: EBCDIC\n";
        exit 0;
     }
+    unless (PerlIO::Layer->find('perlio')){
+       print "1..0 # Skip: PerlIO required\n";
+       exit 0;
+    }
     $| = 1;
 }
 use strict;
@@ -53,6 +57,7 @@ for my $charset (qw(jisx0201 jisx0212 jisx0208)){
     is(compare_text($utf, $ref), 0, "$utf eq $ref");
     
     open $src, "<:utf8", $ref or die "$ref : $!";
+    binmode($src);
     $uni = join('', <$src>);
     close $src;
 
index 0cf1908..1ffb4e6 100644 (file)
@@ -8,23 +8,23 @@ BEGIN {
       print "1..0 # Skip: Encode was not built\n";
       exit 0;
     }
-    unless (find PerlIO::Layer 'perlio') {
-       print "1..0 # Skip: PerlIO was not built\n";
-       exit 0;
-    }
     if (ord("A") == 193) {
        print "1..0 # Skip: EBCDIC\n";
        exit 0;
     }
+    unless (PerlIO::Layer->find('perlio')){
+       print "1..0 # Skip: PerlIO required\n";
+       exit 0;
+    }
     $| = 1;
 }
 use strict;
-use Test::More tests => 15;
+use Test::More tests => 11;
 #use Test::More qw(no_plan);
 use Encode;
 use File::Basename;
 use File::Spec;
-use File::Compare;
+use File::Compare qw(compare_text);
 require_ok "Encode::KR";
 
 my ($src, $uni, $dst, $txt, $euc, $utf, $ref, $rnd);
@@ -34,48 +34,59 @@ ok($enc->isa('Encode::XS'));
 is($enc->name,'euc-kr');
 my $dir = dirname(__FILE__);
 
-my @subcodings = qw(ksc5601);
-
-for my $subcoding (@subcodings){
-    $euc = File::Spec->catfile($dir,"$subcoding.euc");
+for my $charset (qw(ksc5601)){
+    $euc = File::Spec->catfile($dir,"$charset.euc");
     $utf = File::Spec->catfile($dir,"$$.utf8");
-    $ref = File::Spec->catfile($dir,"$subcoding.ref");
+    $ref = File::Spec->catfile($dir,"$charset.ref");
     $rnd = File::Spec->catfile($dir,"$$.rnd");
-    print "# Basic decode test\n";
-    open($src,"<",$euc) || die "Cannot open $euc:$!";
+
+    open($src,"<",$euc) or die "Cannot open $euc:$!";
     binmode($src);
-    ok(defined($src) && fileno($src));
     $txt = join('',<$src>);
-    open($dst,">:utf8",$utf) || die "Cannot open $utf:$!";
-    binmode($dst);
-    ok(defined($dst) && fileno($dst));
-    eval{ $uni = $enc->decode($txt,1) };
+    close($src);
+    
+    eval{ $uni = $enc->decode($txt, 1) }; 
     $@ and print $@;
-    ok(defined($uni));
-    is(length($txt),0);
+    ok(defined($uni),  "decode $charset");
+    is(length($txt),0, "decode $charset completely");
+
+    open($dst,">:utf8",$utf) or die "Cannot open $utf:$!";
+    binmode($dst);
     print $dst $uni;
-    close($dst);
-    close($src);
-    ok(compare($utf,$ref) == 0);
-}
+    close($dst); 
+    is(compare_text($utf, $ref), 0, "$utf eq $ref");
+    
+    open $src, "<:utf8", $ref or die "$ref : $!";
+    binmode($src);
+    $uni = join('', <$src>);
+    close $src;
 
-print "# Basic encode test\n";
-open($src,"<:utf8",$ref) || die "Cannot open $ref:$!";
-binmode($src);
-ok(defined($src) && fileno($src));
-$uni = join('',<$src>);
-open($dst,">",$rnd) || die "Cannot open $rnd:$!";
-binmode($dst);
-ok(defined($dst) && fileno($dst));
-$txt = $enc->encode($uni,1);
-ok(defined($txt));
-is(length($uni),0);
-print $dst $txt;
-close($dst);
-close($src);
-ok(compare($euc,$rnd) == 0);
+    for my $canon (qw(euc-kr)){
+       my $test = \&is;
+       if   ($charset eq 'jisx0201'){
+           $canon eq 'iso-2022-jp'   and $test = \&isnt;
+           $canon eq 'iso-2022-jp-1' and $test = \&isnt;
+       }elsif($charset eq 'jisx0212'){
+           $canon eq 'shiftjis'    and   $test = \&isnt;
+           $canon eq 'iso-2022-jp' and   $test = \&isnt;
+       }
+       my $rt = ($test eq \&is) ? 'RT' : 'non-RT';
+       $test->($uni, decode($canon, encode($canon, $uni)), 
+             "$rt $charset $canon");
+       
+     }
 
-is($enc->name,'euc-kr');
+    eval{ $txt = $enc->encode($uni,1) };    
+    $@ and print $@;
+    ok(defined($txt),   "encode $charset");
+    is(length($uni), 0, "encode $charset completely");
+
+    open($dst,">", $rnd) or die "Cannot open $utf:$!";
+    binmode($dst);
+    print $dst $txt;
+    close($dst); 
+    is(compare_text($euc, $rnd), 0 => "$rnd eq $euc");
+}
 
 END {
  1 while unlink($utf,$rnd);
index dd95324..faaf743 100644 (file)
@@ -1,5 +1,5 @@
 #
-# $Id: jperl.t,v 1.23 2002/04/22 09:48:07 dankogai Exp dankogai $
+# $Id: jperl.t,v 1.23 2002/04/22 09:48:07 dankogai Exp $
 #
 # This script is written in euc-jp
 
index 3b82e9e..5c628cf 100644 (file)
@@ -12,6 +12,10 @@ BEGIN {
        print "1..0 # Skip: EBCDIC\n";
        exit 0;
     }
+    unless (PerlIO::Layer->find('perlio')){
+        print "1..0 # Skip: PerlIO required\n";
+        exit 0;
+    }
     $| = 1;
 }
 
@@ -28,8 +32,6 @@ use Test::More tests => 28;
 our $DEBUG = 0;
 
 use Encode (":all");
-eval { require PerlIO::encoding };
-
 {
     no warnings;
     @ARGV and $DEBUG = shift;