Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes ingydotnet/io-all-pm#93: -utf8 not applied everywhere. #98

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/IO/All/File.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ sub assert_tied_file {
if $@;
my $array_ref = do { my @array; \@array };
my $name = $self->pathname;
my @options = $self->_rdonly ? (mode => O_RDONLY) : ();
my @options;
push @options, (recsep => $self->separator);
push @options, (mode => O_RDONLY) if $self->_rdonly;
push @options, (discipline => join('', grep {defined} @{$self->_layers}));
tie @$array_ref, 'Tie::File', $name, @options;
$self->throw("Can't tie 'Tie::File' to '$name':\n$!")
unless tied @$array_ref;
Expand Down
23 changes: 18 additions & 5 deletions test/tie_file.t
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,34 @@ my $t; use lib ($t = -e 't' ? 't' : 'test');
use Test::More;
use IO_All_Test;
use IO::All;
use open qw(:std :utf8);
use utf8;

plan((eval {require Tie::File; 1})
? (tests => 2)
? (tests => 4)
: (skip_all => "requires Tie::File")
);

{
(io(o_dir() . '/tie_file1') < io("$t/tie_file.t"))->close;
(io(o_dir() . '/tie_file1') < io($0))->close;
my $file = io(o_dir() . '/tie_file1')->rdonly;
is($file->[-1], 'bar');
is($file->[-2], 'foo');

"foo\n" x 3 > io(o_dir() . '/tie_file2');
io(o_dir() . '/tie_file2')->[1] = 'bar';
}
$file = io(o_dir() . '/tie_file2');
$file->[1] = 'bar';

$file = io(o_dir() . '/tie_file2')->utf8;
push @{$file}, 'åäöüß';

is ($file->size, 23, "file size with UTF-8 chars");

is ($file->all, <<EOT, "UTF-8 content");
foo
bar
foo
åäöüß
EOT

del_output_dir();

Expand Down