Skip to content

Commit

Permalink
improve portability of slurp function in Mojo::Util
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Aug 31, 2015
1 parent 20bb97d commit 1c448e3
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.18 2015-08-29
6.18 2015-08-31
- Improved portability of slurp function in Mojo::Util.
- Fixed Makefile.PL to be compliant with version 2 of the CPAN distribution
metadata specification. (Grinnz)

Expand Down
7 changes: 5 additions & 2 deletions lib/Mojo/Util.pm
Expand Up @@ -233,9 +233,12 @@ sub sha1_sum { sha1_hex @_ }

sub slurp {
my $path = shift;

open my $file, '<', $path or croak qq{Can't open file "$path": $!};
defined $file->sysread(my $content, -s $file, 0)
or croak qq{Can't read from file "$path": $!};
my $ret = my $content = '';
while ($ret = $file->sysread(my $buffer, 131072, 0)) { $content .= $buffer }
croak qq{Can't read from file "$path": $!} unless defined $ret;

return $content;
}

Expand Down

0 comments on commit 1c448e3

Please sign in to comment.