import initial sketch of Object::Remote
[scpubgit/Object-Remote.git] / lib / Object / Remote / Connector / STDIO.pm
1 package Object::Remote::Connector::STDIO;
2
3 use File::Spec;
4 use Object::Remote::Connection;
5 use Moo;
6
7 sub connect {
8   open my $stdin, '<&', \*STDIN or die "Duping stdin: $!";
9   open my $stdout, '>&', \*STDOUT or die "Duping stdout: $!";
10   $stdout->autoflush(1);
11   # if we don't re-open them then 0 and 1 get re-used - which is not
12   # only potentially bloody confusing but results in warnings like:
13   # "Filehandle STDOUT reopened as STDIN only for input"
14   close STDIN or die "Closing stdin: $!";
15   open STDIN, '<', File::Spec->dev_null or die "Re-opening stdin: $!";
16   close STDOUT or die "Closing stdout: $!";
17   open STDOUT, '>', File::Spec->dev_null or die "Re-opening stdout: $!";
18   Object::Remote::Connection->new(
19     send_to_fh => $stdout,
20     receive_from_fh => $stdin
21   );
22 }
23
24 1;