Skip to content

Instantly share code, notes, and snippets.

@jberger
Created August 31, 2015 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jberger/2d8e7767b1bd470c8551 to your computer and use it in GitHub Desktop.
Save jberger/2d8e7767b1bd470c8551 to your computer and use it in GitHub Desktop.
use Mojo::Base -strict;
use Test::More;
use Mojo::Util qw/slurp spurt/;
package My::Handle {
use parent 'IO::File';
use overload '-X' => sub {
my ($self, $op) = @_;
if ($op eq 's') { return 0 }
die "-$op unimplemented";
};
}
use File::Temp ();
my $tmp = File::Temp->new;
spurt 'lalala' => $tmp->filename;
my $h = My::Handle->new;
$h->open($tmp->filename, '<');
is -s($h), 0, 'correct mock size';
BEGIN { *CORE::GLOBAL::open = sub { $tmp } }
is slurp($tmp->filename), 'lalala', 'correct content';
done_testing;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment