Change 11249 by jhi@alpha on 2001/07/10 03:50:18
Add a test for for PerlIO ":encoding(...)" layer.
Affected files ...
... //depot/perl/MANIFEST#497 edit
... //depot/perl/ext/Encode/Encode.pm#31 edit
... //depot/perl/ext/PerlIO/t/encoding.t#1 add
Differences ...
==== //depot/perl/MANIFEST#497 (text) ====
Index: perl/MANIFEST
--- perl/MANIFEST.~1~ Mon Jul 9 22:00:06 2001
+++ perl/MANIFEST Mon Jul 9 22:00:06 2001
@@ -426,6 +426,7 @@
ext/PerlIO/Scalar/Makefile.PL PerlIO layer for scalars
ext/PerlIO/Scalar/Scalar.pm PerlIO layer for scalars
ext/PerlIO/Scalar/Scalar.xs PerlIO layer for scalars
+ext/PerlIO/t/encoding.t See if PerlIo encoding conversion works
ext/PerlIO/t/scalar.t Test of PerlIO::Scalar
ext/PerlIO/Via/Makefile.PL PerlIO layer for layers in perl
ext/PerlIO/Via/Via.pm PerlIO layer for layers in perl
==== //depot/perl/ext/Encode/Encode.pm#31 (text) ====
Index: perl/ext/Encode/Encode.pm
--- perl/ext/Encode/Encode.pm.~1~ Mon Jul 9 22:00:06 2001
+++ perl/ext/Encode/Encode.pm Mon Jul 9 22:00:06 2001
@@ -739,9 +739,15 @@
C<Encode> provides a "layer" (See L<perliol>) which can transform
data as it is read or written.
+Here is how the blind poet would modernise the encoding:
+
use Encode;
- open(my $ilyad,'>:encoding(iso-8859-7)','ilyad.greek');
- print $ilyad @epic;
+ open(my $iliad,'<:encoding(iso-8859-7)','iliad.greek');
+ open(my $utf8,'>:utf8','iliad.utf8');
+ my @epic = <$iliad>;
+ print $utf8 @epic;
+ close($utf8);
+ close($illiad);
In addition the new IO system can also be configured to read/write
UTF-8 encoded characters (as noted above this is efficient):
==== //depot/perl/ext/PerlIO/t/encoding.t#1 (text) ====
Index: perl/ext/PerlIO/t/encoding.t
--- perl/ext/PerlIO/t/encoding.t.~1~ Mon Jul 9 22:00:06 2001
+++ perl/ext/PerlIO/t/encoding.t Mon Jul 9 22:00:06 2001
@@ -0,0 +1,49 @@
+my $grk = "grk$$";
+my $utf = "utf$$";
+
+if (open(GRK, ">$grk")) {
+ # alpha beta gamma in ISO 8859-7
+ print GRK "\xe1\xe2\xe3";
+ close GRK;
+}
+
+{
+ use Encode;
+ open(my $i,'<:encoding(iso-8859-7)',$grk);
+ print "ok 1\n";
+ open(my $o,'>:utf8',$utf);
+ print "ok 2\n";
+ print $o readline($i);
+ print "ok 3\n";
+ close($o);
+ close($i);
+}
+
+if (open(UTF, "<$utf")) {
+ # alpha beta gamma in UTF-8 Unicode (0x3b1 0x3b2 0x3b3)
+ print "not " unless <UTF> eq "\xce\xb1\xce\xb2\xce\xb3";
+ print "ok 4\n";
+ close $grk;
+}
+
+{
+ use Encode;
+ open(my $i,'<:utf8',$utf);
+ print "ok 5\n";
+ open(my $o,'>:encoding(iso-8859-7)',$grk);
+ print "ok 6\n";
+ print $o readline($i);
+ print "ok 7\n";
+ close($o);
+ close($i);
+}
+
+if (open(GRK, "<$grk")) {
+ print "not " unless <GRK> eq "\xe1\xe2\xe3";
+ print "ok 8\n";
+ close $grk;
+}
+
+END {
+ unlink($grk, $utf);
+}
End of Patch.