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