| 1 | |||||||||||||||||||||||||||||
| 2 | package File::Slurp::Remote::SmartOpen; | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | require Exporter; | |||||||||||||||||||||||||||
| 7 | 1 | ▶ | use File::Slurp::Remote::BrokenDNS qw($myfqdn %fqdnify); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Tie::Function::Examples qw(%q_shell); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our @EXPORT = qw(smartopen); | |||||||||||||||||||||||||||
| 12 | 1 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 13 | 1 | our $ssh = "ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o PasswordAuthentication=no"; | |||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = 0.2; | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | sub smartopen($\$$) | ||||||||||||||||||||||||||||
| 17 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
smartopen: not called CC=19 SCAR=59.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | my ($file, $fdref, $mode) = @_; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | my $unzip = ''; | |||||||||||||||||||||||||||
| 21 | 0 | my $zip = ''; | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | if ($file =~ /\.gz$/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 23 | 0 | $unzip = "zcat"; | |||||||||||||||||||||||||||
| 24 | 0 | $zip = "gzip"; | |||||||||||||||||||||||||||
| 25 | } elsif ($file =~ /\.bz2$/) { | ||||||||||||||||||||||||||||
| 26 | 0 | $unzip = "bzcat"; | |||||||||||||||||||||||||||
| 27 | 0 | $zip = "bzip2"; | |||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | my $pid; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 0 | my $fd = $$fdref; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if ($file =~ s/(.+):// && $fqdnify{$1} ne $myfqdn) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$file =~ s/(.+):// and $File::Slurp::Remote::SmartOpen::fqdnify{$1} ne $File::Slurp::Remote::SmartOpen::myfqdn
MC/DC0%0/2
$file =~ s/(.+):// and $File::Slurp::Remote::SmartOpen::fqdnify{$1} ne $File::Slurp::Remote::SmartOpen::myfqdn
$file =~ s/(.+)://
$File::Slurp::Remote::SmartOpen::fqdnify{$1} ne $File::Slurp::Remote::SmartOpen::myfqdn
Truth table0%0/3
A and B
A= $file =~ s/(.+)://B= $File::Slurp::Remote::SmartOpen::fqdnify{$1} ne $File::Slurp::Remote::SmartOpen::myfqdn
| |||||||||||||||||||||||||||||
| 35 | 0 | my $host = $1; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | $unzip = "|$unzip" if $unzip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | $zip = "$zip|" if $zip; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if ($mode && $mode eq 'w') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mode and $mode eq "w"
MC/DC0%0/2
$mode and $mode eq "w"
$mode
$mode eq "w"
Truth table0%0/3
A and B
A= $modeB= $mode eq "w"
| |||||||||||||||||||||||||||||
| 39 | 0 | my $cat = $q_shell{"cat > $q_shell{$file}"}; | |||||||||||||||||||||||||||
| 40 | 0 | ▶ | $pid = open $fd, "|$zip $ssh $q_shell{$host} $cat" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | or confess "open |$zip $ssh $q_shell{$host} $cat: $!"; | ||||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||
| 43 | 0 | ▶ | $pid = open $fd, "$ssh -n $q_shell{$host} cat $q_shell{$file} $unzip|" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | or confess "open $ssh $q_shell{$host} cat $q_shell{$file} $unzip|: $!"; | ||||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if ($mode && $mode eq 'w') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$mode and $mode eq "w"
MC/DC0%0/2
$mode and $mode eq "w"
$mode
$mode eq "w"
Truth table0%0/3
A and B
A= $modeB= $mode eq "w"
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | if ($zip) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $pid = open $fd, "|$zip > $q_shell{$file}" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | or die "open |$zip > $q_shell{$file}: $!"; | ||||||||||||||||||||||||||||
| 51 | } else { | ||||||||||||||||||||||||||||
| 52 | 0 | ▶ | open $fd, ">", $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | or die "open >$file: $!"; | ||||||||||||||||||||||||||||
| 54 | 0 | $pid = "0butTrue"; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | } else { | ||||||||||||||||||||||||||||
| 57 | 0 | ▶ | if ($unzip) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | $pid = open $fd, "$unzip < $q_shell{$file}|" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | or die "open $unzip < $q_shell{$file}|: $!"; | ||||||||||||||||||||||||||||
| 60 | } else { | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | open $fd, "<", $file | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | or die "open <$file: $!"; | ||||||||||||||||||||||||||||
| 63 | 0 | $pid = "0buttrue"; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | 0 | $$fdref = $fd; | |||||||||||||||||||||||||||
| 68 | 0 | return $pid; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 1 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||