| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
@lines and $lines[0] =~ s[ \A \#! \s* (?:/\S+/)? perl \b (.*) \z ][$ExtUtils::Helpers::Unix::Config{"startperl"}$1]msx
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
| |||||||||||||||||||||||||||||
| 22 | 1 | ▶ | open my $out, ">$layer", "$filename.new" or croak "Couldn't open $filename.new: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 26 | 1 | ▶ | rename "$filename.new", $filename or croak "Couldn't rename $filename.new to $filename"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 38 | 5 | $string =~ s/^\s+|\s+$//g; | |||||||||||||||||||||||||||
| 39 | 5 | ▶ | return if not length $string; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
$ENV{'HOME'} || (getpwuid $>)[7]
MC/DC0%0/2
$ENV{'HOME'} || (getpwuid $>)[7]
$ENV{'HOME'}
(getpwuid $>)[7]
Truth table33%1/3
A || B
A= $ENV{'HOME'}B= (getpwuid $>)[7]
| |||||||||||||||||||||||||||||
| 49 | 3 | ▶ | s{ ^ ~ ([^/]+) (?= /|$) } { (getpwnam $1)[7] || "~$1" }ex; # tilde with user name | ||||||||||||||||||||||||||
|
Condition100%2/2
(getpwnam $1)[7] || "~$1"
MC/DC100%1/1
(getpwnam $1)[7] || "~$1"
(getpwnam $1)[7]
Truth table100%2/2
A
A= (getpwnam $1)[7]
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 9 | return $value; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 4 | 1; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | # ABSTRACT: Unix specific helper bits | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||