| 1 | package IO::Handle::Iterator; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use parent qw(IO::Handle::Prototype); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # error, clearerr, new_from_fd, fdopen | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub new { | ||||||||||||||||||||||||||||
| 13 | 1 | ▶ | my ( $class, $cb ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 1 | bless { | |||||||||||||||||||||||||||
| 16 | cb => $cb, | ||||||||||||||||||||||||||||
| 17 | }, $class; | ||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | sub getline { shift->_cb } | ||||||||||||||||||||||||||
|
Subroutine
getline: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub _cb { | ||||||||||||||||||||||||||||
| 23 | 9 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_cb: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 9 | ▶ | if ( my $cb = $self->{cb} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 9 | ▶ | if ( defined(my $next = $cb->()) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | 8 | return $next; | |||||||||||||||||||||||||||
| 28 | } else { | ||||||||||||||||||||||||||||
| 29 | 1 | $self->close; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 1 | return; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | sub _rebless_and { | ||||||||||||||||||||||||||||
| 37 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_rebless_and: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | 2 | my $method = shift; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | bless $self, "IO::Handle::Iterator::Buffered"; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | $self->$method(@_); | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | ▶ | sub read { shift->_rebless_and( read => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub sysread { shift->_rebless_and( sysread => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
sysread: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub getc { shift->_rebless_and( getc => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
getc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub ungetc { shift->_rebless_and( ungetc => @_ ) } | ||||||||||||||||||||||||||
|
Subroutine
ungetc: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | sub open { Carp::croak("Can't open an iterator") } | ||||||||||||||||||||||||||
|
Subroutine
open: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub print { Carp::croak("Can't print to iterator") } | ||||||||||||||||||||||||||
|
Subroutine
print: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | sub printflush { Carp::croak("Can't print to iterator") } | ||||||||||||||||||||||||||
|
Subroutine
printflush: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub printf { Carp::croak("Can't print to iterator") } | ||||||||||||||||||||||||||
|
Subroutine
printf: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub say { Carp::croak("Can't print to iterator") } | ||||||||||||||||||||||||||
|
Subroutine
say: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 55 | 0 | ▶ | sub write { Carp::croak("Can't write to iterator") } | ||||||||||||||||||||||||||
|
Subroutine
write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub syswrite { Carp::croak("Can't write to iterator") } | ||||||||||||||||||||||||||
|
Subroutine
syswrite: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub format_write { Carp::croak("Can't write to iterator") } | ||||||||||||||||||||||||||
|
Subroutine
format_write: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub ioctl { Carp::croak("Can't ioctl on iterator") } | ||||||||||||||||||||||||||
|
Subroutine
ioctl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | sub fcntl { Carp::croak("Can't fcntl on iterator") } | ||||||||||||||||||||||||||
|
Subroutine
fcntl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub truncate { Carp::croak("Can't truncate iterator") } | ||||||||||||||||||||||||||
|
Subroutine
truncate: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | sub sync { Carp::croak("Can't sync an iterator") } | ||||||||||||||||||||||||||
|
Subroutine
sync: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | sub flush { Carp::croak("Can't flush an iterator") } | ||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub autoflush { 1 } | ||||||||||||||||||||||||||
|
Subroutine
autoflush: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub opened { 1 } | ||||||||||||||||||||||||||
|
Subroutine
opened: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | sub blocking { | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | my ( $self, @args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
blocking: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 0 | ▶ | Carp::croak("Can't set blocking mode on iterator") if @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | return 1; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub stat { return undef } | ||||||||||||||||||||||||||
|
Subroutine
stat: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | sub fileno { return undef } | ||||||||||||||||||||||||||
|
Subroutine
fileno: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | ▶ | sub close { delete $_[0]{cb} } | ||||||||||||||||||||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 9 | ▶ | sub eof { not exists $_[0]{cb} } | ||||||||||||||||||||||||||
|
Subroutine
eof: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | sub getlines { | ||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
getlines: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | my @accum; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | ▶ | while ( defined(my $next = $self->getline) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | 0 | push @accum, $next; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | return @accum; | |||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | package IO::Handle::Iterator::Buffered; # FIXME IO::Handle::BufferMixin? | ||||||||||||||||||||||||||||
| 95 | 1 | ▶ | use parent qw(IO::Handle::Iterator); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 1 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | sub eof { | ||||||||||||||||||||||||||||
| 100 | 13 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
eof: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 13 | ▶ | length($self->{buf}) == 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 103 | and | ||||||||||||||||||||||||||||
| 104 | $self->SUPER::eof; | ||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub getc { | ||||||||||||||||||||||||||||
| 108 | 2 | ▶ | shift->read(my $c, 1); | ||||||||||||||||||||||||||
|
Subroutine
getc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | 2 | return $c; | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | sub ungetc { | ||||||||||||||||||||||||||||
| 113 | 1 | ▶ | my ( $self, $ord ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
ungetc: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | 1 | substr($self->{buf}, 0, 0, chr($ord)); # yuck | |||||||||||||||||||||||||||
| 115 | 1 | return; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | sub sysread { shift->read(@_) } | ||||||||||||||||||||||||||
|
Subroutine
sysread: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | sub read { | ||||||||||||||||||||||||||||
| 121 | 6 | ▶ | my ( $self, undef, $length, $offset ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=9 SCAR=22.8
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 6 | ▶ | return 0 if $self->eof; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 6 | ▶ | if ( $offset and length($_[1]) < $offset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$offset and length $_[1] < $offset
MC/DC50%1/2
$offset and length $_[1] < $offset
$offset
length $_[1] < $offset
Truth table66%2/3
A and B
A= $offsetB= length $_[1] < $offset
| |||||||||||||||||||||||||||||
| 126 | 1 | $_[1] .= "\0" x ( $offset - length($_[1]) ); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 6 | ▶ | while (length($self->{buf}) < $length) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | 7 | ▶ | if ( defined(my $next = $self->_cb) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 6 | $self->{buf} .= $next; | |||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||
| 133 | # data ended but still under $length, return all that remains and | ||||||||||||||||||||||||||||
| 134 | # empty the buffer | ||||||||||||||||||||||||||||
| 135 | 1 | my $ret = length($self->{buf}); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1 | ▶ | if ( $offset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 1 | substr($_[1], $offset) = delete $self->{buf}; | |||||||||||||||||||||||||||
| 139 | } else { | ||||||||||||||||||||||||||||
| 140 | 0 | $_[1] = delete $self->{buf}; | |||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 1 | return $ret; | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 5 | my $read; | |||||||||||||||||||||||||||
| 148 | 5 | ▶ | if ( $length > length($self->{buf}) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 0 | $read = delete $self->{buf}; | |||||||||||||||||||||||||||
| 150 | } else { | ||||||||||||||||||||||||||||
| 151 | 5 | $read = substr($self->{buf}, 0, $length, ''); | |||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 5 | ▶ | if ( $offset ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | substr($_[1], $offset) = $read; | |||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||
| 157 | 5 | $_[1] = $read; | |||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 5 | return length($read); | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | sub getline { | ||||||||||||||||||||||||||||
| 164 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
getline: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 1 | my $line = delete $self->{buf}; | |||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 1 | bless $self, 'IO::Handle::Iterator'; | |||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 1 | return $line; | |||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 1 | __PACKAGE__ | |||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||
| 175 | # ex: set sw=4 et: | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | __END__ | ||||||||||||||||||||||||||||