line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
package Mojo::IOLoop::LineReader; |
3
|
|
|
|
|
|
|
$Mojo::IOLoop::LineReader::VERSION = '0.3'; |
4
|
|
|
|
|
|
|
# ABSTRACT: Non-blocking line-oriented input stream |
5
|
|
|
|
|
|
|
|
6
|
5
|
|
|
5
|
|
85519
|
use Mojo::Base 'Mojo::IOLoop::Stream'; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
30
|
|
7
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
865819
|
use Scalar::Util (); |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
1541
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
has 'input_record_separator'; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub new { |
13
|
17
|
|
|
17
|
1
|
123624
|
my $self = shift->SUPER::new(@_); |
14
|
17
|
|
|
|
|
274
|
$self->input_record_separator($/); |
15
|
17
|
|
|
|
|
122
|
return $self->_setup; |
16
|
|
|
|
|
|
|
} |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub _setup { |
19
|
17
|
|
|
17
|
|
23
|
my $self = shift; |
20
|
|
|
|
|
|
|
|
21
|
17
|
|
|
|
|
57
|
Scalar::Util::weaken($self); |
22
|
17
|
|
|
17
|
|
121
|
$self->on(close => sub { shift; $self->_closeln(@_) }); |
|
17
|
|
|
|
|
2537
|
|
|
17
|
|
|
|
|
35
|
|
23
|
17
|
|
|
14
|
|
140
|
$self->on(read => sub { shift; $self->_readln(@_) }); |
|
14
|
|
|
|
|
2609
|
|
|
14
|
|
|
|
|
34
|
|
24
|
|
|
|
|
|
|
|
25
|
17
|
|
|
|
|
77
|
return $self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub _closeln { |
29
|
17
|
|
|
17
|
|
16
|
my ($self) = @_; |
30
|
17
|
100
|
|
|
|
56
|
$self->emit(readln => $self->{lr_chunk}) if length $self->{lr_chunk}; |
31
|
17
|
|
|
|
|
1283
|
$self->{lr_chunk} = ''; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub _readln { |
35
|
14
|
|
|
14
|
|
22
|
my ($self, $bytes) = @_; |
36
|
|
|
|
|
|
|
|
37
|
14
|
|
|
3
|
|
341
|
open my $r, '<', \$bytes; |
|
3
|
|
|
|
|
29
|
|
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
21
|
|
38
|
14
|
|
100
|
|
|
3164
|
my $n = delete $self->{lr_chunk} // ''; |
39
|
14
|
|
|
|
|
38
|
local $/ = $self->input_record_separator; |
40
|
14
|
|
|
|
|
87
|
my $i; |
41
|
14
|
|
|
|
|
69
|
while (<$r>) { |
42
|
12531
|
100
|
|
|
|
13901
|
$n .= $_, next unless $i++; |
43
|
12517
|
|
|
|
|
14210
|
$self->emit(readln => $n); |
44
|
12517
|
|
|
|
|
76753
|
$n = $_; |
45
|
|
|
|
|
|
|
} |
46
|
14
|
100
|
|
|
|
40
|
if (chomp(my $tmp = $n)) { |
47
|
8
|
|
|
|
|
13
|
$self->emit(readln => $n); |
48
|
8
|
|
|
|
|
48
|
$n = ''; |
49
|
|
|
|
|
|
|
} |
50
|
14
|
|
|
|
|
135
|
$self->{lr_chunk} = $n; |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
1; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
__END__ |