| 1 | package IO::Factotum; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 54 | ▶ | use v5.16; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 54 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 54 | our $VERSION = "0.05"; | |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 54 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 54 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 54 | ▶ | use IO::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 54 | ▶ | use IO::Handle; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 54 | ▶ | use File::Spec; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 54 | ▶ | use POSIX (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | 54 | ▶ | use Command::Run::Tmpfile; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 54 | my @converter; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 102 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: called CC=14 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 102 | my %arg = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | 102 | my $match = delete $arg{match}; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 102 | my $command = delete $arg{command}; | |||||||||||||||||||||||||||||||||||||||||
| 22 | 102 | my $with = delete $arg{with}; | |||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | croak "register: unknown parameter: @{[ sort keys %arg ]}" if %arg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 24 | 102 | ▶ | if (defined $with) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | # An object which gives the content of a file by its method | ||||||||||||||||||||||||||||||||||||||||||
| 26 | # file. It tells by itself which files are its own, so match | ||||||||||||||||||||||||||||||||||||||||||
| 27 | # is not required. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 20 | ▶ | croak "register: with and command can not be given together" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | if defined $command; | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 18 | ▶ | Scalar::Util::blessed($with) && $with->can('file') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
builtin::blessed($with) and $with->can("file")
MC/DC100%2/2
builtin::blessed($with) and $with->can("file")
builtin::blessed($with)
$with->can("file")
Truth table100%3/3
A and B
A= builtin::blessed($with)B= $with->can("file")
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | or croak "register: with must be an object which has the method file"; | ||||||||||||||||||||||||||||||||||||||||||
| 32 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 33 | 82 | ▶ | $match // croak "register: match is required"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$match // croak("register: match is required")
MC/DC100%1/1
$match // croak("register: match is required")
$match
Truth table100%2/2
A
A= $match
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 80 | ▶ | $command // croak "register: command is required"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$command // croak("register: command is required")
MC/DC0%0/1
$command // croak("register: command is required")
$command
Truth table50%1/2
A
A= $command
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 80 | ▶ | ref $command eq 'ARRAY' && @$command | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $command eq "ARRAY" and @$command
MC/DC0%0/2
ref $command eq "ARRAY" and @$command
ref $command eq "ARRAY"
@$command
Truth table33%1/3
A and B
A= ref $command eq "ARRAY"B= @$command
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | or croak "register: command must be an array reference"; | ||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | 94 | ▶ | !defined $match or ref $match eq 'Regexp' or ref $match eq 'CODE' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not defined $match or ref $match eq "Regexp" or ref $match eq "CODE"
not defined $match or ref $match eq "Regexp"
MC/DC0%0/3
not defined $match or ref $match eq "Regexp" or ref $match eq "CODE"
not defined $match
ref $match eq "Regexp"
ref $match eq "CODE"
Truth table75%3/4
not(A) or B or C
A= not defined $matchB= ref $match eq "Regexp"C= ref $match eq "CODE"
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | or croak "register: match must be a regex or a code reference"; | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 94 | ▶ | push @converter, { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | match => $match, | ||||||||||||||||||||||||||||||||||||||||||
| 42 | defined $with ? (with => $with) : (command => [ @$command ]), | ||||||||||||||||||||||||||||||||||||||||||
| 43 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 94 | return; | |||||||||||||||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 49 | ▶ | sub clear { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clear: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 49 | @converter = (); | |||||||||||||||||||||||||||||||||||||||||
| 49 | 49 | return; | |||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | # The converters which take the file, in the order they were registered | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 124 | ▶ | sub converter { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
converter: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 124 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 55 | grep { | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 124 | my $match = $_->{match}; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 131 | ▶ | !defined $match or ref $match eq 'CODE' ? $match->($file) : $file =~ $match; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
!defined($match) || (ref $match eq 'CODE' ? &$match($file) : $file =~ /$match/u)
MC/DC100%2/2
!defined($match) || (ref $match eq 'CODE' ? &$match($file) : $file =~ /$match/u)
!defined($match)
(ref $match eq 'CODE' ? &$match($file) : $file =~ /$match/u)
Truth table100%3/3
not(A) || B
A= !defined($match)B= (ref $match eq 'CODE' ? &$match($file) : $file =~ /$match/u)
| |||||||||||||||||||||||||||||||||||||||||||
| 58 | } @converter; | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 136 | ▶ | sub open_input { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_input: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | 136 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | # The standard input is read as it is, by STDIN itself: another | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # handle on it would not see what STDIN has read ahead | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 136 | ▶ | return *STDIN{IO} if $file eq '-'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # The file is opened first: a file which can not be read is an | ||||||||||||||||||||||||||||||||||||||||||
| 69 | # error of the caller with $! set, whatever the converter does | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 132 | ▶ | my $fh = IO::File->new($file, '<') // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
"IO::File"->new($file, "<") // (return undef)
MC/DC100%1/1
"IO::File"->new($file, "<") // (return undef)
"IO::File"->new($file, "<")
Truth table100%2/2
A
A= "IO::File"->new($file, "<")
| |||||||||||||||||||||||||||||||||||||||||||
| 71 | 124 | binmode $fh, ':raw'; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 124 | for my $c (converter($file)) { | |||||||||||||||||||||||||||||||||||||||||
| 74 | 111 | ▶ | if (my $with = $c->{with}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | # an object which gives nothing passes the file to the next | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 17 | ▶ | my $converted = content($with, $file) // next; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
content($with, $file) // (next)
MC/DC100%1/1
content($with, $file) // (next)
content($with, $file)
Truth table100%2/2
A
A= content($with, $file)
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 11 | return $converted; | |||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||
| 79 | # a command which fails leaves the file as it is | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 94 | ▶ | return convert($c->{command}, $file) // $fh; | ||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
convert($c->{"command"}, $file) // $fh
MC/DC0%0/2
convert($c->{"command"}, $file) // $fh
convert($c->{"command"}, $file)
$fh
Truth table66%2/3
A // B
A= convert($c->{"command"}, $file)B= $fh
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 19 | $fh; | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | # Ask the object for the content of the file, and return the handle of | ||||||||||||||||||||||||||||||||||||||||||
| 86 | # a temporary file which has it, or undef when the object gives | ||||||||||||||||||||||||||||||||||||||||||
| 87 | # nothing, or dies. Characters are written as UTF-8. | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 17 | ▶ | sub content { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
content: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 17 | my($with, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 17 | ▶ | my $content = eval { $with->file($file) } // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
eval {
do {
$with->file($file)
}
} // (return undef)
MC/DC100%1/1
eval {
do {
$with->file($file)
}
} // (return undef)
eval {
do {
$with->file($file)
}
}
Truth table100%2/2
A
A= eval {
do {
$with->file($file)
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 91 | 11 | ▶ | utf8::encode($content) if utf8::is_utf8($content); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 11 | my $tmp = Command::Run::Tmpfile->new(raw => 1); | |||||||||||||||||||||||||||||||||||||||||
| 93 | 11 | my $fh = $tmp->fh; | |||||||||||||||||||||||||||||||||||||||||
| 94 | 11 | ▶ | print $fh $content or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 11 | $fh->flush; | |||||||||||||||||||||||||||||||||||||||||
| 96 | 11 | ▶ | $fh->seek(0, 0) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 11 | $fh; | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | # Run the command with the file name, in a process of its own, and | ||||||||||||||||||||||||||||||||||||||||||
| 101 | # return the handle of a temporary file which has what it wrote to the | ||||||||||||||||||||||||||||||||||||||||||
| 102 | # standard output, or undef when it fails. The output goes to the file | ||||||||||||||||||||||||||||||||||||||||||
| 103 | # as it is, byte for byte. The standard error is thrown away. | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 94 | ▶ | sub convert { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
convert: called CC=11 SCAR=26.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 94 | my($command, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 94 | my @command = (@$command, $file); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 94 | my $tmp = Command::Run::Tmpfile->new(raw => 1); | |||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | # $? and $! of the caller are kept, and the child is waited for | ||||||||||||||||||||||||||||||||||||||||||
| 110 | # even when the caller ignores SIGCHLD | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 94 | local($?, $!); | |||||||||||||||||||||||||||||||||||||||||
| 112 | 94 | local $SIG{CHLD} = 'DEFAULT'; | |||||||||||||||||||||||||||||||||||||||||
| 113 | # what is in the buffers is not to be written twice | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 94 | STDOUT->flush; | |||||||||||||||||||||||||||||||||||||||||
| 115 | 94 | STDERR->flush; | |||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||
| 117 | 94 | ▶ | my $pid = fork // return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
fork // (return undef)
MC/DC0%0/1
fork // (return undef)
fork
Truth table50%1/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 94 | ▶ | if ($pid == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | # The child never returns to the program: it ends by _exit, so | ||||||||||||||||||||||||||||||||||||||||||
| 120 | # that the END blocks and the destructors of the program do not | ||||||||||||||||||||||||||||||||||||||||||
| 121 | # run here, even when open_input is called inside eval. | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 31 | ▶ | my $status = eval { | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
eval {
do {
open STDIN, "<", "File::Spec"->devnull or die;
open STDOUT, ">&", $tmp->fh or die;
open STDERR, ">", "File::Spec"->devnull or die;
binmode STDOUT, ":raw";
if (ref $command[0] eq "CODE") {
my $code = shift @command;
&$code(@command);
"STDOUT"->flush;
0;
}
else {
BEGIN {${^WARNING_BITS} = "\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"}
exec {$command[0];} @command or POSIX::_exit(127);
}
}
} // 1
MC/DC0%0/1
eval {
do {
open STDIN, "<", "File::Spec"->devnull or die;
open STDOUT, ">&", $tmp->fh or die;
open STDERR, ">", "File::Spec"->devnull or die;
binmode STDOUT, ":raw";
if (ref $command[0] eq "CODE") {
my $code = shift @command;
&$code(@command);
"STDOUT"->flush;
0;
}
else {
BEGIN {${^WARNING_BITS} = "\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"}
exec {$command[0];} @command or POSIX::_exit(127);
}
}
} // 1
eval {
do {
open STDIN, "<", "File::Spec"->devnull or die;
open STDOUT, ">&", $tmp->fh or die;
open STDERR, ">", "File::Spec"->devnull or die;
binmode STDOUT, ":raw";
if (ref $command[0] eq "CODE") {
my $code = shift @command;
&$code(@command);
"STDOUT"->flush;
0;
}
else {
BEGIN {${^WARNING_BITS} = "\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"}
exec {$command[0];} @command or POSIX::_exit(127);
}
}
}
Truth table0%0/2
A
A= eval {
do {
open STDIN, "<", "File::Spec"->devnull or die;
open STDOUT, ">&", $tmp->fh or die;
open STDERR, ">", "File::Spec"->devnull or die;
binmode STDOUT, ":raw";
if (ref $command[0] eq "CODE") {
my $code = shift @command;
&$code(@command);
"STDOUT"->flush;
0;
}
else {
BEGIN {${^WARNING_BITS} = "\x55\x15\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55"}
exec {$command[0];} @command or POSIX::_exit(127);
}
}
}
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | 31 | ▶ | open STDIN, '<', File::Spec->devnull or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 124 | 31 | ▶ | open STDOUT, '>&', $tmp->fh or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 31 | ▶ | open STDERR, '>', File::Spec->devnull or die; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 31 | binmode STDOUT, ':raw'; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 31 | ▶ | if (ref $command[0] eq 'CODE') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | my $code = shift @command; | |||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | $code->(@command); | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | STDOUT->flush; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | 0; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 133 | # "or" keeps old perls from warning about a statement | ||||||||||||||||||||||||||||||||||||||||||
| 134 | # after exec | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 54 | ▶ | no warnings 'exec'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | 31 | ▶ | exec { $command[0] } @command | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
exec({$command[0];} @command) || POSIX::_exit(127)
MC/DC0%0/2
exec({$command[0];} @command) || POSIX::_exit(127)
exec({$command[0];} @command)
POSIX::_exit(127)
Truth table0%0/3
A || B
A= exec({$command[0];} @command)B= POSIX::_exit(127)
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | or POSIX::_exit(127); | ||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | } // 1; | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | POSIX::_exit($status); | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 63 | waitpid $pid, 0; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 63 | ▶ | return undef if $? != 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 56 | my $converted = $tmp->fh; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 56 | ▶ | $converted->seek(0, 0) or return undef; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | 56 | $converted; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | # Register the converters of IO::Factotum::NAME by their names | ||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | sub load { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
load: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | for my $name (@_) { | |||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $name =~ /\A\w+(?:::\w+)*\z/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | or croak "IO::Factotum: $name: invalid converter name"; | ||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $module = __PACKAGE__ . "::$name"; | |||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | eval "require $module; 1" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | or die "IO::Factotum: $name: no such converter\n$@"; | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | my $setup = $module->can('setup') | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | or die "IO::Factotum: $module has no setup function\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $setup->(); | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | 31 | ▶ | sub tie_argv { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tie_argv: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 166 | 31 | ▶ | return if tied *ARGV; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 29 | require IO::Factotum::ARGV; | |||||||||||||||||||||||||||||||||||||||||
| 168 | 29 | tie *ARGV, 'IO::Factotum::ARGV'; | |||||||||||||||||||||||||||||||||||||||||
| 169 | 29 | return; | |||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 54 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | __END__ | ||||||||||||||||||||||||||||||||||||||||||