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; |
12fb4a80 |
6 | use Object::Remote::ReadChannel; |
9e72f0cf |
7 | use Moo; |
8 | |
9 | sub 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 | |
26 | 1; |
4e25b1fd |
27 | |
28 | =head1 NAME |
29 | |
8dbf62a5 |
30 | Object::Remote::Connector::STDIO - A connector used in remote OR nodes |
31 | |
32 | =head1 DESCRIPTION |
33 | |
34 | This connector only exists to provide L<Object:Remote::Node> with a connection |
35 | that handles its OR JSON command and response processing. Reads from STDIN and |
36 | prints to STDOUT. |
4e25b1fd |
37 | |
38 | =head1 ARGUMENTS |
39 | |
8dbf62a5 |
40 | Provides no arguments. However the adventurous can replace STDIN/STDOUT of the |
41 | current process with other filehandles. |
4e25b1fd |
42 | |
43 | =cut |