blib/lib/File/Slurp/Remote/SmartOpen.pm

filter: Statementstmt 85.7% 54 / 63 Branchbran 58.7% 27 / 46 Conditioncond 85.7% 18 / 21 MC/DCmcdc 75.0% 9 / 12 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 77.3% 116 / 150 CC 31 SCAR 34.1
CC
31
Cov
76%
smartopen
38.5
_local_user
8.7
BEGIN
1.0
CRAP 30.2
↑ Summary blib/lib/File/Slurp/Remote/BrokenDNS.pm »
1  
2 package File::Slurp::Remote::SmartOpen;
3  
4 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 require Exporter;
7 3 ▶use File::Slurp::Remote::BrokenDNS qw($myfqdn %fqdnify);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Tie::Function::Examples qw(%q_shell);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use Carp qw(confess);
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 our @EXPORT = qw(smartopen);
12 3 our @ISA = qw(Exporter);
13 3 our $ssh = "ssh -o StrictHostKeyChecking=no -o BatchMode=yes -o PasswordAuthentication=no";
14 3 our $VERSION = '0.48';
15  
16 sub smartopen($\$$)
17 13 ▶{
Subroutine smartopen: called CC=28 SCAR=36.5
Pod documented
18 13 my ($file, $fdref, $mode) = @_;
19  
20 13 my $unzip = '';
21 13 my $zip = '';
22 13 ▶ if ($file =~ /\.gz$/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($file =~ /\.gz$/) { } 0 13 13
elsif ($file =~ /\.bz2$/) { } 0 13 13
23 0 $unzip = "zcat";
24 0 $zip = "gzip";
25 } elsif ($file =~ /\.bz2$/) {
26 0 $unzip = "bzcat";
27 0 $zip = "bzip2";
28 }
29  
30 13 my $pid;
31  
32 13 my $fd = $$fdref;
33  
34 13 my ($user, $host);
35 # As with scp, a colon before any slash separates the host from the path
36 13 ▶ if ($file =~ s/^([^\/]+?)://) {
Branch: 1 branch
BranchTrueFalseTotal
if ($file =~ s[^([^/]+?):][]) 12 1 13
37 12 $host = $1;
38 # Allow user@host; like ssh, split at the last @
39 12 ▶ if ($host =~ /^(.*)@([^@]*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($host =~ /^(.*)@([^\@]*)$/) 10 2 12
40 10 ($user, $host) = ($1, $2);
41 10 ▶ confess "smartopen: invalid user '$user'" if $user eq '' || $user =~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
if $user eq "" or $user =~ /^-/ 2 8 10
Condition100%3/3
$user eq "" or $user =~ /^-/
l!l&&r!l&&!r
118
MC/DC100%2/2
$user eq "" or $user =~ /^-/
$user eq "" $user =~ /^-/
Truth table100%3/3
A or B
A= $user eq ""B= $user =~ /^-/
ABresult
1X1
011
000
42 }
43 10 ▶ confess "smartopen: invalid host '$host'" if $host eq '' || $host =~ /^-/;
Branch: 1 branch
BranchTrueFalseTotal
if $host eq "" or $host =~ /^-/ 2 8 10
Condition100%3/3
$host eq "" or $host =~ /^-/
l!l&&r!l&&!r
118
MC/DC100%2/2
$host eq "" or $host =~ /^-/
$host eq "" $host =~ /^-/
Truth table100%3/3
A or B
A= $host eq ""B= $host =~ /^-/
ABresult
1X1
011
000
44 }
45  
46 9 ▶ if (defined($host) && ($fqdnify{$host} ne $myfqdn || (defined($user) && $user ne _local_user()))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $host and $File::Slurp::Remote::SmartOpen::fqdnify{$host} ne $File::Slurp::Remote::SmartOpen::myfqdn || defined $user && $user ne _local_user()) { } 7 2 9
Condition88%8/9
defined $host and $File::Slurp::Remote::SmartOpen::fqdnify{$host} ne $File::Slurp::Remote::SmartOpen::myfqdn || defined $user && $user ne _local_user()
!ll&&!rl&&r
117
$File::Slurp::Remote::SmartOpen::fqdnify{$host} ne $File::Slurp::Remote::SmartOpen::myfqdn or defined $user and $user ne _local_user()
l!l&&r!l&&!r
611
defined $user and $user ne _local_user()
!ll&&!rl&&r
011
MC/DC75%3/4
defined $host and $File::Slurp::Remote::SmartOpen::fqdnify{$host} ne $File::Slurp::Remote::SmartOpen::myfqdn || defined $user && $user ne _local_user()
defined $host $File::Slurp::Remote::SmartOpen::fqdnify{$host} ne $File::Slurp::Remote::SmartOpen::myfqdn defined $user $user ne _local_user()
Truth table80%4/5
A and B or C and D
A= defined $hostB= $File::Slurp::Remote::SmartOpen::fqdnify{$host} ne $File::Slurp::Remote::SmartOpen::myfqdnC= defined $userD= $user ne _local_user()
ABCDresult
0XXX0
100X0
10100
11XX1
10111
47 7 ▶ my $dest = defined($user) ? "-l $q_shell{$user} $q_shell{$host}" : $q_shell{$host};
Branch: 1 branch
BranchTrueFalseTotal
defined $user ? : 6 1 7
48 7 ▶ $unzip = "|$unzip" if $unzip;
Branch: 1 branch
BranchTrueFalseTotal
if $unzip 0 7 7
49 7 ▶ $zip = "$zip|" if $zip;
Branch: 1 branch
BranchTrueFalseTotal
if $zip 0 7 7
50 7 ▶ if ($mode && $mode eq 'w') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode and $mode eq 'w') { } 2 5 7
Condition66%2/3
$mode and $mode eq "w"
!ll&&!rl&&r
052
MC/DC50%1/2
$mode and $mode eq "w"
$mode $mode eq "w"
Truth table66%2/3
A and B
A= $modeB= $mode eq "w"
ABresult
0X0
100
111
51 2 my $cat = $q_shell{"cat > $q_shell{$file}"};
52 2 ▶ $pid = open $fd, "|$zip $ssh $dest $cat"
Branch: 1 branch
BranchTrueFalseTotal
$pid = open($fd, "|$zip $File::Slurp::Remote::SmartOpen::ssh $dest $cat") or confess("open |$zip $File::Slurp::Remote::SmartOpen::ssh $dest ${cat}: $!") 2 0 2
53 or confess "open |$zip $ssh $dest $cat: $!";
54 } else {
55 5 ▶ $pid = open $fd, "$ssh -n $dest cat $q_shell{$file} $unzip|"
Branch: 1 branch
BranchTrueFalseTotal
$pid = open($fd, "$File::Slurp::Remote::SmartOpen::ssh -n $dest cat $File::Slurp::Remote::SmartOpen::q_shell{$file} $unzip|") or confess("open $File::Slurp::Remote::SmartOpen::ssh $dest cat $File::Slurp::Remote::SmartOpen::q_shell{$file} $unzip|: $!") 5 0 5
56 or confess "open $ssh $dest cat $q_shell{$file} $unzip|: $!";
57 }
58 } else {
59 2 ▶ if ($mode && $mode eq 'w') {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode and $mode eq 'w') { } 1 1 2
Condition66%2/3
$mode and $mode eq "w"
!ll&&!rl&&r
011
MC/DC50%1/2
$mode and $mode eq "w"
$mode $mode eq "w"
Truth table66%2/3
A and B
A= $modeB= $mode eq "w"
ABresult
0X0
100
111
60 1 ▶ if ($zip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($zip) { } 0 1 1
61 0 ▶ $pid = open $fd, "|$zip > $q_shell{$file}"
Branch: 1 branch
BranchTrueFalseTotal
$pid = open($fd, "|$zip > $File::Slurp::Remote::SmartOpen::q_shell{$file}") or die "open |$zip > $File::Slurp::Remote::SmartOpen::q_shell{$file}: $!" 0 0 0
62 or die "open |$zip > $q_shell{$file}: $!";
63 } else {
64 1 ▶ open $fd, ">", $file
Branch: 1 branch
BranchTrueFalseTotal
open $fd, ">", $file or die "open >${file}: $!" 1 0 1
65 or die "open >$file: $!";
66 1 $pid = "0butTrue";
67 }
68 } else {
69 1 ▶ if ($unzip) {
Branch: 1 branch
BranchTrueFalseTotal
if ($unzip) { } 0 1 1
70 0 ▶ $pid = open $fd, "$unzip < $q_shell{$file}|"
Branch: 1 branch
BranchTrueFalseTotal
$pid = open($fd, "$unzip < $File::Slurp::Remote::SmartOpen::q_shell{$file}|") or die "open $unzip < $File::Slurp::Remote::SmartOpen::q_shell{$file}|: $!" 0 0 0
71 or die "open $unzip < $q_shell{$file}|: $!";
72 } else {
73 1 ▶ open $fd, "<", $file
Branch: 1 branch
BranchTrueFalseTotal
open $fd, "<", $file or die "open <${file}: $!" 1 0 1
74 or die "open <$file: $!";
75 1 $pid = "0buttrue";
76 }
77 }
78 }
79 9 $$fdref = $fd;
80 9 return $pid;
81 }
82  
83 # The login name of the user running this process
84 sub _local_user
85 3 ▶{
Subroutine _local_user: called CC=4 SCAR=21.7
86 3 my $name = eval { scalar getpwuid($<) };
87 3 ▶ return $name if defined $name;
Branch: 1 branch
BranchTrueFalseTotal
if defined $name 3 0 3
88 0 ▶ return $ENV{USER} if defined $ENV{USER};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"USER"} 0 0 0
89 0 ▶ return $ENV{USERNAME} if defined $ENV{USERNAME};
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"USERNAME"} 0 0 0
90 0 return '';
91 }
92  
93 3 1;
94  
95 __END__
↑ Summary blib/lib/File/Slurp/Remote/BrokenDNS.pm »