blib/lib/ExtUtils/Helpers/Unix.pm

filter: Statementstmt 100% 47 / 47 Branchbran 55.5% 10 / 18 Conditioncond 50.0% 4 / 8 MC/DCmcdc 20.0% 1 / 5 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 3 totaltotal 78.8% 71 / 90 CC 13 SCAR 15.2
CC
13
Cov
84%
make_executable
7.9
detildefy
5.1
split_like_shell
3.1
CRAP 4.6
« blib/lib/ExtUtils/Helpers/VMS.pm ↑ Summary blib/lib/ExtUtils/Helpers.pm »
1 package ExtUtils::Helpers::Unix;
2 4 $ExtUtils::Helpers::Unix::VERSION = '0.028';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 ▶use Exporter 5.57 'import';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 our @EXPORT = qw/make_executable split_like_shell detildefy/;
8  
9 4 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Text::ParseWords 3.24 qw/shellwords/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 4 ▶my $layer = $] >= 5.008001 ? ":raw" : "";
Branch: 1 branch
BranchTrueFalseTotal
$] >= 5.008001 ? : 4 0 4
14  
15 1 ▶sub make_executable {
Subroutine make_executable: called CC=7 SCAR=20.6
Pod undocumented
16 1 my $filename = shift;
17 1 my $current_mode = (stat $filename)[2] + 0;
18 1 ▶ if (-T $filename) {
Branch: 1 branch
BranchTrueFalseTotal
if (-T $filename) 1 0 1
19 1 open my $fh, "<$layer", $filename;
20 1 my @lines = <$fh>;
21 1 ▶ if (@lines and $lines[0] =~ s{ \A \#! \s* (?:/\S+/)? perl \b (.*) \z }{$Config{startperl}$1}xms) {
Branch: 1 branch
BranchTrueFalseTotal
if (@lines and $lines[0] =~ s[ \A \#! \s* (?:/\S+/)? perl \b (.*) \z ][$ExtUtils::Helpers::Unix::Config{"startperl"}$1]msx) 1 0 1
Condition33%1/3
@lines and $lines[0] =~ s[ \A \#! \s* (?:/\S+/)? perl \b (.*) \z ][$ExtUtils::Helpers::Unix::Config{"startperl"}$1]msx
!ll&&!rl&&r
001
MC/DC0%0/2
@lines and $lines[0] =~ s[ \A \#! \s* (?:/\S+/)? perl \b (.*) \z ][$ExtUtils::Helpers::Unix::Config{"startperl"}$1]msx
@lines $lines[0] =~ s[ \A \#! \s* (?:/\S+/)? perl \b (.*) \z ][$ExtUtils::Helpers::Unix::Config{"startperl"}$1]msx
Truth table33%1/3
A and B
A= @linesB= $lines[0] =~ s[ \A \#! \s* (?:/\S+/)? perl \b (.*) \z ][$ExtUtils::Helpers::Unix::Config{"startperl"}$1]msx
ABresult
0X0
100
111
22 1 ▶ open my $out, ">$layer", "$filename.new" or croak "Couldn't open $filename.new: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $out, ">$layer", "$filename.new" or croak("Couldn't open $filename.new: $!") 1 0 1
23 1 print $out @lines;
24 1 close $out;
25 1 ▶ rename $filename, "$filename.bak" or croak "Couldn't rename $filename to $filename.bak";
Branch: 1 branch
BranchTrueFalseTotal
rename $filename, "$filename.bak" or croak("Couldn't rename $filename to $filename.bak") 1 0 1
26 1 ▶ rename "$filename.new", $filename or croak "Couldn't rename $filename.new to $filename";
Branch: 1 branch
BranchTrueFalseTotal
rename "$filename.new", $filename or croak("Couldn't rename $filename.new to $filename") 1 0 1
27 1 unlink "$filename.bak";
28 }
29 }
30 1 chmod $current_mode | oct(111), $filename;
31 1 return;
32 }
33  
34 5 ▶sub split_like_shell {
Subroutine split_like_shell: called CC=3 SCAR=11.3
Pod undocumented
35 5 my ($string) = @_;
36  
37 5 ▶ return if not defined $string;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $string 0 5 5
38 5 $string =~ s/^\s+|\s+$//g;
39 5 ▶ return if not length $string;
Branch: 1 branch
BranchTrueFalseTotal
unless length $string 0 5 5
40  
41 5 return shellwords($string);
42 }
43  
44 9 ▶sub detildefy {
Subroutine detildefy: called CC=5 SCAR=16.3
Pod undocumented
45 9 my $value = shift;
46 # tilde with optional username
47 9 for ($value) {
48 9 ▶ s{ ^ ~ (?= /|$)} [ $ENV{HOME} || (getpwuid $>)[7] ]ex or # tilde without user name
Branch: 1 branch
BranchTrueFalseTotal
s[ ^ ~ (?= /|$)][$ENV{"HOME"} or (getpwuid $>)[7];]ex or s[ ^ ~ ([^/]+) (?= /|$) ][(getpwnam $1)[7] or "~$1";]ex 5 4 9
Condition33%1/3
$ENV{'HOME'} || (getpwuid $>)[7]
l!l&&r!l&&!r
500
MC/DC0%0/2
$ENV{'HOME'} || (getpwuid $>)[7]
$ENV{'HOME'} (getpwuid $>)[7]
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= (getpwuid $>)[7]
ABresult
1X1
011
000
49 3 ▶ s{ ^ ~ ([^/]+) (?= /|$) } { (getpwnam $1)[7] || "~$1" }ex; # tilde with user name
Condition100%2/2
(getpwnam $1)[7] || "~$1"
l!l
12
MC/DC100%1/1
(getpwnam $1)[7] || "~$1"
(getpwnam $1)[7]
Truth table100%2/2
A
A= (getpwnam $1)[7]
Aresult
11
00
50 }
51 9 return $value;
52 }
53  
54 4 1;
55  
56 # ABSTRACT: Unix specific helper bits
57  
58 __END__
« blib/lib/ExtUtils/Helpers/VMS.pm ↑ Summary blib/lib/ExtUtils/Helpers.pm »