Commit | Line | Data |
9e72f0cf |
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: $!"; |
9d804009 |
15 | open STDIN, '<', File::Spec->devnull or die "Re-opening stdin: $!"; |
9e72f0cf |
16 | close STDOUT or die "Closing stdout: $!"; |
9d804009 |
17 | open STDOUT, '>', File::Spec->devnull or die "Re-opening stdout: $!"; |
47c83a13 |
18 | return Object::Remote::Connection->new( |
9e72f0cf |
19 | send_to_fh => $stdout, |
20 | receive_from_fh => $stdin |
21 | ); |
22 | } |
23 | |
24 | 1; |