Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
document and test all open variants
  • Loading branch information
kraih committed Feb 5, 2017
1 parent f85c841 commit 62d0440
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/Mojo/File.pm
Expand Up @@ -16,7 +16,7 @@ use File::Path ();
use File::Spec::Functions
qw(abs2rel canonpath catfile file_name_is_absolute rel2abs splitdir);
use File::Temp ();
use IO::File;
use IO::File ();
use Mojo::Collection;

our @EXPORT_OK = ('path', 'tempdir', 'tempfile');
Expand Down Expand Up @@ -329,6 +329,9 @@ directory.
=head2 open
my $handle = $path->open('+<');
my $handle = $path->open('r+');
my $handle = $path->open(O_RDWR);
my $handle = $path->open('<:encoding(UTF-8)');
Open file with L<IO::File>.
Expand Down
9 changes: 9 additions & 0 deletions t/mojo/file.t
Expand Up @@ -2,10 +2,12 @@ use Mojo::Base -strict;

use Test::More;
use Cwd 'getcwd';
use Fcntl 'O_RDONLY';
use File::Basename qw(basename dirname);
use File::Spec::Functions qw(abs2rel canonpath catfile rel2abs splitdir);
use File::Temp;
use Mojo::File qw(path tempdir tempfile);
use Mojo::Util 'encode';

# Constructor
is(Mojo::File->new, canonpath(getcwd), 'same path');
Expand Down Expand Up @@ -79,6 +81,13 @@ $file = tempfile;
$file->spurt("test\n123\n");
my $handle = $file->open('<');
is_deeply [<$handle>], ["test\n", "123\n"], 'right structure';
$handle = $file->open('r');
is_deeply [<$handle>], ["test\n", "123\n"], 'right structure';
$handle = $file->open(O_RDONLY);
is_deeply [<$handle>], ["test\n", "123\n"], 'right structure';
$file->spurt(encode('UTF-8', ''));
$handle = $file->open('<:encoding(UTF-8)');
is_deeply [<$handle>], [''], 'right structure';

# Make path
$dir = tempdir;
Expand Down

0 comments on commit 62d0440

Please sign in to comment.