| 1 | package Message::Passing::Input::STDIN; | ||||||||||
| 2 | 4 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use AnyEvent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 4 | ▶ | use Try::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 4 | ▶ | use Scalar::Util qw/ weaken /; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 4 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 4 | ▶ | use IO::Handle; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 4 | with qw/ | |||||||||
| 10 | Message::Passing::Role::Input | ||||||||||
| 11 | /; | ||||||||||
| 12 | |||||||||||
| 13 | has reader => ( | ||||||||||
| 14 | is => 'ro', | ||||||||||
| 15 | lazy => 1, | ||||||||||
| 16 | default => sub { | ||||||||||
| 17 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=4.1
| |||||||||||
| 18 | 4 | weaken($self); | |||||||||
| 19 | AnyEvent->io(fh => \*STDIN, poll => 'r', cb => sub { | ||||||||||
| 20 | 0 | ▶ | exit 0 if STDIN->eof; | ||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
Branch: 1 branch
| |||||||||||
| 21 | 0 | my $input = <STDIN>; | |||||||||
| 22 | 0 | ▶ | return unless defined $input; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | chomp($input); | |||||||||
| 24 | 0 | ▶ | return unless length $input; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 25 | 0 | $self->output_to->consume($input); | |||||||||
| 26 | 4 | }); | |||||||||
| 27 | }, | ||||||||||
| 28 | 4 | ); | |||||||||
| 29 | |||||||||||
| 30 | sub BUILD { | ||||||||||
| 31 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
BUILD: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 32 | 4 | $self->reader; | |||||||||
| 33 | } | ||||||||||
| 34 | |||||||||||
| 35 | |||||||||||
| 36 | 4 | 1; | |||||||||
| 37 | |||||||||||
| 38 | =head1 NAME | ||||||||||
| 39 | |||||||||||
| 40 | Message::Passing::Input::STDIN - STDIN input | ||||||||||
| 41 | |||||||||||
| 42 | =head1 SYNOPSIS | ||||||||||
| 43 | |||||||||||
| 44 | message-pass --input STDIN --output STDOUT | ||||||||||
| 45 | {"foo": "bar"} | ||||||||||
| 46 | {"foo":"bar"} | ||||||||||
| 47 | |||||||||||
| 48 | =head1 DESCRIPTION | ||||||||||
| 49 | |||||||||||
| 50 | An input which gets messages from STDIN. | ||||||||||
| 51 | |||||||||||
| 52 | Messages are expected to be c<\n> separated, and if EOF is encountered | ||||||||||
| 53 | then this input will call C<exit> to terminate the program. | ||||||||||
| 54 | |||||||||||
| 55 | =head1 SEE ALSO | ||||||||||
| 56 | |||||||||||
| 57 | L<Message::Passing> | ||||||||||
| 58 | |||||||||||
| 59 | =head1 SPONSORSHIP | ||||||||||
| 60 | |||||||||||
| 61 | This module exists due to the wonderful people at Suretec Systems Ltd. | ||||||||||
| 62 | <http://www.suretecsystems.com/> who sponsored its development for its | ||||||||||
| 63 | VoIP division called SureVoIP <http://www.surevoip.co.uk/> for use with | ||||||||||
| 64 | the SureVoIP API - | ||||||||||
| 65 | <http://www.surevoip.co.uk/support/wiki/api_documentation> | ||||||||||
| 66 | |||||||||||
| 67 | =head1 AUTHOR, COPYRIGHT AND LICENSE | ||||||||||
| 68 | |||||||||||
| 69 | See L<Message::Passing>. | ||||||||||
| 70 | |||||||||||
| 71 | =cut | ||||||||||
| 72 | |||||||||||