blib/lib/Mojo/IOLoop/LineReader.pm

filter: Statementstmt 100% 37 / 37 Branchbran 100% 8 / 8 Conditioncond 100% 2 / 2 MC/DCmcdc 100% 1 / 1 Subroutinesub 100% 8 / 8 Podpod 100% 1 / 1 totaltotal 100% 57 / 57 CC 6 SCAR 9.9
CC
6
Cov
100%
_readln
5.0
_closeln
2.0
BEGIN
1.0
CRAP 2.7
↑ Summary
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
BranchTrueFalseTotal
if length $self->{"lr_chunk"} 4 13 17
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"} // ""
l!l
212
MC/DC100%1/1
delete $self->{"lr_chunk"} // ""
delete $self->{"lr_chunk"}
Truth table100%2/2
A
A= delete $self->{"lr_chunk"}
Aresult
11
00
39 14 local $/ = $self->input_record_separator;
40 14 my $i;
41 14 ▶ while (<$r>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $r)) 12531 14 12545
42 12531 ▶ $n .= $_, next unless $i++;
Branch: 1 branch
BranchTrueFalseTotal
unless $i++ 14 12517 12531
43 12517 $self->emit(readln => $n);
44 12517 $n = $_;
45 }
46 14 ▶ if (chomp(my $tmp = $n)) {
Branch: 1 branch
BranchTrueFalseTotal
if (chomp(my $tmp = $n)) 8 6 14
47 8 $self->emit(readln => $n);
48 8 $n = '';
49 }
50 14 $self->{lr_chunk} = $n;
51 }
52  
53 5 1;
54  
55 __END__
↑ Summary