| 1 | package Perl6::Slurp; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use Scalar::Util 'refaddr'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 13 | our $VERSION = '0.051005'; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | # Exports only the slurp() sub... | ||||||||||||||||||||||||||||||||||||||||||
| 12 | 13 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 13 | *{caller().'::slurp'} = \&slurp; | |||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | # Recognize mode arguments... | ||||||||||||||||||||||||||||||||||||||||||
| 18 | 13 | my $mode_pat = qr{ | |||||||||||||||||||||||||||||||||||||||||
| 19 | ^ \s* ( (?: < | \+< | \+>>? ) &? ) \s* | ||||||||||||||||||||||||||||||||||||||||||
| 20 | }x; | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | # Recognize a mode followed by optional layer arguments... | ||||||||||||||||||||||||||||||||||||||||||
| 23 | 13 | my $mode_plus_layers = qr{ | |||||||||||||||||||||||||||||||||||||||||
| 24 | (?: $mode_pat | ^ \s* -\| \s* ) | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ( (?: :[^\W\d]\w* (?: \( .*? \) ?)? \s* )* ) | ||||||||||||||||||||||||||||||||||||||||||
| 26 | \s* | ||||||||||||||||||||||||||||||||||||||||||
| 27 | \z | ||||||||||||||||||||||||||||||||||||||||||
| 28 | }x; | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # Is this a pure number??? | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 26 | ▶ | sub is_pure_num { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_pure_num: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 26 | return (~$_[0] & $_[0]) eq 0; # ~ acts differently for numbers and strings | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # The magic subroutine that does everything... | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 140 | ▶ | sub slurp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
slurp: called CC=45 SCAR=38.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | # Are we in a useful context??? | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 140 | my $list_context = wantarray; | |||||||||||||||||||||||||||||||||||||||||
| 39 | 140 | ▶ | croak "Useless use of &slurp in a void context" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | unless defined $list_context; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | # Missing args default to $_, so we need to catch that early... | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 139 | my $default = $_; | |||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | # Remember any I/O layers and other options specified... | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 139 | my @layers_or_options; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | # Process the argument list... | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 139 | ▶ | for (my $i=0; $i<@_; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Ignore non-reference args... | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 247 | ▶ | my $type = ref $_[$i] or next; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # Hashes indicate extra layers; remove from @_, add them in sequence... | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 139 | ▶ | if ($type eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 55 | 48 | push @layers_or_options, splice @_, $i--, 1 | |||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Arrays also indicate extra layers; remove from @_, convert to hash | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # form, and add them in sequence... | ||||||||||||||||||||||||||||||||||||||||||
| 60 | elsif ($type eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # Splice out the array and unpack it... | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 3 | my @array = @{splice @_, $i--, 1}; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # Verify and convert each layer specified to a one-key hash... | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | while (@array) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | my ($layer, $value) = splice @array, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 6 | ▶ | croak "Incomplete layer specification for :$layer", | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | "\n(did you mean: $layer=>1)\n " | ||||||||||||||||||||||||||||||||||||||||||
| 69 | unless $value; | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 6 | push @layers_or_options, { $layer=>$value }; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | # Any remaining args are the read mode, source file, and whatever... | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 139 | my ($mode, $source, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | # If no arguments, use defaults... | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 139 | ▶ | if (!defined $mode) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 6 | ▶ | $mode = defined $default ? $default | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | : @ARGV ? \*ARGV | ||||||||||||||||||||||||||||||||||||||||||
| 82 | : "<" | ||||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # If mode was a reference, it must really have been the source... | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 139 | ▶ | if (ref $mode) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 53 | $source = $mode; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 53 | $mode = "<"; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | # If mode isn't a valid mode, it must actually have been the source... | ||||||||||||||||||||||||||||||||||||||||||
| 92 | elsif ($mode !~ /$mode_plus_layers/x) { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 25 | $source = $mode; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 25 | ▶ | $mode = $source =~ s/$mode_pat//x ? "$1" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | : $source =~ s/ \| \s* $//x ? "-|" | ||||||||||||||||||||||||||||||||||||||||||
| 96 | : "<" | ||||||||||||||||||||||||||||||||||||||||||
| 97 | ; | ||||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # Sources can be references, but only certain kinds of references... | ||||||||||||||||||||||||||||||||||||||||||
| 101 | 139 | my $ref = ref $source; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 139 | ▶ | if ($ref) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 103 | croak "Can't use $ref as a data source" | ||||||||||||||||||||||||||||||||||||||||||
| 104 | unless $ref eq 'SCALAR' | ||||||||||||||||||||||||||||||||||||||||||
| 105 | || $ref eq 'GLOB' | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 89 | ▶ | || eval { $source->isa('IO::Handle') }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$ref eq "SCALAR" or $ref eq "GLOB" or eval {
do {
$source->isa("IO::Handle")
}
}
$ref eq "SCALAR" or $ref eq "GLOB"
MC/DC0%0/3
$ref eq "SCALAR" or $ref eq "GLOB" or eval {
do {
$source->isa("IO::Handle")
}
}
$ref eq "SCALAR"
$ref eq "GLOB"
eval {
do {
$source->isa("IO::Handle")
}
}
Truth table75%3/4
A or B or C
A= $ref eq "SCALAR"B= $ref eq "GLOB"C= eval {
do {
$source->isa("IO::Handle")
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # slurp() always uses \n as its input record separator (a la Perl 6) | ||||||||||||||||||||||||||||||||||||||||||
| 110 | 139 | local $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | # This track the various options slurp() allows... | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 139 | my ($chomp, $chomp_to, $layers) = (0, "", ""); | |||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | # Can this slurp be done in an optimized way (assume so initially)??? | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 139 | my $optimized = 1; | |||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||
| 118 | # Decode the layers and options... | ||||||||||||||||||||||||||||||||||||||||||
| 119 | 139 | my $IRS = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 120 | 139 | for (@layers_or_options) { | |||||||||||||||||||||||||||||||||||||||||
| 121 | # Input record separator... | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 54 | ▶ | if (exists $_->{irs}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 30 | $IRS = $_->{irs}; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 30 | ▶ | $/ = $IRS if !ref($IRS); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 30 | delete $_->{irs}; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 30 | ▶ | $optimized &&= !ref($IRS); # ...can't be optimized if irs is a regex | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$optimized &&= !ref($IRS)
MC/DC50%1/2
$optimized &&= !ref($IRS)
$optimized
!ref($IRS)
Truth table66%2/3
A &&= not(B)
A= $optimizedB= !ref($IRS)
| |||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | # Autochomp... | ||||||||||||||||||||||||||||||||||||||||||
| 130 | 54 | ▶ | if (exists $_->{chomp}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 26 | $chomp = 1; | |||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | # If the chomp value is a string, that becomes to replacement... | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 26 | ▶ | if (defined $_->{chomp} && !is_pure_num($_->{chomp})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $_->{"chomp"} and not is_pure_num($_->{"chomp"})
MC/DC50%1/2
defined $_->{"chomp"} and not is_pure_num($_->{"chomp"})
defined $_->{"chomp"}
not is_pure_num($_->{"chomp"})
Truth table66%2/3
A and not(B)
A= defined $_->{"chomp"}B= not is_pure_num($_->{"chomp"})
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | $chomp_to = $_->{chomp} | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 14 | } | |||||||||||||||||||||||||||||||||||||||||
| 137 | 26 | delete $_->{chomp}; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 26 | $optimized = 0; # ...chomped slurps can't be optimized | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | # Any other entries are layers... | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 54 | $layers .= join " ", map ":$_", keys %$_; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | # Add any layers found to the mode specification... | ||||||||||||||||||||||||||||||||||||||||||
| 146 | 139 | $mode .= " $layers"; | |||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | # Open the source as a filehandle... | ||||||||||||||||||||||||||||||||||||||||||
| 149 | 139 | my $FH; | |||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | # Source is a typeglob... | ||||||||||||||||||||||||||||||||||||||||||
| 152 | 139 | ▶ | if ($ref && $ref ne 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
$ref and $ref ne "SCALAR"
MC/DC100%2/2
$ref and $ref ne "SCALAR"
$ref
$ref ne "SCALAR"
Truth table100%3/3
A and B
A= $refB= $ref ne "SCALAR"
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 43 | $FH = $source; | |||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | # No source, specified: use *ARGV... | ||||||||||||||||||||||||||||||||||||||||||
| 157 | elsif (!$source) { | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 13 | ▶ | no warnings 'io'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | open $FH, '<-' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | or croak "Can't open stdin: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | # Source specified: open it... | ||||||||||||||||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 13 | ▶ | no warnings 'io'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 96 | ▶ | open $FH, $mode, $source, @args | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | or croak "Can't open '$source': $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | # Standardize chomp-converter sub... | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 137 | ▶ | my $chomp_into = ref $chomp_to eq 'CODE' ? $chomp_to : sub{ $chomp_to }; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # Optimized slurp if possible in list context... | ||||||||||||||||||||||||||||||||||||||||||
| 174 | 137 | ▶ | if ($list_context && $optimized) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$list_context and $optimized
MC/DC100%2/2
$list_context and $optimized
$list_context
$optimized
Truth table100%3/3
A and B
A= $list_contextB= $optimized
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | 36 | return <$FH>; | |||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # Acquire data (working around bug between $/ and in magic ARGV)... | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 101 | ▶ | my $data = refaddr($FH) == \*ARGV ? join("",<>) : do { local $/; <$FH> }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | # Prepare input record separator regex... | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 101 | ▶ | my $irs = ref($IRS) ? $IRS | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | : defined($IRS) ? qr{\Q$IRS\E} | ||||||||||||||||||||||||||||||||||||||||||
| 184 | : qr{(?!)}; | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # List context may require input record separator processing... | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 101 | ▶ | if ($list_context) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | # No data --> nothing to return... | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 14 | ▶ | return () unless defined $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||
| 191 | # Split acquired data into lines according to IRS... | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 14 | my @components = split /($irs)/, $data; | |||||||||||||||||||||||||||||||||||||||||
| 193 | 14 | my @lines; | |||||||||||||||||||||||||||||||||||||||||
| 194 | 14 | ▶ | while (@components) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | # Extract the next line and separator... | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 56 | my ($line, $sep) = splice @components, 0, 2; | |||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | # Add the line... | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 56 | push @lines, $line; | |||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||
| 201 | # Chomp as requested... | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 56 | ▶ | if (defined $sep && length $sep) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $sep and length $sep
MC/DC50%1/2
defined $sep and length $sep
defined $sep
length $sep
Truth table66%2/3
A and B
A= defined $sepB= length $sep
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | 50 | ▶ | $lines[-1] .= $chomp ? $chomp_into->($sep) : $sep; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 14 | return @lines; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | # Scalar context... | ||||||||||||||||||||||||||||||||||||||||||
| 210 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 211 | # No data --> nothing to return... | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 87 | ▶ | return q{} unless defined $data; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | # Otherwise, do any requested chomp-conversion... | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 78 | ▶ | if ($chomp) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 13 | $data =~ s{($irs)}{$chomp_into->($1)}ge; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 78 | return $data; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||
| 223 | 13 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 224 | __END__ | ||||||||||||||||||||||||||||||||||||||||||