line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FSP::Handle::Read; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
26
|
|
3
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use Net::FSP::Handle qw/do_or_fail/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
64
|
|
6
|
1
|
|
|
1
|
|
23
|
use base 'Net::FSP::Handle'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
886
|
|
7
|
|
|
|
|
|
|
our $VERSION = $Net::FSP::VERSION; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub OPEN { |
10
|
0
|
|
|
0
|
|
|
my ($self, $mode, $filename) = @_; |
11
|
|
|
|
|
|
|
|
12
|
0
|
0
|
|
|
|
|
$self->CLOSE if keys %{$self} > 1; |
|
0
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
|
$self->{position} = 0; |
14
|
0
|
|
|
|
|
|
$self->{reader} = $self->{fsp}->_get_reader('get_file', $filename, \$self->{position}); |
15
|
0
|
|
|
|
|
|
$self->{buffer} = ''; |
16
|
0
|
|
|
|
|
|
return $self; |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub _replenish { |
20
|
0
|
|
|
0
|
|
|
my $self = shift; |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
|
my $block = $self->{reader}->(); |
23
|
0
|
0
|
|
|
|
|
if (length $block == 0) { |
24
|
0
|
|
|
|
|
|
$self->{eof} = 1; |
25
|
|
|
|
|
|
|
} |
26
|
0
|
|
|
|
|
|
$self->{buffer} .= $block; |
27
|
0
|
|
|
|
|
|
return; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub READ { |
31
|
0
|
|
|
0
|
|
|
my $self = shift; |
32
|
0
|
|
|
|
|
|
my $bufref = \$_[0]; |
33
|
0
|
|
|
|
|
|
my (undef, $length, $offset) = @_; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
return do_or_fail { |
36
|
0
|
|
0
|
0
|
|
|
while (length $self->{buffer} < $length and not $self->{eof}) { |
37
|
0
|
|
|
|
|
|
$self->_replenish; |
38
|
|
|
|
|
|
|
} |
39
|
0
|
|
|
|
|
|
my $to_move = substr $self->{buffer}, 0, $length, ''; |
40
|
0
|
|
|
|
|
|
substr ${$bufref}, $offset, length $to_move, $to_move; |
|
0
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
return length $to_move; |
42
|
0
|
|
|
|
|
|
}; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub READLINE { |
46
|
0
|
|
|
0
|
|
|
my $self = shift; |
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
if (wantarray) { |
49
|
0
|
|
|
|
|
|
my @ret; |
50
|
0
|
|
|
|
|
|
while (defined(my $line = $self->READLINE)) { |
51
|
0
|
|
|
|
|
|
push @ret, $line; |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
return @ret; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
return do_or_fail { |
57
|
0
|
|
0
|
0
|
|
|
while ($self->{buffer} !~ /\n/ and not $self->{eof}) { |
58
|
0
|
|
|
|
|
|
$self->_replenish; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
|
|
|
|
if ($self->{buffer} =~ s/ \A ( [^\n]* \n ) //xms) {#TODO: refactor |
|
|
0
|
|
|
|
|
|
61
|
0
|
|
|
|
|
|
return $1; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
elsif ($self->{buffer} =~ s/ \A ( [^\n]+ ) //xms) { |
64
|
0
|
|
|
|
|
|
return $1; |
65
|
|
|
|
|
|
|
} |
66
|
0
|
|
|
|
|
|
return; |
67
|
|
|
|
|
|
|
} |
68
|
0
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub GETC { |
71
|
0
|
|
|
0
|
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
my $len = $self->READ(my $ret, 1, 0); |
73
|
0
|
0
|
|
|
|
|
return $len ? $ret : undef; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub EOF { |
77
|
0
|
|
|
0
|
|
|
my $self = shift; |
78
|
0
|
0
|
|
|
|
|
return $self->{eof} and $self->{buffer} eq ''; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub TELL { |
82
|
0
|
|
|
0
|
|
|
my $self = shift; |
83
|
0
|
|
|
|
|
|
return $self->{position}; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
#note: seeking is currently not supported |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
1; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
__END__ |