Skip to content

Commit

Permalink
made slurp a little smarter
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jun 25, 2012
1 parent 7879d9d commit 6186a49
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/Mojo/ByteStream.pm
Expand Up @@ -71,8 +71,8 @@ sub secure_compare { Mojo::Util::secure_compare ${shift()}, @_ }
sub size { length ${shift()} }

sub slurp {
my $self = shift;
$$self = Mojo::Util::slurp @_;
my ($self, $path) = @_;
$$self = Mojo::Util::slurp $path // $$self;
return $self;
}

Expand Down Expand Up @@ -278,10 +278,13 @@ Size of bytestream.
=head2 C<slurp>
$stream = $stream->slurp;
$stream = $stream->slurp('/etc/passwd');
Alias for L<Mojo::Util/"slurp">.
b('/home/sri/myapp.pl')->slurp->b64_encode->say;
=head2 C<split>
my $collection = $stream->split(',');
Expand Down
4 changes: 3 additions & 1 deletion t/mojo/bytestream.t
Expand Up @@ -5,7 +5,7 @@ use utf8;
# "Homer, we're going to ask you a few simple yes or no questions.
# Do you understand?
# Yes. *lie dectector blows up*"
use Test::More tests => 146;
use Test::More tests => 147;

# MIME::Base64 needs to be loaded first to trigger edge case
use MIME::Base64;
Expand Down Expand Up @@ -408,6 +408,8 @@ $stream = b('whatever')->slurp($file);
is $stream, "test\n% die;\n123\n", 'right content';
$stream = b()->slurp($file)->b64_encode('');
is $stream, 'dGVzdAolIGRpZTsKMTIzCg==', 'right content';
$stream = b($file)->slurp->split("\n")->grep(sub {/die/})->join('');
is $stream, '% die;', 'right content';

# secure_compare
ok b('hello')->secure_compare('hello'), 'values are equal';
Expand Down

0 comments on commit 6186a49

Please sign in to comment.