Skip to content

Commit

Permalink
improve slurp method in Mojo::Asset::File to only use one file descri…
Browse files Browse the repository at this point in the history
…ptor
  • Loading branch information
kraih committed Aug 21, 2015
1 parent 6d1e9cf commit ec7920e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
3 changes: 2 additions & 1 deletion Changes
@@ -1,5 +1,6 @@

6.17 2015-08-20
6.17 2015-08-21
- Improved slurp method in Mojo::Asset::File to only use one file descriptor.

6.16 2015-08-19
- Improved check_box, radio_button and select_field tag helpers to handle the
Expand Down
7 changes: 5 additions & 2 deletions lib/Mojo/Asset/File.pm
Expand Up @@ -124,8 +124,11 @@ sub mtime { (stat shift->handle)[9] }
sub size { -s shift->handle }

sub slurp {
return '' unless defined(my $file = shift->path);
return Mojo::Util::slurp $file;
my $handle = shift->handle;
$handle->sysseek(0, SEEK_SET);
defined $handle->sysread(my $content, -s $handle, 0)
or croak qq{Can't read from asset: $!};
return $content;
}

1;
Expand Down

0 comments on commit ec7920e

Please sign in to comment.