App-FileSync
view release on metacpan or search on metacpan
lib/App/FileSync/Transport/Local.pm view on Meta::CPAN
Side Effects: starts C<$^X server_bin --root ... --repo ... --client ...
--role ...>. The child's standard error is the parent's, never the protocol
pipe: sharing it would put diagnostics into the protocol stream.
Usage:
my $transport = App::FileSync::Transport::Local->new(%args);
=head3 EXAMPLE
my $t = App::FileSync::Transport::Local->new(root => $root, repo => 'docs', client => 'test-1');
print {$t->writer} ...;
=head3 API SPECIFICATION
=head4 INPUT
{
root => { type => 'string', min => 1 },
repo => { type => 'string', min => 1 },
client => { type => 'string', min => 1 },
role => { type => 'string', optional => 1 },
server_bin => { type => 'string', optional => 1 },
}
=head4 OUTPUT
{ type => 'object', isa => 'App::FileSync::Transport::Local' }
=head3 MESSAGES
Key Meaning Resolution
transport.missing root, repo or client absent pass it
=head3 FORMAL SPECIFICATION
new(a) â â child ⢠argv(child) = â¨perl, bin, --root, a.root, --repo, a.repo, --client, a.client, --role, roleâ©
=cut
sub new {
my $class = shift;
my $args = named(\@_, {
map({ $_ => { type => 'string', optional => 1 } } qw(root repo client role server_bin)),
}, 'Transport::Local->new');
for my $required (qw(root repo client)) {
throw('transport.missing', { transport => 'Local', what => $required })
unless defined $args->{$required} && length $args->{$required};
}
my @command = (
$^X, $args->{server_bin} || _default_server_bin(),
'--root', $args->{root},
'--repo', $args->{repo},
'--client', $args->{client},
'--role', $args->{role} || $ROLE_CLIENT,
);
# The child's stderr is a dup of ours. A pipe here would not be read, and
# the first log line would kill the server with SIGPIPE.
my $child = App::FileSync::Process::spawn(command => \@command, stderr => fileno(STDERR));
return bless { %{$child} }, $class;
}
=head2 reader
Documented with L</writer> below.
=head2 writer
Purpose: the pipes to and from the server.
Args: none.
Returns: the read handle (server's stdout) or write handle (its stdin).
Side Effects: none.
Usage:
my $in = $transport->reader;
=head3 EXAMPLE
App::FileSync::Protocol->new(in => $t->reader, out => $t->writer);
=head3 API SPECIFICATION
=head4 INPUT
[ { name => 'self', type => 'object' } ]
=head4 OUTPUT
{ type => 'object' }
=head3 MESSAGES
None.
=head3 FORMAL SPECIFICATION
reader = self.reader ; writer = self.writer
=cut
sub reader {
my ($self) = @_;
return $self->{reader};
}
sub writer {
my ($self) = @_;
return $self->{writer};
}
=head2 close
( run in 1.139 second using v1.01-cache-2.11-cpan-60884a8df76 )