| 1 | package Net::FSP::Handle::Read; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Net::FSP::Handle qw/do_or_fail/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use base 'Net::FSP::Handle'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 2 | our $VERSION = $Net::FSP::VERSION; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 0 | ▶ | sub OPEN { | ||||||||||||||||||||||||||
|
Subroutine
OPEN: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 10 | 0 | my ($self, $mode, $filename) = @_; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | $self->CLOSE if keys %{$self} > 1; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub _replenish { | ||||||||||||||||||||||||||
|
Subroutine
_replenish: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 20 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 0 | my $block = $self->{reader}->(); | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | if (length $block == 0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | $self->{eof} = 1; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 0 | $self->{buffer} .= $block; | |||||||||||||||||||||||||||
| 27 | 0 | return; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub READ { | ||||||||||||||||||||||||||
|
Subroutine
READ: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 31 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 32 | 0 | my $bufref = \$_[0]; | |||||||||||||||||||||||||||
| 33 | 0 | my (undef, $length, $offset) = @_; | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 0 | ▶ | return do_or_fail { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | while (length $self->{buffer} < $length and not $self->{eof}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
length $self->{"buffer"} < $length and not $self->{"eof"}
MC/DC0%0/2
length $self->{"buffer"} < $length and not $self->{"eof"}
length $self->{"buffer"} < $length
not $self->{"eof"}
Truth table0%0/3
A and not(B)
A= length $self->{"buffer"} < $lengthB= 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; | |||||||||||||||||||||||||||
| 41 | 0 | return length $to_move; | |||||||||||||||||||||||||||
| 42 | 0 | }; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub READLINE { | ||||||||||||||||||||||||||
|
Subroutine
READLINE: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 46 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if (wantarray) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | my @ret; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | while (defined(my $line = $self->READLINE)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | push @ret, $line; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | return @ret; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | return do_or_fail { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | while ($self->{buffer} !~ /\n/ and not $self->{eof}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$self->{"buffer"} =~ /\n/ or $self->{"eof"}
MC/DC0%0/2
$self->{"buffer"} =~ /\n/ or $self->{"eof"}
$self->{"buffer"} =~ /\n/
$self->{"eof"}
Truth table0%0/3
A or B
A= $self->{"buffer"} =~ /\n/B= $self->{"eof"}
| |||||||||||||||||||||||||||||
| 58 | 0 | $self->_replenish; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ($self->{buffer} =~ s/ \A ( [^\n]* \n ) //xms) {#TODO: refactor | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub GETC { | ||||||||||||||||||||||||||
|
Subroutine
GETC: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | 0 | my $len = $self->READ(my $ret, 1, 0); | |||||||||||||||||||||||||||
| 73 | 0 | ▶ | return $len ? $ret : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub EOF { | ||||||||||||||||||||||||||
|
Subroutine
EOF: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 0 | return $self->{eof} and $self->{buffer} eq ''; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub TELL { | ||||||||||||||||||||||||||
|
Subroutine
TELL: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 82 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 83 | 0 | return $self->{position}; | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | #note: seeking is currently not supported | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 2 | 1; | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||