Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
change return value of move_to method
  • Loading branch information
kraih committed Jan 7, 2017
1 parent a9f4983 commit 2808cf5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/Mojo/File.pm
Expand Up @@ -71,7 +71,7 @@ sub move_to {
my ($self, $to) = @_;
File::Copy::move($$self, $to)
or croak qq{Can't move file "$$self" to "$to": $!};
return $self->new($to);
return $self;
}

sub new {
Expand Down Expand Up @@ -284,10 +284,9 @@ Create the given directories if they don't exist already with L<File::Path>.
=head2 move_to
my $destination = $path->move_to('/home/sri/.vimrc.backup');
$path = $path->move_to('/home/sri/.vimrc.backup');
Move a file with L<File::Copy> and return a new L<Mojo::File> object for the
destination path.
Move file with L<File::Copy>.
=head2 new
Expand Down
10 changes: 10 additions & 0 deletions t/mojo/file.t
Expand Up @@ -60,6 +60,16 @@ ok !-d $subdir, 'directory does not exist anymore';
$subdir->make_path;
ok -d $subdir, 'directory exists';

# Move to
$dir = tempdir;
my $destination = $dir->child('dest.txt');
my $source = $dir->child('src.txt')->spurt('works!');
ok -f $source, 'file exists';
ok !-f $destination, 'file does not exists';
ok !-f $source->move_to($destination), 'file no longer exists';
ok -f $destination, 'file exists';
is $destination->slurp, 'works!', 'right content';

# List
is_deeply path('does_not_exist')->list->to_array, [], 'no files';
is_deeply path(__FILE__)->list->to_array, [], 'no files';
Expand Down

0 comments on commit 2808cf5

Please sign in to comment.