Navigation Menu

Skip to content

Commit

Permalink
separate the three cases
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Feb 5, 2017
1 parent 49f3f78 commit f85c841
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions lib/Mojo/Asset/File.pm
Expand Up @@ -10,14 +10,16 @@ has [qw(cleanup path)];
has handle => sub {
my $self = shift;

# Enable automatic cleanup if the file has to be created
# Open existing file
my $path = $self->path;
$self->cleanup(1) if !defined $self->cleanup && (!defined $path || !-e $path);
return Mojo::File->new($path)->open('<') if defined $path && -e $path;

# Open existing file
return Mojo::File->new($path)->open(-e $path ? '<' : '+>>') if defined $path;
$self->cleanup(1) unless defined $self->cleanup;

# Create a specific file
return Mojo::File->new($path)->open('+>>') if defined $path;

# Open new or temporary file
# Create a temporary file
my $template = 'mojo.tmp.XXXXXXXXXXXXXXXX';
my $file = tempfile DIR => $self->tmpdir, TEMPLATE => $template, UNLINK => 0;
$self->path($file->to_string);
Expand Down
4 changes: 2 additions & 2 deletions lib/Mojo/File.pm
Expand Up @@ -328,9 +328,9 @@ directory.
=head2 open
my $handle = $path->open('<');
my $handle = $path->open('+<');
Open the file with L<IO::File>.
Open file with L<IO::File>.
=head2 remove_tree
Expand Down

0 comments on commit f85c841

Please sign in to comment.