| 1 | package WARC::Record::Logical::Block; # -*- CPerl -*- | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | our @ISA = qw(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use WARC; *WARC::Record::Logical::Block::VERSION = \$WARC::VERSION; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Carp; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Fcntl qw/SEEK_SET SEEK_CUR SEEK_END/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # This implementation uses an array as the underlying object. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use constant { PARENT => 0, SEGMENT => 1, HANDLE => 2 }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | use constant OBJECT_INIT => undef, 0, undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # Invariant: HANDLE is always valid if SEGMENT is within range. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 2 | ▶ | BEGIN { require WARC::Record::Logical; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | BEGIN { $WARC::Record::Logical::Block::{$_} = $WARC::Record::Logical::{$_} | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | ▶ | for WARC::Record::Logical::SEGMENT_INDEX; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | sub _dbg_dump { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 62 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_dbg_dump: called CC=4 SCAR=14.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 62 | my $out = 'logical record block'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | $out .= ' @['.($self->[SEGMENT]).' / ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 62 | .($#{$self->[PARENT]{segments}}).']'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 62 | ▶ | $out .= ' [EOF]' if $self->[SEGMENT] > $#{$self->[PARENT]{segments}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 62 | $out .= "\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 0 | $out .= ' '.((tied *{$self->[HANDLE]})->_dbg_dump) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 62 | ▶ | if $self->[HANDLE] && UNIVERSAL::can(tied *{$self->[HANDLE]}, '_dbg_dump'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->[2] and UNIVERSAL::can(tied *{$self->[2];}, "_dbg_dump")
MC/DC0%0/2
$self->[2] and UNIVERSAL::can(tied *{$self->[2];}, "_dbg_dump")
$self->[2]
UNIVERSAL::can(tied *{$self->[2];}, "_dbg_dump")
Truth table66%2/3
A and B
A= $self->[2]B= UNIVERSAL::can(tied *{$self->[2];}, "_dbg_dump")
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 62 | return $out; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | sub TIEHANDLE { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 22 | ▶ | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TIEHANDLE: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 22 | my $parent = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 22 | my $ob = [OBJECT_INIT]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 22 | $ob->[PARENT] = $parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 22 | $ob->[HANDLE] = $parent->{segments}[0][SEG_REC]->open_block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 22 | bless $ob, $class; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | # advance to next segment; return false if already at last segment | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | sub _next_segment { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 79 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_next_segment: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 79 | ▶ | unless ($self->[PARENT]{segments}[1+$self->[SEGMENT]]) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 16 | { $self->[SEGMENT]++; return 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 63 | close $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | $self->[HANDLE] = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 63 | $self->[PARENT]{segments}[++$self->[SEGMENT]][SEG_REC]->open_block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 63 | return $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | sub READLINE { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 63 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
READLINE: called CC=32 SCAR=34.7
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 63 | ▶ | if (wantarray) { # data slurp; we might run out of memory... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | my @data = (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 1 | ▶ | while (defined(my $line = $self->READLINE())) { push @data, $line } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | return @data | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 62 | ▶ | return undef if $self->[SEGMENT] > $#{$self->[PARENT]{segments}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 57 | ▶ | if (not defined $/) { # file slurp; we might run out of memory... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 4 | my $data = readline $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 4 | ▶ | $data = '' unless defined $data; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 4 | ▶ | $data .= readline $self->[HANDLE] while $self->_next_segment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 4 | ▶ | return (length($data) ? $data : undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } elsif (ref $/) { # record read; fill a block... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | ▶ | use bytes; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 10 | my $rec_len = 0+${$/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 10 | my $rec = readline $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 10 | ▶ | $rec = '' unless defined $rec; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 10 | ▶ | while (length $rec < $rec_len) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 9 | local $/ = \(do {$rec_len - length $rec}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 9 | ▶ | last unless $self->_next_segment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 8 | $rec .= readline $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 10 | ▶ | return (length ($rec) ? $rec : undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } elsif ($/ eq '') { # paragraph read; delimiter is empty line... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 11 | my $para = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 11 | my $input = readline $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | ▶ | while (((defined $input and $para .= $input) or $self->_next_segment) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
defined $input && ($para .= $input) || $self->_next_segment and "\n\n" ne substr($para, -2)
defined $input and $para .= $input or $self->_next_segment
defined $input and $para .= $input
MC/DC75%3/4
defined $input && ($para .= $input) || $self->_next_segment and "\n\n" ne substr($para, -2)
defined $input
$para .= $input
$self->_next_segment
"\n\n" ne substr($para, -2)
Truth table50%4/8
A and B or C and D
A= defined $inputB= $para .= $inputC= $self->_next_segmentD= "\n\n" ne substr($para, -2)
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | and ("\n\n" ne substr $para, -2)) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # segment boundary was in the middle of a line, continuing read is safe | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 13 | { $input = readline $self->[HANDLE] } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | # paragraph delimiter may or may not span segments... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 11 | ▶ | if (eof $self->[HANDLE]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | # next segment may begin with newlines, if so, they must be read | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | my $ch; my $end_pos = $self->TELL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 6 | ▶ | $end_pos = $self->TELL, $para .= "\n" | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined($ch = $self->GETC) and $ch eq "\n"
MC/DC100%2/2
defined($ch = $self->GETC) and $ch eq "\n"
defined($ch = $self->GETC)
$ch eq "\n"
Truth table100%3/3
A and B
A= defined($ch = $self->GETC)B= $ch eq "\n"
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | while (defined ($ch = $self->GETC) and $ch eq "\n"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 6 | $self->SEEK($end_pos, SEEK_SET); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | ▶ | $input = defined($ch) ? '' : undef; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 11 | ▶ | return (length ($para) ? $para : undef); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } else { # ordinary line read... | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 2 | ▶ | use bytes; # a line delimiter may be split on any octet boundary | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 32 | my $line = ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 32 | my $input = readline $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | # read more data until we have a complete line or reach EOF | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 32 | ▶ | while (((defined $input and $line .= $input) or $self->_next_segment) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
defined $input && ($line .= $input) || $self->_next_segment and $/ ne substr($line, -length($/))
defined $input and $line .= $input or $self->_next_segment
defined $input and $line .= $input
MC/DC75%3/4
defined $input && ($line .= $input) || $self->_next_segment and $/ ne substr($line, -length($/))
defined $input
$line .= $input
$self->_next_segment
$/ ne substr($line, -length($/))
Truth table50%4/8
A and B or C and D
A= defined $inputB= $line .= $inputC= $self->_next_segmentD= $/ ne substr($line, -length($/))
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | and ($/ ne substr $line, -length $/)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 51 | ▶ | if (length $/ > 1) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # each number N in this array indicates that a length-N prefix of | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | # $/ currently matches at the end of the line buffer | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | my @prefixes = | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 22 | grep {substr($/, 0, $_) eq substr($line, -$_)} 1 .. length $/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 22 | ▶ | while (@prefixes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 39 | my $count = $self->READ($input, 1); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 39 | ▶ | return $line unless $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 38 | $line .= $input; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 38 | ▶ | return $line if $/ eq substr $line, -length $/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 34 | unshift @prefixes, 0; @prefixes = # sieve prefixes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 34 | grep {++$_; substr($/, 0, $_) eq substr($line, -$_)} @prefixes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } # loop iterates until no prefix of $/ matches the tail of $line | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 46 | $input = readline $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 27 | ▶ | return $input unless length $line; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 25 | return $line; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | # This sub must rely on the aliasing effect of @_. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | sub READ { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 70 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
READ: called CC=9 SCAR=22.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # args now: 0: buffer 1: length 2: offset into buffer or undef | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 70 | my $length = $_[1]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 70 | ▶ | my $offset = $_[2] || 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_[2] || 0
MC/DC100%1/1
$_[2] || 0
$_[2]
Truth table100%2/2
A
A= $_[2]
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 70 | ▶ | return 0 if $self->[SEGMENT] > $#{$self->[PARENT]{segments}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 68 | my $buf = ''; my $count = 1; my $bpos = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 68 | ▶ | while ($length && ($count || $self->_next_segment)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$length and $count || $self->_next_segment
$count or $self->_next_segment
MC/DC66%2/3
$length and $count || $self->_next_segment
$length
$count
$self->_next_segment
Truth table75%3/4
A and B or C
A= $lengthB= $countC= $self->_next_segment
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 99 | $count = read $self->[HANDLE], $buf, $length, $bpos; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 99 | ▶ | return undef unless defined $count; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 99 | $length -= $count; $bpos += $count; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 68 | ▶ | $_[0] = '' unless defined $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 68 | ▶ | $_[0] .= "\0" x ($offset - length($_[0])) if $offset > length $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 68 | substr $_[0], $offset, (length($_[0]) - $offset), $buf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 68 | return $bpos; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | sub GETC { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 22 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
GETC: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 22 | my $ch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 22 | ▶ | return undef unless $self->READ($ch, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 18 | return $ch; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | sub EOF { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 16 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
EOF: called CC=3 SCAR=11.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 16 | ▶ | return 1 if $self->[SEGMENT] > $#{$self->[PARENT]{segments}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | return 0 if $self->[SEGMENT] < $#{$self->[PARENT]{segments}}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | return eof $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | sub SEEK { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 12 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
SEEK: called CC=9 SCAR=22.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 12 | my $offset = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 12 | my $whence = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 12 | my $segments = $self->[PARENT]{segments}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 12 | my $npos; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 12 | ▶ | if ($whence == SEEK_SET) { $npos = $offset } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | elsif ($whence == SEEK_CUR) { $npos = $self->TELL + $offset } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | elsif ($whence == SEEK_END) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 2 | { $npos = ($segments->[-1][SEG_BASE] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | + $segments->[-1][SEG_LENGTH] + $offset) } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 1 | else { croak "unknown WHENCE $whence in call to seek" } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # This function must be able to seek backwards, even if the underlying | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | # handles cannot, to support paragraph reads. Seeking generally requires | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | # finding the new segment, switching to that segment, and seeking | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # forwards to the desired offset within the new segment. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | # Special handling for seek to or past end-of-file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 11 | ▶ | if ($npos >= ($segments->[-1][SEG_BASE] + $segments->[-1][SEG_LENGTH])) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 4 | $self->[SEGMENT] = @$segments; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 4 | close $self->[HANDLE]; $self->[HANDLE] = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 4 | return 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | my $new_segment_index = @$segments; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 7 | ▶ | for (my $i = 0; $i < $new_segment_index; $i++) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 23 | ▶ | $new_segment_index = $i # which also exits this loop | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$npos >= $segments->[$i][2] and $npos < $segments->[$i][2] + $segments->[$i][1]
MC/DC100%2/2
$npos >= $segments->[$i][2] and $npos < $segments->[$i][2] + $segments->[$i][1]
$npos >= $segments->[$i][2]
$npos < $segments->[$i][2] + $segments->[$i][1]
Truth table100%3/3
A and B
A= $npos >= $segments->[$i][2]B= $npos < $segments->[$i][2] + $segments->[$i][1]
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | if $npos >= $segments->[$i][SEG_BASE] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | && $npos < ($segments->[$i][SEG_BASE] + $segments->[$i][SEG_LENGTH]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 7 | my $new_segment = $segments->[$new_segment_index]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 7 | ▶ | return 0 unless $new_segment; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 6 | $self->[SEGMENT] = $new_segment_index; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 6 | close $self->[HANDLE]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 6 | $self->[HANDLE] = $new_segment->[SEG_REC]->open_block; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 6 | seek $self->[HANDLE], $npos - $new_segment->[SEG_BASE], SEEK_SET; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | sub TELL { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 15 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
TELL: called CC=2 SCAR=6.9
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 15 | my $segments = $self->[PARENT]{segments}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | return ($segments->[$self->[SEGMENT]][SEG_BASE] + (tell $self->[HANDLE])) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 15 | ▶ | if $self->[SEGMENT] <= $#{$segments}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 3 | return ($segments->[-1][SEG_BASE] + $segments->[-1][SEG_LENGTH]); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | sub CLOSE { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 1 | ▶ | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
CLOSE: called CC=1 SCAR=0.0
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | $self->[SEGMENT] = 1+$#{$self->[PARENT]{segments}}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 1 | close $self->[HANDLE]; $self->[HANDLE] = undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 2 | 1; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | __END__ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||