| 1 | package Tak::STDIOSetup; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Log::Contextual qw(:log); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Log::Contextual::SimpleLogger; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use Tak::ConnectionService; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Tak::Router; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use Tak; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use IO::Handle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use strictures 1; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | sub run { | ||||||||||
| 12 | 0 | ▶ | open my $stdin, '<&', \*STDIN or die "Duping stdin: $!"; | ||||||||
|
Subroutine
run: not called CC=8 SCAR=42.8
Pod
undocumented
Branch: 1 branch
| |||||||||||
| 13 | 0 | ▶ | open my $stdout, '>&', \*STDOUT or die "Duping stdout: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 14 | 0 | $stdout->autoflush(1); | |||||||||
| 15 | # if we don't re-open them then 0 and 1 get re-used - which is not | ||||||||||
| 16 | # only potentially bloody confusing but results in warnings like: | ||||||||||
| 17 | # "Filehandle STDOUT reopened as STDIN only for input" | ||||||||||
| 18 | 0 | ▶ | close STDIN or die "Closing stdin: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | 0 | ▶ | open STDIN, '<', '/dev/null' or die "Re-opening stdin: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 0 | ▶ | close STDOUT or die "Closing stdout: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 0 | ▶ | open STDOUT, '>', '/dev/null' or die "Re-opening stdout: $!"; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 0 | my ($host, $level) = @ARGV; | |||||||||
| 23 | 0 | my $sig = '<'.join ':', $host, $$.'> '; | |||||||||
| 24 | Log::Contextual::set_logger( | ||||||||||
| 25 | Log::Contextual::SimpleLogger->new({ | ||||||||||
| 26 | levels_upto => $level, | ||||||||||
| 27 | 0 | ▶ | coderef => sub { print STDERR $sig, @_; } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 28 | }) | ||||||||||
| 29 | 0 | ); | |||||||||
| 30 | 0 | my $done; | |||||||||
| 31 | my $connection = Tak::ConnectionService->new( | ||||||||||
| 32 | read_fh => $stdin, write_fh => $stdout, | ||||||||||
| 33 | listening_service => Tak::Router->new, | ||||||||||
| 34 | 0 | ▶ | on_close => sub { $done = 1 } | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 35 | 0 | ); | |||||||||
| 36 | 0 | $connection->receiver->service->register_weak(remote => $connection); | |||||||||
| 37 | 0 | $0 = 'tak-stdio-node'; | |||||||||
| 38 | 0 | ▶ | log_debug { "Node starting" }; | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 39 | # Tell the other end that we've finished messing around with file | ||||||||||
| 40 | # descriptors and that it's therefore safe to start sending requests. | ||||||||||
| 41 | 0 | print $stdout "Ssyshere\n"; | |||||||||
| 42 | 0 | Tak->loop_until($done); | |||||||||
| 43 | 0 | ▶ | if (our $Next) { goto &$Next } | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 1 | 1; | |||||||||