Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/grinnz/mojo-ioloop-stream-role-linebuffer
Mojo::IOLoop::Stream::Role::LineBuffer - Read and write streams by lines
https://github.com/grinnz/mojo-ioloop-stream-role-linebuffer
Last synced: 5 days ago
JSON representation
Mojo::IOLoop::Stream::Role::LineBuffer - Read and write streams by lines
- Host: GitHub
- URL: https://github.com/grinnz/mojo-ioloop-stream-role-linebuffer
- Owner: Grinnz
- License: other
- Created: 2018-03-25T03:07:59.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-11-09T01:31:58.000Z (about 3 years ago)
- Last Synced: 2024-11-13T05:42:28.992Z (about 2 months ago)
- Language: Perl
- Homepage: https://metacpan.org/pod/Mojo::IOLoop::Stream::Role::LineBuffer
- Size: 45.9 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.pod
- Changelog: Changes
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
=pod
=head1 NAME
Mojo::IOLoop::Stream::Role::LineBuffer - Read and write streams by lines
=head1 SYNOPSIS
use Mojo::IOLoop;
Mojo::IOLoop->client({port => 3000} => sub {
my ($loop, $err, $stream) = @_;
$stream->with_roles('+LineBuffer')->watch_lines->on(read_line => sub {
my ($stream, $line) = @_;
say "Received line: $line";
$stream->write_line('Line received');
});
});=head1 DESCRIPTION
L composes the method
L"watch_lines"> which causes a L object to emit the
L"read_line"> event for each line received. The L"write_line"> method is
also provided to add a line separator to the passed data before writing.=head1 EVENTS
L can emit the following events.
=head2 read_line
$stream->on(read_line => sub {
my ($stream, $line, $separator) = @_;
...
});Emitted when a line ending in L"read_line_separator"> arrives on the stream,
and when the stream closes if data is still buffered. The separator is passed
as a separate argument if present.=head1 ATTRIBUTES
L composes the following attributes.
=head2 read_line_separator
my $separator = $stream->read_line_separator;
$stream = $stream->read_line_separator(qr/\x0D\x0A/);Regular expression to indicate new lines in received bytes. Defaults to a
newline (LF) character optionally preceded by a CR character (C<\x0D?\x0A>).
Note that if you set this to L or
C<\v> (vertical whitespace), this may match the CR character of a CR/LF
sequence and consider the LF as a separate line if they are read separately.=head2 write_line_separator
my $separator = $stream->write_line_separator;
$stream = $stream->write_line_separator("\x0A");Byte sequence to indicate new lines in data written with L"write_line">.
Defaults to the network newline CR/LF (C<\x0D\x0A>).=head1 METHODS
L composes the following methods.
=head2 watch_lines
$stream = $stream->watch_lines;
Subscribe to the L and
L events, to buffer received bytes and emit
L"read_line"> when L"read_line_separator"> is encountered or the stream is
closed with buffered data.=head2 write_line
$stream = $stream->write_line($bytes);
$stream = $stream->write_line($bytes => sub {...});Write a line to the stream by appending L"write_line_separator"> to the data.
The optional drain callback will be executed once all data has been written.=head1 BUGS
Report any issues on the public bugtracker.
=head1 AUTHOR
Dan Book
=head1 COPYRIGHT AND LICENSE
This software is Copyright (c) 2018 by Dan Book.
This is free software, licensed under:
The Artistic License 2.0 (GPL Compatible)
=head1 SEE ALSO
L, L, L,
L=cut