Author: Alexander Zangerl <az@debian.org>
Subject: binmode fix for multibyte-encoded data

diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' libfile-slurp-perl-9999.19~/MANIFEST libfile-slurp-perl-9999.19/MANIFEST
--- libfile-slurp-perl-9999.19~/MANIFEST	2011-05-24 15:16:12.000000000 +1000
+++ libfile-slurp-perl-9999.19/MANIFEST	2011-08-31 10:17:55.750011076 +1000
@@ -33,6 +33,8 @@
 t/stringify.t
 t/tainted.t
 t/write_file_win32.t
+t/utf8.data
+t/utf8.t
 extras/slurp_bench.pl
 extras/FileSlurp_12.pm
 extras/slurp_article.pod
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' libfile-slurp-perl-9999.19~/META.yml libfile-slurp-perl-9999.19/META.yml
--- libfile-slurp-perl-9999.19~/META.yml	2011-08-31 10:16:49.000000000 +1000
+++ libfile-slurp-perl-9999.19/META.yml	2011-08-31 10:17:12.501430635 +1000
@@ -8,6 +8,7 @@
 generated_by:        ExtUtils::MakeMaker version 6.42
 distribution_type:   module
 requires:     
+    Digest::MD5: 0
     Carp:                          0
     Exporter:                      0
     Fcntl:                         0
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' libfile-slurp-perl-9999.19~/t/utf8.data libfile-slurp-perl-9999.19/t/utf8.data
--- libfile-slurp-perl-9999.19~/t/utf8.data	1970-01-01 10:00:00.000000000 +1000
+++ libfile-slurp-perl-9999.19/t/utf8.data	2011-08-31 10:17:12.501430635 +1000
@@ -0,0 +1,3 @@
+hallo grüezi blödel schaß und aus.
+Gregorian: ლრ
+Arabic: ڐڡڠڟڞ
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' libfile-slurp-perl-9999.19~/t/utf8.t libfile-slurp-perl-9999.19/t/utf8.t
--- libfile-slurp-perl-9999.19~/t/utf8.t	1970-01-01 10:00:00.000000000 +1000
+++ libfile-slurp-perl-9999.19/t/utf8.t	2011-08-31 10:17:12.501430635 +1000
@@ -0,0 +1,40 @@
+#!/usr/bin/perl
+use Test::More tests => 4;
+use strict; 
+use File::Slurp;
+use Encode qw/encode_utf8/;
+use Digest::MD5 qw/md5_hex/;
+use Devel::Peek;
+
+my $digest = 'e30ffef9b0c5623bc1ddd1ba73302f14';
+
+my $utf8 = read_file("t/utf8.data", binmode => ":utf8");
+my $latin = read_file("t/utf8.data");
+
+ok(  Encode::is_utf8($utf8),  "Reading the data file with binmode options results in UTF8 encoded string");
+ok(! Encode::is_utf8($latin), "Reading the data file without options correctly results in unencoded string");
+
+my $ctx1 = new Digest::MD5;
+   $ctx1->add(encode_utf8($utf8));  # encode_utf8 is needed, see http://search.cpan.org/dist/Digest-MD5/MD5.pm
+
+ok($ctx1->hexdigest eq $digest, "The data from the data file we just read came through intact");
+
+
+###
+# Write to a tempfile and rest
+###
+
+my $fn_utf8  = "/tmp/file-slurp-utf8.txt";
+
+write_file($fn_utf8, { binmode => ":utf8" }, $utf8);
+
+open my $fh_utf8, "$fn_utf8" or die "Could not open $fn_utf8: $!\n";
+my $ctx2 = new Digest::MD5;
+   $ctx2->addfile($fh_utf8);
+
+ok($ctx2->hexdigest eq $digest, "The data is written correctly with binmode options");
+
+unlink($fn_utf8);
+
+
+
diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' libfile-slurp-perl-9999.19~/t/utf8.t.alt libfile-slurp-perl-9999.19/t/utf8.t.alt
--- libfile-slurp-perl-9999.19~/t/utf8.t.alt	1970-01-01 10:00:00.000000000 +1000
+++ libfile-slurp-perl-9999.19/t/utf8.t.alt	2011-08-31 10:17:12.502430579 +1000
@@ -0,0 +1,19 @@
+use Test::More tests => 1;
+use strict; 
+use File::Slurp;
+my $fn="/tmp/utf8.txt";
+
+my $data="hallo grezi bldel scha und aus.\n";
+open F,">$fn";
+binmode(F, ":utf8");
+print F $data;
+close F;
+
+my $x=read_file($fn,binmode=>":utf8");
+ok($x eq $data,"utf8 encoded data survives slurp");
+unlink($fn);
+
+
+
+
+
