| 1 | |||||||||||||
| 2 | package Mojo::IOLoop::LineReader; | ||||||||||||
| 3 | 5 | $Mojo::IOLoop::LineReader::VERSION = '0.3'; | |||||||||||
| 4 | # ABSTRACT: Non-blocking line-oriented input stream | ||||||||||||
| 5 | |||||||||||||
| 6 | 5 | ▶ | use Mojo::Base 'Mojo::IOLoop::Stream'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | |||||||||||||
| 8 | 5 | ▶ | use Scalar::Util (); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 9 | |||||||||||||
| 10 | 5 | has 'input_record_separator'; | |||||||||||
| 11 | |||||||||||||
| 12 | 17 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 13 | 17 | my $self = shift->SUPER::new(@_); | |||||||||||
| 14 | 17 | $self->input_record_separator($/); | |||||||||||
| 15 | 17 | return $self->_setup; | |||||||||||
| 16 | } | ||||||||||||
| 17 | |||||||||||||
| 18 | 17 | ▶ | sub _setup { | ||||||||||
|
Subroutine
_setup: called CC=1 SCAR=0.0
| |||||||||||||
| 19 | 17 | my $self = shift; | |||||||||||
| 20 | |||||||||||||
| 21 | 17 | Scalar::Util::weaken($self); | |||||||||||
| 22 | 17 | ▶ | $self->on(close => sub { shift; $self->_closeln(@_) }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 23 | 17 | ▶ | $self->on(read => sub { shift; $self->_readln(@_) }); | ||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||
| 24 | |||||||||||||
| 25 | 17 | return $self; | |||||||||||
| 26 | } | ||||||||||||
| 27 | |||||||||||||
| 28 | 17 | ▶ | sub _closeln { | ||||||||||
|
Subroutine
_closeln: called CC=2 SCAR=6.9
| |||||||||||||
| 29 | 17 | my ($self) = @_; | |||||||||||
| 30 | 17 | ▶ | $self->emit(readln => $self->{lr_chunk}) if length $self->{lr_chunk}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 31 | 17 | $self->{lr_chunk} = ''; | |||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 14 | ▶ | sub _readln { | ||||||||||
|
Subroutine
_readln: called CC=5 SCAR=16.1
| |||||||||||||
| 35 | 14 | my ($self, $bytes) = @_; | |||||||||||
| 36 | |||||||||||||
| 37 | 14 | open my $r, '<', \$bytes; | |||||||||||
| 38 | 14 | ▶ | my $n = delete $self->{lr_chunk} // ''; | ||||||||||
|
Condition100%2/2
delete $self->{"lr_chunk"} // ""
MC/DC100%1/1
delete $self->{"lr_chunk"} // ""
delete $self->{"lr_chunk"}
Truth table100%2/2
A
A= delete $self->{"lr_chunk"}
| |||||||||||||
| 39 | 14 | local $/ = $self->input_record_separator; | |||||||||||
| 40 | 14 | my $i; | |||||||||||
| 41 | 14 | ▶ | while (<$r>) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 42 | 12531 | ▶ | $n .= $_, next unless $i++; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 43 | 12517 | $self->emit(readln => $n); | |||||||||||
| 44 | 12517 | $n = $_; | |||||||||||
| 45 | } | ||||||||||||
| 46 | 14 | ▶ | if (chomp(my $tmp = $n)) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 47 | 8 | $self->emit(readln => $n); | |||||||||||
| 48 | 8 | $n = ''; | |||||||||||
| 49 | } | ||||||||||||
| 50 | 14 | $self->{lr_chunk} = $n; | |||||||||||
| 51 | } | ||||||||||||
| 52 | |||||||||||||
| 53 | 5 | 1; | |||||||||||
| 54 | |||||||||||||
| 55 | __END__ | ||||||||||||