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

--- a/MANIFEST
+++ b/MANIFEST
@@ -33,6 +33,8 @@ t/stdin.t
 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
--- a/META.yml
+++ b/META.yml
@@ -8,6 +8,7 @@ author:
 generated_by:        ExtUtils::MakeMaker version 6.42
 distribution_type:   module
 requires:     
+    Digest::MD5: 0
     Carp:                          0
     Exporter:                      0
     Fcntl:                         0
--- /dev/null
+++ b/t/utf8.data
@@ -0,0 +1,3 @@
+hallo grüezi blödel schaß und aus.
+Gregorian: ლრ
+Arabic: ڐڡڠڟڞ
--- /dev/null
+++ b/t/utf8.t
@@ -0,0 +1,44 @@
+#!/usr/bin/perl
+use Test::More;
+use strict;
+use File::Slurp;
+use Encode qw/encode_utf8/;
+use Digest::MD5 qw/md5_hex/;
+use Devel::Peek;
+
+BEGIN {
+	plan skip_all => "Newer Perl doesn't like sysread with utf8 binmode"
+			if $] >= 5.024000;
+}
+
+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);
+
+done_testing;
--- /dev/null
+++ b/t/utf8.t.alt
@@ -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);
+
+
+
+
+
--- a/lib/File/Slurp.pm
+++ b/lib/File/Slurp.pm
@@ -923,6 +923,9 @@ read in binary mode, utf8, etc. See perl
 	my $bin_data = read_file( $bin_file, binmode => ':raw' ) ;
 	my $utf_text = read_file( $bin_file, binmode => ':utf8' ) ;
 
+Please note that using binmode :utf8 with sysread (and thus read_file) 
+has been deprecated in recent versions of perl.
+
 =head3 array_ref
 
 If this boolean option is set, the return value (only in scalar
--- a/t/binmode.t
+++ b/t/binmode.t
@@ -7,7 +7,9 @@ use File::Slurp ;
 
 BEGIN {
 	plan skip_all => 'Older Perl lacking unicode support'
-		if $] < 5.008001 ;
+			if $] < 5.008001 ;
+	plan skip_all => "Newer Perl doesn't like sysread with utf8 binmode"
+			if $] >= 5.024000;
 }
 
 plan tests => 2 ;
