create ReadChannel object to allow moving Shere logic into connect
[scpubgit/Object-Remote.git] / lib / Object / Remote / Connector / STDIO.pm
CommitLineData
9e72f0cf 1package Object::Remote::Connector::STDIO;
2
3use File::Spec;
4c8c83d7 4use IO::Handle;
9e72f0cf 5use Object::Remote::Connection;
12fb4a80 6use Object::Remote::ReadChannel;
9e72f0cf 7use Moo;
8
9sub connect {
10 open my $stdin, '<&', \*STDIN or die "Duping stdin: $!";
11 open my $stdout, '>&', \*STDOUT or die "Duping stdout: $!";
12 $stdout->autoflush(1);
13 # if we don't re-open them then 0 and 1 get re-used - which is not
14 # only potentially bloody confusing but results in warnings like:
15 # "Filehandle STDOUT reopened as STDIN only for input"
16 close STDIN or die "Closing stdin: $!";
9d804009 17 open STDIN, '<', File::Spec->devnull or die "Re-opening stdin: $!";
9e72f0cf 18 close STDOUT or die "Closing stdout: $!";
9d804009 19 open STDOUT, '>', File::Spec->devnull or die "Re-opening stdout: $!";
47c83a13 20 return Object::Remote::Connection->new(
9e72f0cf 21 send_to_fh => $stdout,
12fb4a80 22 read_channel => Object::Remote::ReadChannel->new(fh => $stdin)
9e72f0cf 23 );
24}
25
261;