Skip to content

Instantly share code, notes, and snippets.

@ugexe
Created March 20, 2016 17:24
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 ugexe/fb1b470fc07650400c98 to your computer and use it in GitHub Desktop.
Save ugexe/fb1b470fc07650400c98 to your computer and use it in GitHub Desktop.
my role IO::Streamable::Socket[*%connect-opts] {
# Fake enough of the interface to be viable
has $.socket;
has $!IO handles 'slurp-rest';
method open {
$!IO //= do {
my $tmpfile = $*TMPDIR.child("{time}.{$*PID}");
$!socket.?connect(|%connect-opts);
$!socket.?send('possible handshake/init stuff');
$tmpfile.spurt: $!socket.recv(:bin);
$tmpfile;
}
}
}
my $h = IO::Handle.new(:path('-')) but IO::Streamable::Socket[:host<localhost>];
...; $h.open.slurp-rest;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment