| 1 | # | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2003-2022 Christian Jaeger, copying@christianjaeger.ch | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||||||||||||||||||||||||||||||||||
| 7 | # bundled with this file. | ||||||||||||||||||||||||||||||||||||||||||
| 8 | # | ||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | # Depends: () | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | Chj::IO::File | ||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | my $f = new Chj::IO::File; | ||||||||||||||||||||||||||||||||||||||||||
| 19 | $f->xopen("<foo/file.txt"); | ||||||||||||||||||||||||||||||||||||||||||
| 20 | my $g = Chj::IO::File->xopen("<foo/file.txt"); | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | ... | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | Something like IO::File, but more lightweight (IO::File takes about 0.3 seconds | ||||||||||||||||||||||||||||||||||||||||||
| 27 | to load on my laptop, whereas this module takes less than 30ms), and with | ||||||||||||||||||||||||||||||||||||||||||
| 28 | methods that throw (currently untyped) exceptions on error. | ||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | NEW: $Chj::IO::ERRNO is set to $!+0 on strategic positions | ||||||||||||||||||||||||||||||||||||||||||
| 31 | $Chj::IO::ERRSTR to $! | ||||||||||||||||||||||||||||||||||||||||||
| 32 | for later reference. | ||||||||||||||||||||||||||||||||||||||||||
| 33 | HACK state is creeping in. Because of ugly Perl bugs. | ||||||||||||||||||||||||||||||||||||||||||
| 34 | todo finish putting those into every other part of these modules. | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | =head1 CLASS METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | =item new ("path") | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | Gives a new unopened filehandle object. (Not really sure what for; you should | ||||||||||||||||||||||||||||||||||||||||||
| 43 | be able to use perl builtins on it.) | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | =item xopen (path [,.. ]) | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | Creates new filehandle and calls builtin open, croaks on errors. | ||||||||||||||||||||||||||||||||||||||||||
| 48 | (May also be called on an existing object if I'm not wrong.) | ||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | =head1 OBJECT METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | =item read ( $buf, numbytes [, offset ] ) | ||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =item xread ( ... ) | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | Calls builtin, without/with error checking. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | =item xreadline () | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | Same as builtin readline, but checks $! for errors. (Not sure that really works.) | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | =item xreadline_chomp () | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | Does xreadline and chomp's the result(s) (unless undefined). | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | =item getline | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | Same as <$self>. Added since MIME::Parse expects this method. | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | =item xreadchunk ( length ) | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | Read a chunk of max length chars/bytes and return it. Return undef on | ||||||||||||||||||||||||||||||||||||||||||
| 77 | end of file. | ||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||
| 79 | # IDEA: xxreadchunk that throws exception on end of file? So no check needed. | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | =item xxreadchunk ( length ) | ||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # Yeah try it. Only string exception so far | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | =item xreadchar () | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | Read one character (can be more than one byte from the source | ||||||||||||||||||||||||||||||||||||||||||
| 88 | filehandle if an encoding is set on the filehandle). | ||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | =item xsysreadcompletely( buf, length [,offset]) -> bool | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | Like xsysread, but resumes reading upon intterrupted system calls and | ||||||||||||||||||||||||||||||||||||||||||
| 93 | partial reads from pipes until the required length has been | ||||||||||||||||||||||||||||||||||||||||||
| 94 | read. Returns true if buf was read completely, false on EOF upon start | ||||||||||||||||||||||||||||||||||||||||||
| 95 | of message. EOF after having read part but not all of buf results in | ||||||||||||||||||||||||||||||||||||||||||
| 96 | an exception. | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | =item xsyswritecompletely( buf [,length [,offset]]) | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | Like xsyswrite, but resumes writing upon interrupted system calls | ||||||||||||||||||||||||||||||||||||||||||
| 101 | until everything is written. Does not return anything. | ||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | =item content | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | =item xcontent | ||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | Returns full contents. Latter also checks $! for errors (see above). | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | =item seek / xseek | ||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||
| 111 | Only special thing is that if you only give one argument, it does | ||||||||||||||||||||||||||||||||||||||||||
| 112 | imply SEEK_SET as the whence value. (Hmmm well, there's also xrewind | ||||||||||||||||||||||||||||||||||||||||||
| 113 | for xseek(0) purpose.) | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | =item truncate / xtruncate | ||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | Totally normal. Just let me state that if your file pointer will not | ||||||||||||||||||||||||||||||||||||||||||
| 118 | be changed by this call, so be sure to call xrewind as well if you | ||||||||||||||||||||||||||||||||||||||||||
| 119 | plan to continue to write to the file handle. | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | I wanted to overload <> to xreadline(), but that does not work (on | ||||||||||||||||||||||||||||||||||||||||||
| 126 | perl 5.6.1), since the CORE::readline function will call into | ||||||||||||||||||||||||||||||||||||||||||
| 127 | <> again causing an infinite recursion. There does not seem to | ||||||||||||||||||||||||||||||||||||||||||
| 128 | be a solution, thus I leave <> the default (without error checking). | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | (BTW there's another perl bug: | ||||||||||||||||||||||||||||||||||||||||||
| 131 | http://bugs6.perl.org/rt2/Ticket/Display.html?id=6748 | ||||||||||||||||||||||||||||||||||||||||||
| 132 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | Not yet fully tested. | ||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | L<Chj::xopen>, L<Chj::IO::SysFile>, L<Chj::xsysopen> | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | =head1 NOTE | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | This is alpha software! Read the status section in the package README | ||||||||||||||||||||||||||||||||||||||||||
| 143 | or on the L<website|http://functional-perl.org/>. | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # '} | ||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | package Chj::IO::File; | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 51 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 51 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 51 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 51 | our @ISA = ("IO"); | |||||||||||||||||||||||||||||||||||||||||
| 156 | 85 | ▶ | sub import { } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | 51 | ▶ | use Symbol; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 51 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 51 | ▶ | use Fcntl qw(:DEFAULT :flock :seek :mode); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 51 | ▶ | use FP::Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 51 | my $has_posix; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 51 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=8.1
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 51 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | eval { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 51 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 51 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 172 | { | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 51 | $has_posix = 1; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 51 | POSIX->import(qw(EINVAL ENOENT)); | |||||||||||||||||||||||||||||||||||||||||
| 175 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $has_posix = 0; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | require Errno; | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | Errno->import(qw(EINVAL ENOENT)); | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 51 | our $DEBUG = 0; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | # numified => [ opened, name, path , xreadline_backwards:data ] | ||||||||||||||||||||||||||||||||||||||||||
| 185 | 51 | my %filemetadata; | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 7 | ▶ | sub set_path { # sets name, too | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_path: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 7 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 190 | 7 | ▶ | my $meta = $filemetadata{ pack "I", $self } || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$filemetadata{pack 'I', $self} || []
MC/DC0%0/1
$filemetadata{pack 'I', $self} || []
$filemetadata{pack 'I', $self}
Truth table50%1/2
A
A= $filemetadata{pack 'I', $self}
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 7 | $$meta[1] = $path; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 7 | $$meta[2] = $path; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | sub unset_path { # sets name, too | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unset_path: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my ($path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | my $meta = $filemetadata{ pack "I", $self } || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$filemetadata{pack 'I', $self} || []
MC/DC0%0/1
$filemetadata{pack 'I', $self} || []
$filemetadata{pack 'I', $self}
Truth table0%0/2
A
A= $filemetadata{pack 'I', $self}
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $$meta[1] = undef; # do not play games like "former '$$meta[1]'" | |||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | $$meta[2] = undef; | |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 275 | ▶ | sub set_opened { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_opened: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 275 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 275 | ▶ | my $meta = $filemetadata{ pack "I", $self } || []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$filemetadata{pack 'I', $self} || []
MC/DC100%1/1
$filemetadata{pack 'I', $self} || []
$filemetadata{pack 'I', $self}
Truth table100%2/2
A
A= $filemetadata{pack 'I', $self}
| |||||||||||||||||||||||||||||||||||||||||||
| 206 | 275 | ($$meta[0]) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | 251 | ▶ | sub opened { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
opened: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | 251 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 211 | 251 | ▶ | my $meta = $filemetadata{ pack "I", $self } or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 245 | $$meta[0] | |||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | my $meta = $filemetadata{ pack "I", $self } or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | $$meta[1] | |||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | 7 | ▶ | sub path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
path: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | ▶ | my $meta = $filemetadata{ pack "I", $self } or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | $$meta[2] | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | 14 | ▶ | sub xpath { # ATTENTION: if path is overridden, xpath must be as well! | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xpath: called CC=3 SCAR=11.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 14 | ▶ | my $meta = $filemetadata{ pack "I", $self } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 230 | or croak "xpath: file object has not yet been opened"; | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 14 | ▶ | defined $$meta[2] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | or croak "xpath: file object does not have a path - " | ||||||||||||||||||||||||||||||||||||||||||
| 233 | . "it may have been opened with a mixed path spec"; | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 14 | $$meta[2] | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub set_opened_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_opened_name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | # arguments: opened,name; well could give _path too as third argument. | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $filemetadata{ pack "I", $self } = [@_]; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | 238 | ▶ | sub set_opened_path { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_opened_path: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 245 | 238 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 246 | 238 | my ($opened, $path) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 247 | 238 | $filemetadata{ pack "I", $self } = [$opened, $path, $path]; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | sub _quote { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_quote: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my ($str, $alternative) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | ▶ | if (defined $str) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | $str =~ s/'/\\'/sg; | |||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | "'$str'" | |||||||||||||||||||||||||||||||||||||||||
| 255 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | $alternative || "undef" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | sub quotedname { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quotedname: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | _quote(scalar $self->name, "(no filename)") | |||||||||||||||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | ▶ | sub _numquote { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_numquote: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my ($num) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if (defined $num) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | $num | |||||||||||||||||||||||||||||||||||||||||
| 269 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | "undef" | |||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | # this exists for subclasses that wrap the filehandle | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 1284 | ▶ | sub fh { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fh: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | 1284 | $_[0] | |||||||||||||||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||||||||||||||||
| 279 | 244 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 280 | 244 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 244 | my $self = gensym; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 244 | bless $self, $class | |||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | 237 | ▶ | sub perhaps_open { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perhaps_open: called CC=6 SCAR=19.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 286 | 237 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 287 | 237 | ▶ | my $self = ref $proto ? $proto : $proto->new; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 237 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 289 | 237 | $! = undef; | |||||||||||||||||||||||||||||||||||||||||
| 290 | 237 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $rv = open $self->fh, $_[0]; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 292 | } elsif (@_ >= 2) { | ||||||||||||||||||||||||||||||||||||||||||
| 293 | 237 | $rv = open $self->fh, $_[0], @_[1 .. $#_]; ## no critic | |||||||||||||||||||||||||||||||||||||||||
| 294 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | croak "xopen @_: wrong number of arguments"; | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | 237 | ▶ | $rv // do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$rv // do {
$Chj::IO::ERRSTR = $!;
$Chj::IO::ERRNO = $! + 0;
return ()
}
MC/DC0%0/2
$rv // do {
$Chj::IO::ERRSTR = $!;
$Chj::IO::ERRNO = $! + 0;
return ()
}
$rv
do {
$Chj::IO::ERRSTR = $!;
$Chj::IO::ERRNO = $! + 0;
return ()
}
Truth table66%2/3
A // B
A= $rvB= do {
$Chj::IO::ERRSTR = $!;
$Chj::IO::ERRNO = $! + 0;
return ()
}
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 6 | $Chj::IO::ERRSTR = $!; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 6 | $Chj::IO::ERRNO = $! +0; | |||||||||||||||||||||||||||||||||||||||||
| 300 | return () | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 6 | }; | |||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||
| 303 | #my $filename = $_[0] =~ /^[<>!+]+\z/ ? $_[1] : $_[0]; | ||||||||||||||||||||||||||||||||||||||||||
| 304 | #$metadata{pack "I",$self} = $filename; | ||||||||||||||||||||||||||||||||||||||||||
| 305 | 231 | ▶ | if ($_[0] =~ /^[<>!+]+\z/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||||||||||||||
| 307 | # separated flags and filepath, cool | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 231 | $self->set_opened_path(1, $_[1]); | |||||||||||||||||||||||||||||||||||||||||
| 309 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||||||||||||||
| 311 | # one-big-mix pathspec | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $self->set_opened_name(1, $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||
| 314 | 231 | $self | |||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | 226 | ▶ | sub xopen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xopen: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 318 | 226 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 319 | 226 | ▶ | if (my ($fh) = $proto->perhaps_open(@_)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 226 | $fh | |||||||||||||||||||||||||||||||||||||||||
| 321 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | croak "xopen @_: $Chj::IO::ERRSTR"; | |||||||||||||||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | # die on all errors except ENOENT | ||||||||||||||||||||||||||||||||||||||||||
| 327 | 11 | ▶ | sub perhaps_xopen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perhaps_xopen: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 328 | 11 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 11 | ▶ | if (my ($fh) = $proto->perhaps_open(@_)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 5 | $fh | |||||||||||||||||||||||||||||||||||||||||
| 331 | } elsif ($Chj::IO::ERRNO == ENOENT) { | ||||||||||||||||||||||||||||||||||||||||||
| 332 | () | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 6 | } else { | |||||||||||||||||||||||||||||||||||||||||
| 334 | 0 | croak "xopen @_: $Chj::IO::ERRSTR"; | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | 7 | ▶ | sub xsysopen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsysopen: called CC=5 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 339 | 7 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 340 | 7 | ▶ | my $self = ref $proto ? $proto : $proto->new; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 7 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 7 | $! = undef; | |||||||||||||||||||||||||||||||||||||||||
| 343 | 7 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $rv = sysopen $self->fh, $_[0], $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 345 | } elsif (@_ == 3) { | ||||||||||||||||||||||||||||||||||||||||||
| 346 | 7 | $rv = sysopen $self->fh, $_[0], $_[1], $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 347 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | croak "xsysopen @_: wrong number of arguments"; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | 7 | ▶ | $rv // do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$rv // do {
$Chj::IO::ERRSTR = $!;
$Chj::IO::ERRNO = $! + 0;
croak('xsysopen ' . _quote($_[0]) . ", mode $_[1], perms " . _numquote($_[2]) . ": $!")
}
MC/DC0%0/2
$rv // do {
$Chj::IO::ERRSTR = $!;
$Chj::IO::ERRNO = $! + 0;
croak('xsysopen ' . _quote($_[0]) . ", mode $_[1], perms " . _numquote($_[2]) . ": $!")
}
$rv
do {
$Chj::IO::ERRSTR = $!;
$Chj::IO::ERRNO = $! + 0;
croak('xsysopen ' . _quote($_[0]) . ", mode $_[1], perms " . _numquote($_[2]) . ": $!")
}
Truth table33%1/3
A // B
A= $rvB= do {
$Chj::IO::ERRSTR = $!;
$Chj::IO::ERRNO = $! + 0;
croak('xsysopen ' . _quote($_[0]) . ", mode $_[1], perms " . _numquote($_[2]) . ": $!")
}
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | $Chj::IO::ERRSTR = $!; | |||||||||||||||||||||||||||||||||||||||||
| 352 | 0 | $Chj::IO::ERRNO = $! +0; | |||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | croak( "xsysopen " | |||||||||||||||||||||||||||||||||||||||||
| 354 | . _quote($_[0]) | ||||||||||||||||||||||||||||||||||||||||||
| 355 | . ", mode $_[1], perms " | ||||||||||||||||||||||||||||||||||||||||||
| 356 | . _numquote($_[2]) | ||||||||||||||||||||||||||||||||||||||||||
| 357 | . ": $!"); | ||||||||||||||||||||||||||||||||||||||||||
| 358 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 359 | 7 | $self->set_opened_path(1, $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 360 | 7 | $self | |||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||
| 363 | 0 | ▶ | sub sysopen { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sysopen: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 364 | 0 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | my $self = ref $proto ? $proto : $proto->new; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | $rv = sysopen $self->fh, $_[0], $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 369 | } elsif (@_ == 3) { | ||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | $rv = sysopen $self->fh, $_[0], $_[1], $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 371 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | croak "sysopen @_: wrong number of arguments"; | |||||||||||||||||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | ▶ | $rv // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$rv // (return undef)
MC/DC0%0/1
$rv // (return undef)
$rv
Truth table0%0/2
A
A= $rv
| |||||||||||||||||||||||||||||||||||||||||||
| 375 | 0 | $self->set_opened_path(1, $_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | $self | |||||||||||||||||||||||||||||||||||||||||
| 377 | } | ||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||
| 379 | # but see set_encoding instead! | ||||||||||||||||||||||||||||||||||||||||||
| 380 | 0 | ▶ | sub xbinmode { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xbinmode: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | ▶ | binmode($self->fh, $_[0]) or die "binmode: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 384 | } elsif (@_ == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 385 | 0 | ▶ | binmode($self->fh) or die "binmode: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 386 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 0 | die "wrong number of arguments"; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | ▶ | sub set_layer_or_encoding { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_layer_or_encoding: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 392 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | my ($layer_or_encoding) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | ▶ | my $layer | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | = ($layer_or_encoding =~ /^:/ | ||||||||||||||||||||||||||||||||||||||||||
| 396 | ? $layer_or_encoding | ||||||||||||||||||||||||||||||||||||||||||
| 397 | : ":encoding($layer_or_encoding)"); | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $self->xbinmode($layer); | |||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 45 | ▶ | sub perhaps_set_layer_or_encoding { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
perhaps_set_layer_or_encoding: called CC=2 SCAR=7.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 402 | 45 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 403 | 45 | my ($maybe_layer_or_encoding) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 404 | 45 | ▶ | if (defined $maybe_layer_or_encoding) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $self->set_layer_or_encoding($maybe_layer_or_encoding); | |||||||||||||||||||||||||||||||||||||||||
| 406 | } | ||||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||
| 409 | 0 | ▶ | sub set_encoding { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_encoding: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 0 | my ($encoding) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 412 | 0 | $self->xbinmode(":encoding($encoding)"); | |||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | ▶ | sub read { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
read: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | if (@_ == 2) { CORE::read $self->fh, $_[0], $_[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | elsif (@_ == 3) { CORE::read $self->fh, $_[0], $_[1], $_[2] } | |||||||||||||||||||||||||||||||||||||||||
| 419 | 0 | else { croak "read: wrong number of arguments" } | |||||||||||||||||||||||||||||||||||||||||
| 420 | } | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 0 | ▶ | sub xread { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xread: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||
| 424 | # XX EINTR / EAGAIN? | ||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | if (@_ == 2) { $rv = CORE::read $self->fh, $_[0], $_[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | elsif (@_ == 3) { $rv = CORE::read $self->fh, $_[0], $_[1], $_[2] } | |||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | else { croak "xread: wrong number of arguments" } | |||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | ▶ | defined $rv or croak "xread from " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 431 | 0 | $rv | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | ▶ | sub xreadchunk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadchunk: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $rv = CORE::read $self->fh, $buf, $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | defined $rv or croak "xreadchunk " . $self->quotedname . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | $rv ? $buf : undef | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | } | ||||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | sub xxreadchunk { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xxreadchunk: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | @_ == 1 or fp_croak_arity 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | my $rv = CORE::read $self->fh, $buf, $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | defined $rv or croak "xreadchunk " . $self->quotedname . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | ▶ | $rv ? $buf : die "EOF\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 450 | } | ||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | ▶ | sub xreadchar { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadchar: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 454 | 0 | $self->xreadchunk(1) | |||||||||||||||||||||||||||||||||||||||||
| 455 | } | ||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | ▶ | sub sysread { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sysread: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 459 | 0 | ▶ | if (@_ == 2) { CORE::sysread $self->fh, $_[0], $_[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 460 | 0 | elsif (@_ == 3) { CORE::sysread $self->fh, $_[0], $_[1], $_[2] } | |||||||||||||||||||||||||||||||||||||||||
| 461 | 0 | else { croak "sysread: wrong number of arguments" } | |||||||||||||||||||||||||||||||||||||||||
| 462 | } | ||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||
| 464 | 65 | ▶ | sub xsysread { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsysread: called CC=4 SCAR=16.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 465 | 65 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 466 | 65 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 65 | ▶ | if (@_ == 2) { $rv = CORE::sysread $self->fh, $_[0], $_[1] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | elsif (@_ == 3) { $rv = CORE::sysread $self->fh, $_[0], $_[1], $_[2] } | |||||||||||||||||||||||||||||||||||||||||
| 469 | 0 | else { croak "xsysread: wrong number of arguments" } | |||||||||||||||||||||||||||||||||||||||||
| 470 | 65 | ▶ | defined $rv or croak "xsysread from " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 471 | 65 | $rv | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||
| 474 | # similar to xsyswritecompletely | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 1 | ▶ | sub xsysreadcompletely { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsysreadcompletely: called CC=9 SCAR=31.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 476 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 1 | my $len = $_[1]; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 1 | my $offset; | |||||||||||||||||||||||||||||||||||||||||
| 479 | 1 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 480 | 1 | $offset = 0; | |||||||||||||||||||||||||||||||||||||||||
| 481 | } elsif (@_ == 3) { | ||||||||||||||||||||||||||||||||||||||||||
| 482 | 0 | $offset = $_[2]; | |||||||||||||||||||||||||||||||||||||||||
| 483 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | croak "xsysreadcompletely: wrong number of arguments" | |||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||
| 486 | 1 | my $restlen = $len; | |||||||||||||||||||||||||||||||||||||||||
| 487 | 1 | my $restoffset = $offset; | |||||||||||||||||||||||||||||||||||||||||
| 488 | LP: { | ||||||||||||||||||||||||||||||||||||||||||
| 489 | 1 | my $rv = CORE::sysread $self->fh, $_[0], $restlen, $restoffset; | |||||||||||||||||||||||||||||||||||||||||
| 490 | 1 | ▶ | if (defined $rv) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 491 | 1 | $restlen -= $rv; | |||||||||||||||||||||||||||||||||||||||||
| 492 | 1 | $restoffset += $rv; | |||||||||||||||||||||||||||||||||||||||||
| 493 | 1 | ▶ | die "bug" if $restlen < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 494 | 1 | ▶ | if ($restlen > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if ($rv == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | ▶ | if ($restlen == $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||
| 498 | # nothing was read | ||||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | 0 | |||||||||||||||||||||||||||||||||||||||||
| 500 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 501 | 0 | croak "xsysreadcompletely: unexpected EOF"; | |||||||||||||||||||||||||||||||||||||||||
| 502 | } | ||||||||||||||||||||||||||||||||||||||||||
| 503 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | redo LP; | |||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 507 | 1 | 1 | |||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | # or $len? but that might actually be 0 | ||||||||||||||||||||||||||||||||||||||||||
| 510 | } | ||||||||||||||||||||||||||||||||||||||||||
| 511 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 512 | 0 | my $errno = $! +0; | |||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | require Errno; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | if ($errno == Errno::EINTR()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||||||||||||||
| 516 | #warn "interrupted system call, redo"; # yep happens | ||||||||||||||||||||||||||||||||||||||||||
| 517 | 0 | redo LP; | |||||||||||||||||||||||||||||||||||||||||
| 518 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 519 | 0 | croak "xsysreadcompletely from " . ($self->quotedname) . ": $!"; | |||||||||||||||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||
| 525 | 0 | ▶ | sub syswrite { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
syswrite: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 526 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 527 | 0 | ▶ | if (@_ == 1) { CORE::syswrite $self->fh, $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 528 | 0 | elsif (@_ == 2) { CORE::syswrite $self->fh, $_[0], $_[1] } | |||||||||||||||||||||||||||||||||||||||||
| 529 | 0 | elsif (@_ == 3) { CORE::syswrite $self->fh, $_[0], $_[1], $_[2] } | |||||||||||||||||||||||||||||||||||||||||
| 530 | 0 | else { croak "syswrite: wrong number of arguments" } | |||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | sub xsyswrite { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsyswrite: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $rv; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | if (@_ == 1) { $rv = CORE::syswrite $self->fh, $_[0] } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 537 | 0 | elsif (@_ == 2) { $rv = CORE::syswrite $self->fh, $_[0], $_[1] } | |||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | elsif (@_ == 3) { $rv = CORE::syswrite $self->fh, $_[0], $_[1], $_[2] } | |||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | else { croak "xsyswrite: wrong number of arguments" } | |||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | ▶ | defined $rv or croak "xsyswrite: from " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 541 | 0 | $rv | |||||||||||||||||||||||||||||||||||||||||
| 542 | } | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | # similar to xsysreadcompletely | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 3 | ▶ | sub xsyswritecompletely { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsyswritecompletely: called CC=9 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 546 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 547 | 3 | ▶ | if (not(@_ >= 1 and @_ <= 3)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ >= 1 and @_ <= 3
MC/DC0%0/2
@_ >= 1 and @_ <= 3
@_ >= 1
@_ <= 3
Truth table33%1/3
A and B
A= @_ >= 1B= @_ <= 3
| |||||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | croak "xsyswritecompletely: wrong number of arguments" | |||||||||||||||||||||||||||||||||||||||||
| 549 | } | ||||||||||||||||||||||||||||||||||||||||||
| 550 | 3 | my (undef, $maybe_len, $maybe_offset) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | # ^$buf | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 3 | ▶ | my $len = defined $maybe_len ? $maybe_len : length($_[0]); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 554 | 3 | ▶ | my $offset = $maybe_offset || 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$maybe_offset || 0
MC/DC0%0/1
$maybe_offset || 0
$maybe_offset
Truth table50%1/2
A
A= $maybe_offset
| |||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | # partial COPYPASTE from xsysreadcompletely | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 3 | my $restlen = $len; | |||||||||||||||||||||||||||||||||||||||||
| 558 | 3 | my $restoffset = $offset; | |||||||||||||||||||||||||||||||||||||||||
| 559 | LP: { | ||||||||||||||||||||||||||||||||||||||||||
| 560 | 3 | my $rv = CORE::syswrite $self->fh, $_[0], $restlen, $restoffset; | |||||||||||||||||||||||||||||||||||||||||
| 561 | 3 | ▶ | if (defined $rv) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 562 | 3 | $restlen -= $rv; | |||||||||||||||||||||||||||||||||||||||||
| 563 | 3 | $restoffset += $rv; | |||||||||||||||||||||||||||||||||||||||||
| 564 | 3 | ▶ | die "bug" if $restlen < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 565 | 3 | ▶ | if ($restlen > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 566 | 0 | redo LP; | |||||||||||||||||||||||||||||||||||||||||
| 567 | } | ||||||||||||||||||||||||||||||||||||||||||
| 568 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 569 | 0 | my $errno = $! +0; | |||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | require Errno; | |||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | ▶ | if ($errno == Errno::EINTR()) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | warn "interrupted system call, redo"; # | |||||||||||||||||||||||||||||||||||||||||
| 573 | 0 | redo LP; | |||||||||||||||||||||||||||||||||||||||||
| 574 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | croak "xsyswritecompletely to " . ($self->quotedname) . ": $!"; | |||||||||||||||||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||||||||||||||
| 579 | } | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | 199 | ▶ | sub xreadline { # XX: test error case (difficult to do) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadline: called CC=4 SCAR=14.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 582 | 199 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 583 | 199 | undef $!; # needed! | |||||||||||||||||||||||||||||||||||||||||
| 584 | 199 | ▶ | if (wantarray) { ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 585 | 198 | my $lines = [CORE::readline($self->fh)]; | |||||||||||||||||||||||||||||||||||||||||
| 586 | 198 | ▶ | if ($!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 587 | 0 | croak "xreadline from " . ($self->quotedname) . ": $!"; | |||||||||||||||||||||||||||||||||||||||||
| 588 | } | ||||||||||||||||||||||||||||||||||||||||||
| 589 | 198 | @$lines | |||||||||||||||||||||||||||||||||||||||||
| 590 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 591 | 1 | my $bufref = \(scalar CORE::readline($self->fh)); # dito | |||||||||||||||||||||||||||||||||||||||||
| 592 | 1 | ▶ | if ($!) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 593 | 0 | croak "xreadline from " . ($self->quotedname) . ": $!"; | |||||||||||||||||||||||||||||||||||||||||
| 594 | } | ||||||||||||||||||||||||||||||||||||||||||
| 595 | 1 | $$bufref | |||||||||||||||||||||||||||||||||||||||||
| 596 | } | ||||||||||||||||||||||||||||||||||||||||||
| 597 | } | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | ▶ | sub xreadline_chomp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadline_chomp: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 600 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | ▶ | if (wantarray) { ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 602 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | chomp; | |||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | $_ | |||||||||||||||||||||||||||||||||||||||||
| 605 | } $s->xreadline | ||||||||||||||||||||||||||||||||||||||||||
| 606 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | ▶ | if (defined(my $ln = $s->xreadline)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | chomp $ln; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | $ln | |||||||||||||||||||||||||||||||||||||||||
| 610 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 611 | return | ||||||||||||||||||||||||||||||||||||||||||
| 612 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 613 | } | ||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||
| 616 | 224 | ▶ | sub getline { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
getline: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 617 | 224 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 618 | 224 | my $fh = $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 619 | <$fh> | ||||||||||||||||||||||||||||||||||||||||||
| 620 | 224 | } | |||||||||||||||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | ▶ | sub xreadline_lf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadline_lf: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 623 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | local $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 625 | 0 | $self->xreadline | |||||||||||||||||||||||||||||||||||||||||
| 626 | } | ||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||
| 628 | 0 | ▶ | sub xreadline_lf_chomp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadline_lf_chomp: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 629 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 630 | 0 | local $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | $self->xreadline_chomp | |||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | sub xreadline0 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadline0: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | local $/ = "\0"; | |||||||||||||||||||||||||||||||||||||||||
| 637 | 0 | $self->xreadline | |||||||||||||||||||||||||||||||||||||||||
| 638 | } | ||||||||||||||||||||||||||||||||||||||||||
| 639 | |||||||||||||||||||||||||||||||||||||||||||
| 640 | 0 | ▶ | sub xreadline0_chop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadline0_chop: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | local $/ = "\0"; | |||||||||||||||||||||||||||||||||||||||||
| 643 | |||||||||||||||||||||||||||||||||||||||||||
| 644 | # yes really *have* to check context. or it would give the number | ||||||||||||||||||||||||||||||||||||||||||
| 645 | # of items | ||||||||||||||||||||||||||||||||||||||||||
| 646 | 0 | ▶ | if (wantarray) { ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 647 | map { | ||||||||||||||||||||||||||||||||||||||||||
| 648 | 0 | chop; | |||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $_ | |||||||||||||||||||||||||||||||||||||||||
| 650 | } $self->xreadline | ||||||||||||||||||||||||||||||||||||||||||
| 651 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | my $str = $self->xreadline; | |||||||||||||||||||||||||||||||||||||||||
| 653 | 0 | ▶ | chop $str if defined $str; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 654 | 0 | $str | |||||||||||||||||||||||||||||||||||||||||
| 655 | } | ||||||||||||||||||||||||||||||||||||||||||
| 656 | } | ||||||||||||||||||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||||||||||||||||
| 658 | { | ||||||||||||||||||||||||||||||||||||||||||
| 659 | 51 | my $SLICE_LENGTH = 1024 * 8; | |||||||||||||||||||||||||||||||||||||||||
| 660 | 51 | my $LINEBREAK = "\n"; # XX test \r\n etc. (and move into object?) | |||||||||||||||||||||||||||||||||||||||||
| 661 | 51 | my $REVERSELINEBREAK = reverse $LINEBREAK; | |||||||||||||||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||||||||||||||||
| 663 | 0 | ▶ | sub xreadline_backwards { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xreadline_backwards: not called CC=22 SCAR=62.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 664 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 665 | 0 | ▶ | my $meta = $filemetadata{ pack "I", $self } ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$filemetadata{pack "I", $self} ||= []
MC/DC0%0/1
$filemetadata{pack "I", $self} ||= []
$filemetadata{pack "I", $self}
Truth table0%0/2
A
A= $filemetadata{pack "I", $self}
| |||||||||||||||||||||||||||||||||||||||||||
| 666 | 0 | ▶ | my $data = $$meta[3] ||= {}; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$meta->[3] ||= {}
MC/DC0%0/1
$meta->[3] ||= {}
$meta->[3]
Truth table0%0/2
A
A= $meta->[3]
| |||||||||||||||||||||||||||||||||||||||||||
| 667 | 0 | ▶ | my $lines = $$data{lines} ||= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$data->{"lines"} ||= []
MC/DC0%0/1
$data->{"lines"} ||= []
$data->{"lines"}
Truth table0%0/2
A
A= $data->{"lines"}
| |||||||||||||||||||||||||||||||||||||||||||
| 668 | 0 | ▶ | my $bufferp = \($$data{buffer} ||= ""); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$data->{"buffer"} ||= ""
MC/DC0%0/1
$data->{"buffer"} ||= ""
$data->{"buffer"}
Truth table0%0/2
A
A= $data->{"buffer"}
| |||||||||||||||||||||||||||||||||||||||||||
| 669 | 0 | ▶ | while (!@$lines) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 670 | 0 | my $curpos = tell($self->fh); | |||||||||||||||||||||||||||||||||||||||||
| 671 | 0 | ▶ | if (!defined($curpos) or $curpos < 0) { # XX correct? doc is very | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $curpos or $curpos < 0
MC/DC0%0/2
not defined $curpos or $curpos < 0
not defined $curpos
$curpos < 0
Truth table0%0/3
not(A) or B
A= not defined $curposB= $curpos < 0
| |||||||||||||||||||||||||||||||||||||||||||
| 672 | # imprecise! | ||||||||||||||||||||||||||||||||||||||||||
| 673 | 0 | croak( "xreadline_backwards on " | |||||||||||||||||||||||||||||||||||||||||
| 674 | . $self->quotedname | ||||||||||||||||||||||||||||||||||||||||||
| 675 | . ": can't seek on this filehandle?: tell: $!"); | ||||||||||||||||||||||||||||||||||||||||||
| 676 | } | ||||||||||||||||||||||||||||||||||||||||||
| 677 | 0 | my $newpos = $curpos - $SLICE_LENGTH; | |||||||||||||||||||||||||||||||||||||||||
| 678 | 0 | ▶ | $newpos = 0 if $newpos < 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 679 | 0 | ▶ | my $len_to_go = ($curpos > $SLICE_LENGTH) ? $SLICE_LENGTH : $curpos; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 680 | 0 | ▶ | if ($len_to_go <= 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 681 | |||||||||||||||||||||||||||||||||||||||||||
| 682 | #warn "debug xreadline_backwards: start of file reached and nothing to go"; | ||||||||||||||||||||||||||||||||||||||||||
| 683 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 684 | } | ||||||||||||||||||||||||||||||||||||||||||
| 685 | $self->xseek( | ||||||||||||||||||||||||||||||||||||||||||
| 686 | 0 | ▶ | -($curpos > $SLICE_LENGTH ? $SLICE_LENGTH : $len_to_go), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 687 | SEEK_CUR); | ||||||||||||||||||||||||||||||||||||||||||
| 688 | 0 | my $totbuf; | |||||||||||||||||||||||||||||||||||||||||
| 689 | 0 | ▶ | while ($len_to_go) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 690 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||||||||
| 691 | 0 | ▶ | if (my $len = $self->xread($buf, $len_to_go)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 692 | 0 | $totbuf .= $buf; | |||||||||||||||||||||||||||||||||||||||||
| 693 | 0 | $len_to_go -= $len; | |||||||||||||||||||||||||||||||||||||||||
| 694 | 0 | ▶ | if ($len_to_go < 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 695 | 0 | die | |||||||||||||||||||||||||||||||||||||||||
| 696 | "strange error (bug?, or maybe file changed while reading?), len_to_go = $len_to_go"; | ||||||||||||||||||||||||||||||||||||||||||
| 697 | } | ||||||||||||||||||||||||||||||||||||||||||
| 698 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 699 | |||||||||||||||||||||||||||||||||||||||||||
| 700 | #die "strange error (bug?, or maybe file changed while reading?): expecting len_to_go=$len_to_go but xread returns len $len"; | ||||||||||||||||||||||||||||||||||||||||||
| 701 | #return; | ||||||||||||||||||||||||||||||||||||||||||
| 702 | } | ||||||||||||||||||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||||||||||||||||
| 705 | 0 | $self->xseek($newpos, SEEK_SET); | |||||||||||||||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||||||||||||||||
| 707 | # now append that to BUFFER. | ||||||||||||||||||||||||||||||||||||||||||
| 708 | 0 | $$bufferp .= reverse $totbuf; | |||||||||||||||||||||||||||||||||||||||||
| 709 | |||||||||||||||||||||||||||||||||||||||||||
| 710 | # now tac off stuff from beginning. | ||||||||||||||||||||||||||||||||||||||||||
| 711 | 0 | ▶ | if ($newpos > 0) { # there is something left to be read from top | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 712 | # of file, so require a linebreak to be seen | ||||||||||||||||||||||||||||||||||||||||||
| 713 | 0 | ▶ | while (length($$bufferp) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
length $$bufferp and $$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(? = \Q$REVERSELINEBREAK\E)//s || $$bufferp =~ s/^(.+?)(? = \Q$REVERSELINEBREAK\E)//s
$$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(? = \Q$REVERSELINEBREAK\E)//s or $$bufferp =~ s/^(.+?)(? = \Q$REVERSELINEBREAK\E)//s
MC/DC0%0/3
length $$bufferp and $$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(? = \Q$REVERSELINEBREAK\E)//s || $$bufferp =~ s/^(.+?)(? = \Q$REVERSELINEBREAK\E)//s
length $$bufferp
$$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(? = \Q$REVERSELINEBREAK\E)//s
$$bufferp =~ s/^(.+?)(? = \Q$REVERSELINEBREAK\E)//s
Truth table0%0/4
A and B or C
A= length $$bufferpB= $$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(? = \Q$REVERSELINEBREAK\E)//sC= $$bufferp =~ s/^(.+?)(? = \Q$REVERSELINEBREAK\E)//s
| |||||||||||||||||||||||||||||||||||||||||||
| 714 | and $$bufferp | ||||||||||||||||||||||||||||||||||||||||||
| 715 | =~ s/^(\Q$REVERSELINEBREAK\E)(? = \Q$REVERSELINEBREAK\E)//s | ||||||||||||||||||||||||||||||||||||||||||
| 716 | || $$bufferp =~ s/^(.+?)(? = \Q$REVERSELINEBREAK\E)//s) | ||||||||||||||||||||||||||||||||||||||||||
| 717 | { | ||||||||||||||||||||||||||||||||||||||||||
| 718 | 0 | push @$lines, scalar reverse($1); | |||||||||||||||||||||||||||||||||||||||||
| 719 | } | ||||||||||||||||||||||||||||||||||||||||||
| 720 | } else { # no need to require a linebreak, begin of string is | ||||||||||||||||||||||||||||||||||||||||||
| 721 | # ok, too. | ||||||||||||||||||||||||||||||||||||||||||
| 722 | 0 | ▶ | while (length($$bufferp) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
length $$bufferp and $$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(\Q$LINEBREAK\E|\z)/$2/s || $$bufferp =~ s/^(.+?)(\Q$LINEBREAK\E|\z)/$2/s
$$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(\Q$LINEBREAK\E|\z)/$2/s or $$bufferp =~ s/^(.+?)(\Q$LINEBREAK\E|\z)/$2/s
MC/DC0%0/3
length $$bufferp and $$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(\Q$LINEBREAK\E|\z)/$2/s || $$bufferp =~ s/^(.+?)(\Q$LINEBREAK\E|\z)/$2/s
length $$bufferp
$$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(\Q$LINEBREAK\E|\z)/$2/s
$$bufferp =~ s/^(.+?)(\Q$LINEBREAK\E|\z)/$2/s
Truth table0%0/4
A and B or C
A= length $$bufferpB= $$bufferp =~ s/^(\Q$REVERSELINEBREAK\E)(\Q$LINEBREAK\E|\z)/$2/sC= $$bufferp =~ s/^(.+?)(\Q$LINEBREAK\E|\z)/$2/s
| |||||||||||||||||||||||||||||||||||||||||||
| 723 | and $$bufferp | ||||||||||||||||||||||||||||||||||||||||||
| 724 | =~ s/^(\Q$REVERSELINEBREAK\E)(\Q$LINEBREAK\E|\z)/$2/s | ||||||||||||||||||||||||||||||||||||||||||
| 725 | || $$bufferp =~ s/^(.+?)(\Q$LINEBREAK\E|\z)/$2/s) | ||||||||||||||||||||||||||||||||||||||||||
| 726 | { | ||||||||||||||||||||||||||||||||||||||||||
| 727 | 0 | push @$lines, scalar reverse($1); #boah scalar. | |||||||||||||||||||||||||||||||||||||||||
| 728 | } | ||||||||||||||||||||||||||||||||||||||||||
| 729 | } | ||||||||||||||||||||||||||||||||||||||||||
| 730 | } | ||||||||||||||||||||||||||||||||||||||||||
| 731 | 0 | shift @$lines; | |||||||||||||||||||||||||||||||||||||||||
| 732 | } | ||||||||||||||||||||||||||||||||||||||||||
| 733 | } | ||||||||||||||||||||||||||||||||||||||||||
| 734 | |||||||||||||||||||||||||||||||||||||||||||
| 735 | 51 | ▶ | sub content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content: not called CC=1 SCAR=3.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 736 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 737 | |||||||||||||||||||||||||||||||||||||||||||
| 738 | #carp "content: you are using a non-error checking function"; | ||||||||||||||||||||||||||||||||||||||||||
| 739 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 740 | 0 | CORE::readline($self->fh) | |||||||||||||||||||||||||||||||||||||||||
| 741 | } | ||||||||||||||||||||||||||||||||||||||||||
| 742 | |||||||||||||||||||||||||||||||||||||||||||
| 743 | 1 | ▶ | sub xcontent { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xcontent: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 744 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 745 | 1 | undef $!; # neeeded! | |||||||||||||||||||||||||||||||||||||||||
| 746 | 1 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 747 | 1 | my $ref = \scalar CORE::readline($self->fh); | |||||||||||||||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||||||||||||||||
| 749 | # ^- scalar is needed! or it will give undef on empty files. | ||||||||||||||||||||||||||||||||||||||||||
| 750 | 1 | ▶ | croak "xcontent on " . ($self->quotedname) . ": $!" if $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 751 | 1 | $$ref | |||||||||||||||||||||||||||||||||||||||||
| 752 | } | ||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||
| 754 | # bad copypaste.. | ||||||||||||||||||||||||||||||||||||||||||
| 755 | 0 | ▶ | sub xcontentref { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xcontentref: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 756 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 757 | 0 | undef $!; # neeeded! | |||||||||||||||||||||||||||||||||||||||||
| 758 | 0 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 759 | 0 | my $ref = \scalar CORE::readline($self->fh); | |||||||||||||||||||||||||||||||||||||||||
| 760 | |||||||||||||||||||||||||||||||||||||||||||
| 761 | # ^- scalar is needed! or it will give undef on empty files. | ||||||||||||||||||||||||||||||||||||||||||
| 762 | 0 | ▶ | croak "xcontentref on " . ($self->quotedname) . ": $!" if $!; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 763 | 0 | $ref | |||||||||||||||||||||||||||||||||||||||||
| 764 | } | ||||||||||||||||||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||||||||||||||||
| 766 | 0 | ▶ | sub syscontent { # prolly not that efficient | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
syscontent: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 767 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 768 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||||||||
| 769 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 770 | 0 | eval { $buf = \$self->xcontent }; | |||||||||||||||||||||||||||||||||||||||||
| 771 | 0 | ▶ | $@ ? undef : $$buf | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 772 | } | ||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||
| 774 | 51 | ▶ | use constant BUFSIZ => 4096 * 16; # 64kb | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 775 | |||||||||||||||||||||||||||||||||||||||||||
| 776 | 0 | ▶ | sub xsyscontent { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsyscontent: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||
| 778 | # funny, but it seems this is more memory efficient than | ||||||||||||||||||||||||||||||||||||||||||
| 779 | # xcontent?? but it's slower. So it makes mem copies but is able | ||||||||||||||||||||||||||||||||||||||||||
| 780 | # to work with lower memory limits? | ||||||||||||||||||||||||||||||||||||||||||
| 781 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 782 | 0 | my ($buf, @buf); | |||||||||||||||||||||||||||||||||||||||||
| 783 | 0 | ▶ | while ($self->xread($buf, BUFSIZ)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 784 | |||||||||||||||||||||||||||||||||||||||||||
| 785 | # ^ guaranteed to either give true and data or false and it's | ||||||||||||||||||||||||||||||||||||||||||
| 786 | # the end or an exception | ||||||||||||||||||||||||||||||||||||||||||
| 787 | 0 | push @buf, $buf; | |||||||||||||||||||||||||||||||||||||||||
| 788 | } | ||||||||||||||||||||||||||||||||||||||||||
| 789 | 0 | join("", @buf) | |||||||||||||||||||||||||||||||||||||||||
| 790 | } | ||||||||||||||||||||||||||||||||||||||||||
| 791 | |||||||||||||||||||||||||||||||||||||||||||
| 792 | 202 | ▶ | sub print { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
print: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 793 | 202 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 794 | 202 | my $fh = $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 795 | 202 | print $fh @_ | |||||||||||||||||||||||||||||||||||||||||
| 796 | } | ||||||||||||||||||||||||||||||||||||||||||
| 797 | |||||||||||||||||||||||||||||||||||||||||||
| 798 | 49 | ▶ | sub xprint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xprint: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 799 | 49 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 800 | 49 | my $fh = $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 801 | 49 | ▶ | print $fh @_ or croak "xprint to " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 802 | } | ||||||||||||||||||||||||||||||||||||||||||
| 803 | |||||||||||||||||||||||||||||||||||||||||||
| 804 | 0 | ▶ | sub xprintln { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xprintln: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 805 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 806 | 0 | my $fh = $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 807 | 0 | ▶ | print $fh @_, "\n" or croak "xprintln to " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 808 | } | ||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||
| 810 | 0 | ▶ | sub sysprint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sysprint: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 811 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 812 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 813 | 0 | my $rv = eval { $self->xsysprint(@_); }; | |||||||||||||||||||||||||||||||||||||||||
| 814 | 0 | ▶ | $@ ? undef : $rv | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 815 | } | ||||||||||||||||||||||||||||||||||||||||||
| 816 | |||||||||||||||||||||||||||||||||||||||||||
| 817 | # (returns the number of chars written = length of all inputs) | ||||||||||||||||||||||||||||||||||||||||||
| 818 | # XX is this unicode safe? | ||||||||||||||||||||||||||||||||||||||||||
| 819 | 0 | ▶ | sub xsysprint { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsysprint: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 820 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 821 | |||||||||||||||||||||||||||||||||||||||||||
| 822 | # hm, writev(2) would make sense here.. but we are not going that far. | ||||||||||||||||||||||||||||||||||||||||||
| 823 | # Would it make sense to write all parts in individual write calls? | ||||||||||||||||||||||||||||||||||||||||||
| 824 | 0 | ▶ | my $bufref = @_ > 1 ? \join("", @_) : \$_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||
| 826 | # Measurements (perl 5.6.1 iirc) show that join costs a copy even | ||||||||||||||||||||||||||||||||||||||||||
| 827 | # in the nargs==1 case (even with taking a reference), thus we | ||||||||||||||||||||||||||||||||||||||||||
| 828 | # special case it. | ||||||||||||||||||||||||||||||||||||||||||
| 829 | 0 | my $len = length $$bufref; | |||||||||||||||||||||||||||||||||||||||||
| 830 | 0 | my $pos = 0; | |||||||||||||||||||||||||||||||||||||||||
| 831 | 0 | my $n; | |||||||||||||||||||||||||||||||||||||||||
| 832 | 0 | ▶ | while ($pos < $len) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 833 | 0 | ▶ | $pos > 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 834 | ? $n = CORE::syswrite $self->fh, substr($$bufref, $pos) | ||||||||||||||||||||||||||||||||||||||||||
| 835 | : $n = CORE::syswrite $self->fh, $$bufref; | ||||||||||||||||||||||||||||||||||||||||||
| 836 | |||||||||||||||||||||||||||||||||||||||||||
| 837 | # Measurements show that even substr with pos 0 makes a copy, | ||||||||||||||||||||||||||||||||||||||||||
| 838 | # thus we specialcase it. | ||||||||||||||||||||||||||||||||||||||||||
| 839 | 0 | ▶ | defined $n or croak "xsysprint to " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 840 | |||||||||||||||||||||||||||||||||||||||||||
| 841 | # XXX hm, will this die in the EINTR case? (should it?) | ||||||||||||||||||||||||||||||||||||||||||
| 842 | 0 | $pos += $n; | |||||||||||||||||||||||||||||||||||||||||
| 843 | } | ||||||||||||||||||||||||||||||||||||||||||
| 844 | $pos | ||||||||||||||||||||||||||||||||||||||||||
| 845 | 0 | } | |||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||
| 847 | # xsysprintcompletely would be complicated; use xsyswritecompletely | ||||||||||||||||||||||||||||||||||||||||||
| 848 | # instead | ||||||||||||||||||||||||||||||||||||||||||
| 849 | |||||||||||||||||||||||||||||||||||||||||||
| 850 | 51 | our $use_sendfile; # may be set by user if he likes. | |||||||||||||||||||||||||||||||||||||||||
| 851 | 51 | our $sendfile_bufsize = 4096 * 8; # is this somehow relevant for readahead? | |||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||
| 853 | 3 | ▶ | sub xsendfile_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xsendfile_to: called CC=11 SCAR=26.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 854 | 3 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 855 | 3 | my ($out, $offset, $count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 856 | 3 | ▶ | if (!defined $use_sendfile) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 857 | 3 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 858 | 3 | eval { require IO::SendFile; }; | |||||||||||||||||||||||||||||||||||||||||
| 859 | 3 | ▶ | if ($@) { $use_sendfile = 0; } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 860 | 0 | else { $use_sendfile = 1 } | |||||||||||||||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||||||||||||||||
| 862 | ## offset is unclear: from current position (skip like), or begin | ||||||||||||||||||||||||||||||||||||||||||
| 863 | ## of file? (whence is missing) | ||||||||||||||||||||||||||||||||||||||||||
| 864 | 3 | ▶ | $offset ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$offset ||= 0
MC/DC0%0/1
$offset ||= 0
$offset
Truth table50%1/2
A
A= $offset
| |||||||||||||||||||||||||||||||||||||||||||
| 865 | 3 | ▶ | $count = 2**31 - 1 unless defined $count; ## well... | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 866 | |||||||||||||||||||||||||||||||||||||||||||
| 867 | 3 | if (0 && $use_sendfile) { | |||||||||||||||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||||||||||||||||
| 869 | # seems buggy, perhaps with big files (stream-cut script) | ||||||||||||||||||||||||||||||||||||||||||
| 870 | undef $!; | ||||||||||||||||||||||||||||||||||||||||||
| 871 | IO::SendFile::sendfile( | ||||||||||||||||||||||||||||||||||||||||||
| 872 | CORE::fileno $out, | ||||||||||||||||||||||||||||||||||||||||||
| 873 | fileno $self->fh, | ||||||||||||||||||||||||||||||||||||||||||
| 874 | \$offset, $count | ||||||||||||||||||||||||||||||||||||||||||
| 875 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||||||||||||||||
| 877 | # or die "xsendfile_to from ".($self->quotedname).": $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 878 | if ($!) { | ||||||||||||||||||||||||||||||||||||||||||
| 879 | if ($! == EINVAL) { | ||||||||||||||||||||||||||||||||||||||||||
| 880 | warn | ||||||||||||||||||||||||||||||||||||||||||
| 881 | "xsendfile_to: got EINVAL, trying non-sendfile version instead" | ||||||||||||||||||||||||||||||||||||||||||
| 882 | if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||||||||||||||||
| 884 | #copy from below! | ||||||||||||||||||||||||||||||||||||||||||
| 885 | my $buf; | ||||||||||||||||||||||||||||||||||||||||||
| 886 | while ($self->xsysread($buf, $sendfile_bufsize)) { | ||||||||||||||||||||||||||||||||||||||||||
| 887 | $out->xsyswritecompletely($buf); | ||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||
| 889 | #warn "wrote a piece" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 890 | } | ||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||
| 892 | #/copy | ||||||||||||||||||||||||||||||||||||||||||
| 893 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 894 | croak "xsendfile_to from " . $self->quotedname . ": $!" if $!; | ||||||||||||||||||||||||||||||||||||||||||
| 895 | } | ||||||||||||||||||||||||||||||||||||||||||
| 896 | } | ||||||||||||||||||||||||||||||||||||||||||
| 897 | |||||||||||||||||||||||||||||||||||||||||||
| 898 | #warn "offset=$offset now"; no need to loop?, even alarm | ||||||||||||||||||||||||||||||||||||||||||
| 899 | #signals won't interrupt the sendfile call, surprisingly. | ||||||||||||||||||||||||||||||||||||||||||
| 900 | |||||||||||||||||||||||||||||||||||||||||||
| 901 | ## should change position so that it's the same with pureperl | ||||||||||||||||||||||||||||||||||||||||||
| 902 | ## and C implementation. | ||||||||||||||||||||||||||||||||||||||||||
| 903 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 904 | 3 | ▶ | croak "offset not implemented" if $offset; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 905 | |||||||||||||||||||||||||||||||||||||||||||
| 906 | # pure perl: | ||||||||||||||||||||||||||||||||||||||||||
| 907 | 3 | my $buf; | |||||||||||||||||||||||||||||||||||||||||
| 908 | 3 | ▶ | if (defined $count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 909 | 3 | my $tot = 0; | |||||||||||||||||||||||||||||||||||||||||
| 910 | 3 | ▶ | while ($tot < $count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 911 | my $cnt = $self->xsysread( | ||||||||||||||||||||||||||||||||||||||||||
| 912 | $buf, | ||||||||||||||||||||||||||||||||||||||||||
| 913 | 6 | do { | |||||||||||||||||||||||||||||||||||||||||
| 914 | 6 | ▶ | if (($tot + $sendfile_bufsize) <= $count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 915 | 6 | $sendfile_bufsize | |||||||||||||||||||||||||||||||||||||||||
| 916 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 917 | 0 | $count - $tot | |||||||||||||||||||||||||||||||||||||||||
| 918 | } | ||||||||||||||||||||||||||||||||||||||||||
| 919 | |||||||||||||||||||||||||||||||||||||||||||
| 920 | #always hoping that floats are not a problem??..... so ugly prl. | ||||||||||||||||||||||||||||||||||||||||||
| 921 | } | ||||||||||||||||||||||||||||||||||||||||||
| 922 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 923 | 6 | ▶ | last unless $cnt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 924 | 3 | $tot += $cnt; | |||||||||||||||||||||||||||||||||||||||||
| 925 | 3 | $out->xsyswritecompletely($buf); | |||||||||||||||||||||||||||||||||||||||||
| 926 | |||||||||||||||||||||||||||||||||||||||||||
| 927 | #warn "wrote a piece" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 928 | } | ||||||||||||||||||||||||||||||||||||||||||
| 929 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 930 | 0 | ▶ | while ($self->xsysread($buf, $sendfile_bufsize)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 931 | 0 | $out->xsyswritecompletely($buf); | |||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||
| 933 | #warn "wrote a piece" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||||||||||||||||
| 936 | } | ||||||||||||||||||||||||||||||||||||||||||
| 937 | } | ||||||||||||||||||||||||||||||||||||||||||
| 938 | |||||||||||||||||||||||||||||||||||||||||||
| 939 | #*xsendfile = \&xsendfile_to; really? | ||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||
| 941 | # same as xsendfile_to but use read/print from the buffering layer; | ||||||||||||||||||||||||||||||||||||||||||
| 942 | # xsendfile_to should have been called xsyssendfile_to but now it's | ||||||||||||||||||||||||||||||||||||||||||
| 943 | # probably too late right? and I'm resorting to this name: | ||||||||||||||||||||||||||||||||||||||||||
| 944 | |||||||||||||||||||||||||||||||||||||||||||
| 945 | 0 | ▶ | sub xprintfile_to { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xprintfile_to: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 946 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 947 | 0 | ▶ | (@_ >= 1 and @_ <= 2) or croak "xprintfile_to needs 1-3 arguments"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ >= 1 and @_ <= 2
MC/DC0%0/2
@_ >= 1 and @_ <= 2
@_ >= 1
@_ <= 2
Truth table0%0/3
A and B
A= @_ >= 1B= @_ <= 2
| |||||||||||||||||||||||||||||||||||||||||||
| 948 | 0 | my ($out, $offset, $count) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 949 | 0 | ▶ | croak "xprintfile_to: offset currently not implemented" if $offset; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||
| 951 | #almost-copy from xsendfile_to: | ||||||||||||||||||||||||||||||||||||||||||
| 952 | 0 | my $buf; | |||||||||||||||||||||||||||||||||||||||||
| 953 | 0 | ▶ | if (defined $count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 954 | 0 | my $tot = 0; | |||||||||||||||||||||||||||||||||||||||||
| 955 | 0 | ▶ | while ($tot < $count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 956 | my $cnt = $self->xread( | ||||||||||||||||||||||||||||||||||||||||||
| 957 | $buf, | ||||||||||||||||||||||||||||||||||||||||||
| 958 | 0 | do { | |||||||||||||||||||||||||||||||||||||||||
| 959 | 0 | ▶ | if (($tot + $sendfile_bufsize) <= $count) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 960 | 0 | $sendfile_bufsize | |||||||||||||||||||||||||||||||||||||||||
| 961 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 962 | 0 | $count - $tot | |||||||||||||||||||||||||||||||||||||||||
| 963 | } | ||||||||||||||||||||||||||||||||||||||||||
| 964 | |||||||||||||||||||||||||||||||||||||||||||
| 965 | #'always hoping that floats are not a problem??..... so ugly prl.' | ||||||||||||||||||||||||||||||||||||||||||
| 966 | } | ||||||||||||||||||||||||||||||||||||||||||
| 967 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 968 | 0 | ▶ | last unless $cnt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 969 | 0 | $tot += $cnt; | |||||||||||||||||||||||||||||||||||||||||
| 970 | 0 | $out->xprint($buf); | |||||||||||||||||||||||||||||||||||||||||
| 971 | |||||||||||||||||||||||||||||||||||||||||||
| 972 | #warn "wrote a piece" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 973 | } | ||||||||||||||||||||||||||||||||||||||||||
| 974 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 975 | 0 | ▶ | while ($self->xread($buf, $sendfile_bufsize)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 976 | 0 | $out->xprint($buf); | |||||||||||||||||||||||||||||||||||||||||
| 977 | |||||||||||||||||||||||||||||||||||||||||||
| 978 | #warn "wrote a piece" if $DEBUG; | ||||||||||||||||||||||||||||||||||||||||||
| 979 | } | ||||||||||||||||||||||||||||||||||||||||||
| 980 | } | ||||||||||||||||||||||||||||||||||||||||||
| 981 | |||||||||||||||||||||||||||||||||||||||||||
| 982 | #/almostcopy | ||||||||||||||||||||||||||||||||||||||||||
| 983 | } | ||||||||||||||||||||||||||||||||||||||||||
| 984 | |||||||||||||||||||||||||||||||||||||||||||
| 985 | 0 | ▶ | sub xrewind { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xrewind: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 986 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 987 | 0 | ▶ | seek $self->fh, 0, 0 or croak "xrewind on " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 988 | 0 | ▶ | sysseek $self->fh, 0, 0 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 989 | or croak "xrewind on " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 990 | } | ||||||||||||||||||||||||||||||||||||||||||
| 991 | |||||||||||||||||||||||||||||||||||||||||||
| 992 | 0 | ▶ | sub xseek { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xseek: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 993 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 994 | 0 | ▶ | @_ == 1 or @_ == 2 or fp_croak_arity "1 or 2"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 or @_ == 2
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1
@_ == 2
Truth table0%0/3
A or B
A= @_ == 1B= @_ == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 995 | 0 | ▶ | seek $self->fh, $_[0], defined $_[1] ? $_[1] : SEEK_SET | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 996 | or croak "xseek on " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 997 | } | ||||||||||||||||||||||||||||||||||||||||||
| 998 | |||||||||||||||||||||||||||||||||||||||||||
| 999 | 19 | ▶ | sub seek { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
seek: called CC=4 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1000 | 19 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1001 | 19 | ▶ | @_ == 1 or @_ == 2 or fp_croak_arity "1 or 2"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@_ == 1 or @_ == 2
MC/DC0%0/2
@_ == 1 or @_ == 2
@_ == 1
@_ == 2
Truth table33%1/3
A or B
A= @_ == 1B= @_ == 2
| |||||||||||||||||||||||||||||||||||||||||||
| 1002 | 19 | ▶ | seek $self->fh, $_[0], defined $_[1] ? $_[1] : SEEK_SET; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1003 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1004 | |||||||||||||||||||||||||||||||||||||||||||
| 1005 | 0 | ▶ | sub xtell { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xtell: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1006 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1007 | 0 | ▶ | @_ == 0 or fp_croak_arity 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1008 | 0 | my $res = tell $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 1009 | 0 | ▶ | if ($res == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1010 | 0 | croak "xtell on " . ($self->quotedname) . ": $!"; | |||||||||||||||||||||||||||||||||||||||||
| 1011 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1012 | 0 | $res | |||||||||||||||||||||||||||||||||||||||||
| 1013 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1014 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1015 | |||||||||||||||||||||||||||||||||||||||||||
| 1016 | 0 | ▶ | sub tell { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tell: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1017 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1018 | 0 | ▶ | @_ == 0 or fp_croak_arity 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1019 | 0 | my $res = tell $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 1020 | 0 | ▶ | if ($res == -1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1021 | undef | ||||||||||||||||||||||||||||||||||||||||||
| 1022 | 0 | } else { | |||||||||||||||||||||||||||||||||||||||||
| 1023 | 0 | $res | |||||||||||||||||||||||||||||||||||||||||
| 1024 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1025 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1026 | |||||||||||||||||||||||||||||||||||||||||||
| 1027 | 0 | ▶ | sub xtruncate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xtruncate: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1028 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1029 | 0 | my ($len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1030 | 0 | ▶ | $len ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$len ||= 0
MC/DC0%0/1
$len ||= 0
$len
Truth table0%0/2
A
A= $len
| |||||||||||||||||||||||||||||||||||||||||||
| 1031 | 0 | ▶ | truncate($self->fh, $len) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1032 | or croak "xtruncate on " . ($self->quotedname) . ": $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 1033 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1034 | |||||||||||||||||||||||||||||||||||||||||||
| 1035 | 0 | ▶ | sub truncate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
truncate: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 1036 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1037 | 0 | my ($len) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1038 | 0 | ▶ | $len ||= 0; | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$len ||= 0
MC/DC0%0/1
$len ||= 0
$len
Truth table0%0/2
A
A= $len
| |||||||||||||||||||||||||||||||||||||||||||
| 1039 | 0 | truncate($self->fh, $len); | |||||||||||||||||||||||||||||||||||||||||
| 1040 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1041 | |||||||||||||||||||||||||||||||||||||||||||
| 1042 | 0 | ▶ | sub dup2 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dup2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1043 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1044 | 0 | local $@; | |||||||||||||||||||||||||||||||||||||||||
| 1045 | 0 | eval { # slow and lazy way | |||||||||||||||||||||||||||||||||||||||||
| 1046 | 0 | $self->xdup2(@_); | |||||||||||||||||||||||||||||||||||||||||
| 1047 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 1048 | 0 | !$@ | |||||||||||||||||||||||||||||||||||||||||
| 1049 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1050 | |||||||||||||||||||||||||||||||||||||||||||
| 1051 | 0 | ▶ | sub xdup2 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xdup2: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1052 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1053 | 0 | my $myfileno = CORE::fileno $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 1054 | 0 | ▶ | defined $myfileno | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1055 | or croak("xdup2: filehandle of " | ||||||||||||||||||||||||||||||||||||||||||
| 1056 | . $self->quotedname | ||||||||||||||||||||||||||||||||||||||||||
| 1057 | . " is undefined (maybe it's closed?)"); | ||||||||||||||||||||||||||||||||||||||||||
| 1058 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 1059 | 0 | for my $dup (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 1060 | 0 | ▶ | my $fileno = $dup =~ /^\d+\z/s ? $dup : CORE::fileno $dup; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1061 | 0 | ▶ | defined $fileno | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1062 | or croak("xdup2: filehandle $dup returns no fileno " | ||||||||||||||||||||||||||||||||||||||||||
| 1063 | . "(maybe it's closed?)"); | ||||||||||||||||||||||||||||||||||||||||||
| 1064 | |||||||||||||||||||||||||||||||||||||||||||
| 1065 | #open $dup,'<&'.$myfileno or croak "?: $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 1066 | # Works for reading handles. Problem: must use < or > | ||||||||||||||||||||||||||||||||||||||||||
| 1067 | # depending on handle, | ||||||||||||||||||||||||||||||||||||||||||
| 1068 | # even +> does not work instead of <. | ||||||||||||||||||||||||||||||||||||||||||
| 1069 | # Thus instead: | ||||||||||||||||||||||||||||||||||||||||||
| 1070 | 0 | ▶ | POSIX::dup2($myfileno, $fileno) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1071 | or croak("xdup2 " | ||||||||||||||||||||||||||||||||||||||||||
| 1072 | . $self->quotedname | ||||||||||||||||||||||||||||||||||||||||||
| 1073 | . " (fd $myfileno) to $dup (fd $fileno): $!"); | ||||||||||||||||||||||||||||||||||||||||||
| 1074 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1075 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1076 | |||||||||||||||||||||||||||||||||||||||||||
| 1077 | 0 | ▶ | sub xdup { # (return objects) | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xdup: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1078 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1079 | 0 | warn | |||||||||||||||||||||||||||||||||||||||||
| 1080 | "xdup: this method is unfinished and only can create output filehandles yet"; | ||||||||||||||||||||||||||||||||||||||||||
| 1081 | 0 | my $myfileno = CORE::fileno $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 1082 | 0 | ▶ | defined $myfileno | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1083 | or croak "xdup: filehandle of " | ||||||||||||||||||||||||||||||||||||||||||
| 1084 | . ($self->quotedname) | ||||||||||||||||||||||||||||||||||||||||||
| 1085 | . " is undefined (maybe it's closed?)"; | ||||||||||||||||||||||||||||||||||||||||||
| 1086 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 1087 | 0 | ▶ | my $fd = POSIX::dup($myfileno) | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
POSIX::dup($myfileno) // croak('xdup ' . $self->quotedname . " (fd $myfileno): $!")
MC/DC0%0/1
POSIX::dup($myfileno) // croak('xdup ' . $self->quotedname . " (fd $myfileno): $!")
POSIX::dup($myfileno)
Truth table0%0/2
A
A= POSIX::dup($myfileno)
| |||||||||||||||||||||||||||||||||||||||||||
| 1088 | // croak "xdup " . $self->quotedname . " (fd $myfileno): $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 1089 | |||||||||||||||||||||||||||||||||||||||||||
| 1090 | # turn an fd into a perl filehandle: | ||||||||||||||||||||||||||||||||||||||||||
| 1091 | # IO::Handle has: if ($io->fdopen(CORE::fileno(STDIN),"r")) { | ||||||||||||||||||||||||||||||||||||||||||
| 1092 | # which works like: open($io, _open_mode_string($mode) . '&' . $fd) | ||||||||||||||||||||||||||||||||||||||||||
| 1093 | # XX HACK: | ||||||||||||||||||||||||||||||||||||||||||
| 1094 | 0 | my $new = ref($self)->new; | |||||||||||||||||||||||||||||||||||||||||
| 1095 | 0 | ▶ | open $new, ">& = $fd" ## no critic | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1096 | or die "xdup: error building perl fh from fd $fd"; | ||||||||||||||||||||||||||||||||||||||||||
| 1097 | 0 | $new | |||||||||||||||||||||||||||||||||||||||||
| 1098 | |||||||||||||||||||||||||||||||||||||||||||
| 1099 | # XX hm IO::Handle::fdopen is checkint if it's a glob already | ||||||||||||||||||||||||||||||||||||||||||
| 1100 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1101 | |||||||||||||||||||||||||||||||||||||||||||
| 1102 | 0 | ▶ | sub xdupfd { # return integers | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xdupfd: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1103 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1104 | 0 | require POSIX; | |||||||||||||||||||||||||||||||||||||||||
| 1105 | 0 | my $myfileno = CORE::fileno $s; | |||||||||||||||||||||||||||||||||||||||||
| 1106 | 0 | ▶ | defined $myfileno | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1107 | or croak "xdup: filehandle of " | ||||||||||||||||||||||||||||||||||||||||||
| 1108 | . ($s->quotedname) | ||||||||||||||||||||||||||||||||||||||||||
| 1109 | . " is undefined (maybe it's closed?)"; | ||||||||||||||||||||||||||||||||||||||||||
| 1110 | 0 | ▶ | POSIX::dup($myfileno) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1111 | or croak "xdup " . $s->quotedname . " (fd $myfileno): $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 1112 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1113 | |||||||||||||||||||||||||||||||||||||||||||
| 1114 | 0 | ▶ | sub autoflush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
autoflush: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1115 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1116 | 0 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1117 | 0 | my ($v) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1118 | 0 | my $old = select $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 1119 | 0 | my $oldv = $|; | |||||||||||||||||||||||||||||||||||||||||
| 1120 | 0 | $| = $v; | |||||||||||||||||||||||||||||||||||||||||
| 1121 | 0 | select $old; | |||||||||||||||||||||||||||||||||||||||||
| 1122 | 0 | $oldv | |||||||||||||||||||||||||||||||||||||||||
| 1123 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1124 | defined wantarray ## no critic | ||||||||||||||||||||||||||||||||||||||||||
| 1125 | 0 | ▶ | or croak | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1126 | "autoflush: used in void context without arguments (note that this is " | ||||||||||||||||||||||||||||||||||||||||||
| 1127 | . __PACKAGE__ | ||||||||||||||||||||||||||||||||||||||||||
| 1128 | . ", not IO::Handle)"; | ||||||||||||||||||||||||||||||||||||||||||
| 1129 | 0 | my $old = select $self->fh; | |||||||||||||||||||||||||||||||||||||||||
| 1130 | 0 | my $oldv = $|; | |||||||||||||||||||||||||||||||||||||||||
| 1131 | 0 | select $old; | |||||||||||||||||||||||||||||||||||||||||
| 1132 | 0 | $oldv | |||||||||||||||||||||||||||||||||||||||||
| 1133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1134 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1135 | |||||||||||||||||||||||||||||||||||||||||||
| 1136 | 0 | ▶ | sub flush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
flush: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1137 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1138 | 0 | require IO::Handle; | |||||||||||||||||||||||||||||||||||||||||
| 1139 | 0 | IO::Handle::flush($self->fh); | |||||||||||||||||||||||||||||||||||||||||
| 1140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1141 | |||||||||||||||||||||||||||||||||||||||||||
| 1142 | 0 | ▶ | sub xflush { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xflush: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1143 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1144 | 0 | require IO::Handle; | |||||||||||||||||||||||||||||||||||||||||
| 1145 | 0 | ▶ | IO::Handle::flush($self->fh) or die "xflush " . $self->quotedname . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1147 | |||||||||||||||||||||||||||||||||||||||||||
| 1148 | 275 | ▶ | sub xclose { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xclose: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1149 | 275 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1150 | 275 | ▶ | CORE::close $self->fh or croak "xclose " . $self->quotedname . ": $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1151 | 275 | $self->set_opened(0); | |||||||||||||||||||||||||||||||||||||||||
| 1152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1153 | |||||||||||||||||||||||||||||||||||||||||||
| 1154 | 0 | ▶ | sub close { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
close: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1155 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1156 | 0 | CORE::close($s); | |||||||||||||||||||||||||||||||||||||||||
| 1157 | 0 | $s->set_opened(0); | |||||||||||||||||||||||||||||||||||||||||
| 1158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1159 | |||||||||||||||||||||||||||||||||||||||||||
| 1160 | 51 | *xxfinish = \&xclose; | |||||||||||||||||||||||||||||||||||||||||
| 1161 | 51 | *xfinish = \&xclose; | |||||||||||||||||||||||||||||||||||||||||
| 1162 | |||||||||||||||||||||||||||||||||||||||||||
| 1163 | 0 | ▶ | sub xunlink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xunlink: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1164 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1165 | 0 | my $path = $self->xpath; | |||||||||||||||||||||||||||||||||||||||||
| 1166 | 0 | ▶ | unlink $path or croak "xunlink '$path': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1167 | 0 | $self->unset_path; | |||||||||||||||||||||||||||||||||||||||||
| 1168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1169 | |||||||||||||||||||||||||||||||||||||||||||
| 1170 | 0 | ▶ | sub xlink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlink: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1171 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1172 | 0 | my ($newpath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1173 | 0 | my $path = $self->xpath; | |||||||||||||||||||||||||||||||||||||||||
| 1174 | 0 | ▶ | link $path, $newpath or croak "xlink '$path','$newpath': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1175 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1176 | |||||||||||||||||||||||||||||||||||||||||||
| 1177 | 7 | ▶ | sub xrename { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xrename: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1178 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1179 | 7 | my ($to) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1180 | 7 | my $path = $self->xpath; | |||||||||||||||||||||||||||||||||||||||||
| 1181 | 7 | ▶ | rename $path, $to or croak "xrename '$path' to '$to': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1182 | 7 | $self->set_path($to); | |||||||||||||||||||||||||||||||||||||||||
| 1183 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1184 | |||||||||||||||||||||||||||||||||||||||||||
| 1185 | 0 | ▶ | sub xlinkunlink { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xlinkunlink: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1186 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1187 | 0 | my ($newpath) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1188 | 0 | my $path = $self->xpath; | |||||||||||||||||||||||||||||||||||||||||
| 1189 | 0 | ▶ | link $path, $newpath or croak "xlinkunlink: link '$path','$newpath': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1190 | 0 | ▶ | unlink $path or croak "xlinkunlink: unlink '$path': $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1191 | 0 | $self->set_path($newpath); | |||||||||||||||||||||||||||||||||||||||||
| 1192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1193 | |||||||||||||||||||||||||||||||||||||||||||
| 1194 | 51 | ▶ | if ($has_posix) { # untested? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1195 | 0 | ▶ | *stat = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1196 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1197 | 0 | ▶ | if (defined(my $fd = CORE::fileno($self->fh))) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1198 | 0 | POSIX::fstat($fd); | |||||||||||||||||||||||||||||||||||||||||
| 1199 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1200 | 0 | (); ## or die? | |||||||||||||||||||||||||||||||||||||||||
| 1201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1202 | 51 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1203 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1204 | 0 | ▶ | *stat = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1205 | 0 | die( "this system does not have POSIX so we can't fstat; " | |||||||||||||||||||||||||||||||||||||||||
| 1206 | . "if you wish you could stat the saved filename instead, " | ||||||||||||||||||||||||||||||||||||||||||
| 1207 | . "though that could be dangerous; died"); | ||||||||||||||||||||||||||||||||||||||||||
| 1208 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1210 | |||||||||||||||||||||||||||||||||||||||||||
| 1211 | 0 | ▶ | sub xstat { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
xstat: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1212 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1213 | 0 | require Chj::xperlfunc; | |||||||||||||||||||||||||||||||||||||||||
| 1214 | 0 | Chj::xperlfunc::xstat($s) | |||||||||||||||||||||||||||||||||||||||||
| 1215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1216 | |||||||||||||||||||||||||||||||||||||||||||
| 1217 | 0 | ▶ | sub fileno { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fileno: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1218 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1219 | 0 | CORE::fileno($s) | |||||||||||||||||||||||||||||||||||||||||
| 1220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1221 | |||||||||||||||||||||||||||||||||||||||||||
| 1222 | 0 | ▶ | sub eof { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
eof: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 1223 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1224 | 0 | CORE::eof($s) | |||||||||||||||||||||||||||||||||||||||||
| 1225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1226 | |||||||||||||||||||||||||||||||||||||||||||
| 1227 | 51 | ▶ | if ($has_posix) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1228 | 51 | my $_base; | |||||||||||||||||||||||||||||||||||||||||
| 1229 | 0 | ▶ | my $base = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1230 | 0 | ▶ | $_base //= do { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_base //= do {
if (-d "/dev/fd") {
"/dev/fd";
}
elsif (-d "/proc/self/fd") {
"/proc/self/fd";
}
else {
die "missing /dev/fd or /proc/self/fd";
}
}
MC/DC0%0/2
$_base //= do {
if (-d "/dev/fd") {
"/dev/fd";
}
elsif (-d "/proc/self/fd") {
"/proc/self/fd";
}
else {
die "missing /dev/fd or /proc/self/fd";
}
}
$_base
do {
if (-d "/dev/fd") {
"/dev/fd";
}
elsif (-d "/proc/self/fd") {
"/proc/self/fd";
}
else {
die "missing /dev/fd or /proc/self/fd";
}
}
Truth table0%0/3
A //= B
A= $_baseB= do {
if (-d "/dev/fd") {
"/dev/fd";
}
elsif (-d "/proc/self/fd") {
"/proc/self/fd";
}
else {
die "missing /dev/fd or /proc/self/fd";
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 1231 | 0 | ▶ | if (-d "/dev/fd") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 1232 | 0 | "/dev/fd" | |||||||||||||||||||||||||||||||||||||||||
| 1233 | } elsif (-d "/proc/self/fd") { | ||||||||||||||||||||||||||||||||||||||||||
| 1234 | 0 | "/proc/self/fd" | |||||||||||||||||||||||||||||||||||||||||
| 1235 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 1236 | 0 | die "missing /dev/fd or /proc/self/fd" | |||||||||||||||||||||||||||||||||||||||||
| 1237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1239 | 51 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1240 | 0 | ▶ | *Fd_dev_path = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1241 | 0 | my ($fileno) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 1242 | 0 | &$base() . "/" . $fileno | |||||||||||||||||||||||||||||||||||||||||
| 1243 | 51 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1244 | 0 | ▶ | *fd_dev_path = sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 1245 | 0 | my $s = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1246 | 0 | Fd_dev_path(CORE::fileno($s)) | |||||||||||||||||||||||||||||||||||||||||
| 1247 | 51 | }; | |||||||||||||||||||||||||||||||||||||||||
| 1248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1249 | |||||||||||||||||||||||||||||||||||||||||||
| 1250 | 244 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 1251 | 244 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 1252 | 244 | local ($@, $!, $?, $_); | |||||||||||||||||||||||||||||||||||||||||
| 1253 | 244 | ▶ | if ($self->opened) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1254 | 2 | ▶ | CORE::close($self->fh) or carp "$self DESTROY: close: $!"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 1255 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1256 | 244 | delete $filemetadata{ pack "I", $self }; | |||||||||||||||||||||||||||||||||||||||||
| 1257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 1258 | |||||||||||||||||||||||||||||||||||||||||||
| 1259 | 51 | 1 | |||||||||||||||||||||||||||||||||||||||||