| 1 | package Command::Run::Tmpfile; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 41 | ▶ | use v5.14; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 41 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 41 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 41 | ▶ | use Carp; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 41 | ▶ | use Fcntl; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 41 | ▶ | use IO::File; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 41 | ▶ | use IO::Handle; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 41 | my $fdpath; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 245 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=8 SCAR=21.3
Pod
documented
| |||||||||||||||||||||
| 14 | 245 | my $class = shift; | |||||||||||||||||||
| 15 | 245 | my %opt = @_; | |||||||||||||||||||
| 16 | 245 | ▶ | my $fh = new_tmpfile IO::File or die "new_tmpfile: $!\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 17 | 245 | ▶ | $fh->fcntl(F_SETFD, 0) or die "fcntl F_SETFD: $!\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 18 | 245 | ▶ | binmode $fh, $opt{raw} ? ':raw' : ':encoding(utf8)'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 19 | # Determine usable fd-path on first instantiation, using the fd we | ||||||||||||||||||||
| 20 | # just allocated. Checking only "$path/0" is insufficient on | ||||||||||||||||||||
| 21 | # FreeBSD where /dev/fd/0,1,2 always exist as device nodes but | ||||||||||||||||||||
| 22 | # /dev/fd/N (N>2) requires fdescfs to be mounted. | ||||||||||||||||||||
| 23 | 245 | ▶ | $fdpath //= do { | ||||||||||||||||||
|
Condition66%2/3
$fdpath //= do {
my $fd = $fh->fileno;
my $found;
foreach my $path ("/proc/self/fd", "/dev/fd") {
-r "$path/$fd" and do {
$found = $path;
last
};
};
$found // ""
}
MC/DC0%0/2
$fdpath //= do {
my $fd = $fh->fileno;
my $found;
foreach my $path ("/proc/self/fd", "/dev/fd") {
-r "$path/$fd" and do {
$found = $path;
last
};
};
$found // ""
}
$fdpath
do {
my $fd = $fh->fileno;
my $found;
foreach my $path ("/proc/self/fd", "/dev/fd") {
-r "$path/$fd" and do {
$found = $path;
last
};
};
$found // ""
}
Truth table66%2/3
A //= B
A= $fdpathB= do {
my $fd = $fh->fileno;
my $found;
foreach my $path ("/proc/self/fd", "/dev/fd") {
-r "$path/$fd" and do {
$found = $path;
last
};
};
$found // ""
}
| |||||||||||||||||||||
| 24 | 40 | my $fd = $fh->fileno; | |||||||||||||||||||
| 25 | 40 | my $found; | |||||||||||||||||||
| 26 | 40 | for my $path (qw(/proc/self/fd /dev/fd)) { | |||||||||||||||||||
| 27 | 40 | ▶ | -r "$path/$fd" and do { $found = $path; last }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | 40 | ▶ | $found // ''; | ||||||||||||||||||
|
Condition50%1/2
$found // ""
MC/DC0%0/1
$found // ""
$found
Truth table50%1/2
A
A= $found
| |||||||||||||||||||||
| 30 | }; | ||||||||||||||||||||
| 31 | 245 | bless { FH => $fh }, $class; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | |||||||||||||||||||||
| 34 | 5 | ▶ | sub write { | ||||||||||||||||||
|
Subroutine
write: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||
| 35 | 5 | my $obj = shift; | |||||||||||||||||||
| 36 | 5 | my $fh = $obj->fh; | |||||||||||||||||||
| 37 | 5 | ▶ | if (@_) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 38 | 5 | my $data = join '', @_; | |||||||||||||||||||
| 39 | 5 | $fh->print($data); | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | 5 | $obj; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 4 | ▶ | sub flush { | ||||||||||||||||||
|
Subroutine
flush: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 45 | 4 | my $obj = shift; | |||||||||||||||||||
| 46 | 4 | $obj->fh->flush; | |||||||||||||||||||
| 47 | 4 | $obj; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 5 | ▶ | sub rewind { | ||||||||||||||||||
|
Subroutine
rewind: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 51 | 5 | my $obj = shift; | |||||||||||||||||||
| 52 | 5 | ▶ | $obj->fh->seek(0, 0) or die "seek: $!\n"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 53 | 5 | $obj; | |||||||||||||||||||
| 54 | } | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | ▶ | sub reset { | ||||||||||||||||||
|
Subroutine
reset: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 57 | 1 | my $obj = shift; | |||||||||||||||||||
| 58 | 1 | $obj->rewind; | |||||||||||||||||||
| 59 | 1 | $obj->fh->truncate(0); | |||||||||||||||||||
| 60 | 1 | $obj; | |||||||||||||||||||
| 61 | } | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | 233 | ▶ | sub fh { | ||||||||||||||||||
|
Subroutine
fh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 64 | 233 | my $obj = shift; | |||||||||||||||||||
| 65 | 233 | $obj->{FH}; | |||||||||||||||||||
| 66 | } | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 11 | ▶ | sub fd { | ||||||||||||||||||
|
Subroutine
fd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||
| 69 | 11 | my $obj = shift; | |||||||||||||||||||
| 70 | 11 | $obj->fh->fileno; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 9 | ▶ | sub path { | ||||||||||||||||||
|
Subroutine
path: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 74 | 9 | my $obj = shift; | |||||||||||||||||||
| 75 | 9 | ▶ | return undef unless $fdpath; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | 9 | sprintf "%s/%d", $fdpath, $obj->fd; | |||||||||||||||||||
| 77 | } | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | 41 | 1; | |||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | __END__ | ||||||||||||||||||||