| 1 | package ExtUtils::Packlist; | ||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use Carp qw(); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use Config; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 5 | our $Relocations; | |||||||||||||||||||||||||||
| 7 | 5 | our $VERSION = '2.22'; | |||||||||||||||||||||||||||
| 8 | 5 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # Used for generating filehandle globs. IO::File might not be available! | ||||||||||||||||||||||||||||
| 11 | 5 | my $fhname = "FH1"; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | =begin _undocumented | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | =over | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | =item mkfh() | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Make a filehandle. Same kind of idea as Symbol::gensym(). | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | =cut | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub mkfh() | ||||||||||||||||||||||||||||
| 24 | 1055 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
mkfh: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 5 | ▶ | no strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | 1055 | local $^W; | |||||||||||||||||||||||||||
| 27 | 1055 | my $fh = \*{$fhname++}; | |||||||||||||||||||||||||||
| 28 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 1055 | return($fh); | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | =item __find_relocations | ||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | Works out what absolute paths in the configuration have been located at run | ||||||||||||||||||||||||||||
| 35 | time relative to $^X, and generates a regexp that matches them | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | =back | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | =end _undocumented | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | sub __find_relocations | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__find_relocations: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 45 | 0 | my %paths; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | while (my ($raw_key, $raw_val) = each %Config) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | my $exp_key = $raw_key . "exp"; | |||||||||||||||||||||||||||
| 48 | 0 | ▶ | next unless exists $Config{$exp_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 0 | ▶ | next unless $raw_val =~ m!\.\.\./!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | 0 | $paths{$Config{$exp_key}}++; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | # Longest prefixes go first in the alternatives | ||||||||||||||||||||||||||||
| 53 | 0 | my $alternations = join "|", map {quotemeta $_} | |||||||||||||||||||||||||||
| 54 | 0 | sort {length $b <=> length $a} keys %paths; | |||||||||||||||||||||||||||
| 55 | 0 | qr/^($alternations)/o; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | sub new($$) | ||||||||||||||||||||||||||||
| 59 | 1047 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||
| 60 | 1047 | my ($class, $packfile) = @_; | |||||||||||||||||||||||||||
| 61 | 1047 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||
| 62 | 1047 | my %self; | |||||||||||||||||||||||||||
| 63 | 1047 | tie(%self, $class, $packfile); | |||||||||||||||||||||||||||
| 64 | 1047 | return(bless(\%self, $class)); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | sub TIEHASH | ||||||||||||||||||||||||||||
| 68 | 1048 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 69 | 1048 | my ($class, $packfile) = @_; | |||||||||||||||||||||||||||
| 70 | 1048 | my $self = { packfile => $packfile }; | |||||||||||||||||||||||||||
| 71 | 1048 | bless($self, $class); | |||||||||||||||||||||||||||
| 72 | 1048 | ▶ | $self->read($packfile) if (defined($packfile) && -f $packfile); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $packfile and -f $packfile
MC/DC100%2/2
defined $packfile and -f $packfile
defined $packfile
-f $packfile
Truth table100%3/3
A and B
A= defined $packfileB= -f $packfile
| |||||||||||||||||||||||||||||
| 73 | 1048 | return($self); | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | sub STORE | ||||||||||||||||||||||||||||
| 77 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
STORE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 78 | 24 | $_[0]->{data}->{$_[1]} = $_[2]; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | sub FETCH | ||||||||||||||||||||||||||||
| 82 | 24 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 83 | 24 | return($_[0]->{data}->{$_[1]}); | |||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | sub FIRSTKEY | ||||||||||||||||||||||||||||
| 87 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
FIRSTKEY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 88 | 1 | my $reset = scalar(keys(%{$_[0]->{data}})); | |||||||||||||||||||||||||||
| 89 | 1 | return(each(%{$_[0]->{data}})); | |||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub NEXTKEY | ||||||||||||||||||||||||||||
| 93 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
NEXTKEY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | 1 | return(each(%{$_[0]->{data}})); | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | sub EXISTS | ||||||||||||||||||||||||||||
| 98 | 1020 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
EXISTS: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 99 | 1020 | return(exists($_[0]->{data}->{$_[1]})); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | sub DELETE | ||||||||||||||||||||||||||||
| 103 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DELETE: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 104 | 1 | return(delete($_[0]->{data}->{$_[1]})); | |||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | sub CLEAR | ||||||||||||||||||||||||||||
| 108 | 1 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
CLEAR: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | 1 | %{$_[0]->{data}} = (); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | sub DESTROY | ||||||||||||||||||||||||||||
| 113 | 0 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | sub read($;$) | ||||||||||||||||||||||||||||
| 117 | 1035 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
read: called CC=9 SCAR=22.7
Pod
documented
| |||||||||||||||||||||||||||||
| 118 | 1035 | my ($self, $packfile) = @_; | |||||||||||||||||||||||||||
| 119 | 1035 | ▶ | $self = tied(%$self) || $self; | ||||||||||||||||||||||||||
|
Condition66%2/3
tied %$self || $self
MC/DC0%0/2
tied %$self || $self
tied %$self
$self
Truth table66%2/3
A || B
A= tied %$selfB= $self
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1035 | ▶ | if (defined($packfile)) { $self->{packfile} = $packfile; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 122 | 1 | else { $packfile = $self->{packfile}; } | |||||||||||||||||||||||||||
| 123 | 1035 | ▶ | Carp::croak("No packlist filename specified") if (! defined($packfile)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 1034 | my $fh = mkfh(); | |||||||||||||||||||||||||||
| 125 | 1034 | ▶ | open($fh, "<$packfile") || Carp::croak("Can't open file $packfile: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 1033 | $self->{data} = {}; | |||||||||||||||||||||||||||
| 127 | 1033 | my ($line); | |||||||||||||||||||||||||||
| 128 | 1033 | ▶ | while (defined($line = <$fh>)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | { | ||||||||||||||||||||||||||||
| 130 | 57483 | chomp $line; | |||||||||||||||||||||||||||
| 131 | 57483 | my ($key, $data) = $line; | |||||||||||||||||||||||||||
| 132 | 57483 | ▶ | if ($key =~ /^(.*?)( \w+=.*)$/) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 133 | { | ||||||||||||||||||||||||||||
| 134 | 1911 | $key = $1; | |||||||||||||||||||||||||||
| 135 | 1911 | $data = { map { split('=', $_) } split(' ', $2)}; | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 1911 | ▶ | if ($Config{userelocatableinc} && $data->{relocate_as}) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$ExtUtils::Packlist::Config{"userelocatableinc"} and $data->{"relocate_as"}
MC/DC0%0/2
$ExtUtils::Packlist::Config{"userelocatableinc"} and $data->{"relocate_as"}
$ExtUtils::Packlist::Config{"userelocatableinc"}
$data->{"relocate_as"}
Truth table33%1/3
A and B
A= $ExtUtils::Packlist::Config{"userelocatableinc"}B= $data->{"relocate_as"}
| |||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||
| 139 | 0 | require File::Spec; | |||||||||||||||||||||||||||
| 140 | 0 | require Cwd; | |||||||||||||||||||||||||||
| 141 | 0 | my ($vol, $dir) = File::Spec->splitpath($packfile); | |||||||||||||||||||||||||||
| 142 | 0 | my $newpath = File::Spec->catpath($vol, $dir, $data->{relocate_as}); | |||||||||||||||||||||||||||
| 143 | 0 | $key = Cwd::realpath($newpath); | |||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | 57483 | $key =~ s!/\./!/!g; # Some .packlists have spurious '/./' bits in the paths | |||||||||||||||||||||||||||
| 147 | 57483 | $self->{data}->{$key} = $data; | |||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||
| 149 | 1033 | close($fh); | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | sub write($;$) | ||||||||||||||||||||||||||||
| 153 | 20 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
write: called CC=13 SCAR=32.4
Pod
documented
| |||||||||||||||||||||||||||||
| 154 | 20 | my ($self, $packfile) = @_; | |||||||||||||||||||||||||||
| 155 | 20 | ▶ | $self = tied(%$self) || $self; | ||||||||||||||||||||||||||
|
Condition66%2/3
tied %$self || $self
MC/DC0%0/2
tied %$self || $self
tied %$self
$self
Truth table66%2/3
A || B
A= tied %$selfB= $self
| |||||||||||||||||||||||||||||
| 156 | 20 | ▶ | if (defined($packfile)) { $self->{packfile} = $packfile; } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | 1 | else { $packfile = $self->{packfile}; } | |||||||||||||||||||||||||||
| 158 | 20 | ▶ | Carp::croak("No packlist filename specified") if (! defined($packfile)); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 159 | 19 | my $fh = mkfh(); | |||||||||||||||||||||||||||
| 160 | 19 | ▶ | open($fh, ">$packfile") || Carp::croak("Can't open file $packfile: $!"); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 18 | foreach my $key (sort(keys(%{$self->{data}}))) | |||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||
| 163 | 34 | my $data = $self->{data}->{$key}; | |||||||||||||||||||||||||||
| 164 | 34 | ▶ | if ($Config{userelocatableinc}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 165 | 0 | ▶ | $Relocations ||= __find_relocations(); | ||||||||||||||||||||||||||
|
Condition0%0/3
$ExtUtils::Packlist::Relocations ||= __find_relocations()
MC/DC0%0/2
$ExtUtils::Packlist::Relocations ||= __find_relocations()
$ExtUtils::Packlist::Relocations
__find_relocations()
Truth table0%0/3
A ||= B
A= $ExtUtils::Packlist::RelocationsB= __find_relocations()
| |||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if ($packfile =~ $Relocations) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 167 | # We are writing into a subdirectory of a run-time relocated | ||||||||||||||||||||||||||||
| 168 | # path. Figure out if the this file is also within a subdir. | ||||||||||||||||||||||||||||
| 169 | 0 | my $prefix = $1; | |||||||||||||||||||||||||||
| 170 | 0 | ▶ | if (File::Spec->no_upwards(File::Spec->abs2rel($key, $prefix))) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | { | ||||||||||||||||||||||||||||
| 172 | # The relocated path is within the found prefix | ||||||||||||||||||||||||||||
| 173 | 0 | my $packfile_prefix; | |||||||||||||||||||||||||||
| 174 | 0 | (undef, $packfile_prefix) | |||||||||||||||||||||||||||
| 175 | = File::Spec->splitpath($packfile); | ||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 0 | my $relocate_as | |||||||||||||||||||||||||||
| 178 | = File::Spec->abs2rel($key, $packfile_prefix); | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if (!ref $data) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | 0 | $data = {}; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | 0 | $data->{relocate_as} = $relocate_as; | |||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | 34 | print $fh ("$key"); | |||||||||||||||||||||||||||
| 188 | 34 | ▶ | if (ref($data)) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | { | ||||||||||||||||||||||||||||
| 190 | 1 | foreach my $k (sort(keys(%$data))) | |||||||||||||||||||||||||||
| 191 | { | ||||||||||||||||||||||||||||
| 192 | 2 | print $fh (" $k=$data->{$k}"); | |||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 34 | print $fh ("\n"); | |||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | 18 | close($fh); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | sub validate($;$) | ||||||||||||||||||||||||||||
| 201 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
validate: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||
| 202 | 2 | my ($self, $remove) = @_; | |||||||||||||||||||||||||||
| 203 | 2 | ▶ | $self = tied(%$self) || $self; | ||||||||||||||||||||||||||
|
Condition33%1/3
tied %$self || $self
MC/DC0%0/2
tied %$self || $self
tied %$self
$self
Truth table33%1/3
A || B
A= tied %$selfB= $self
| |||||||||||||||||||||||||||||
| 204 | 2 | my @missing; | |||||||||||||||||||||||||||
| 205 | 2 | foreach my $key (sort(keys(%{$self->{data}}))) | |||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||
| 207 | 4 | ▶ | if (! -e $key) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | { | ||||||||||||||||||||||||||||
| 209 | 2 | push(@missing, $key); | |||||||||||||||||||||||||||
| 210 | 2 | ▶ | delete($self->{data}{$key}) if ($remove); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | 2 | return(@missing); | |||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | sub packlist_file($) | ||||||||||||||||||||||||||||
| 217 | 2 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
packlist_file: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||
| 218 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 219 | 2 | ▶ | $self = tied(%$self) || $self; | ||||||||||||||||||||||||||
|
Condition66%2/3
tied %$self || $self
MC/DC0%0/2
tied %$self || $self
tied %$self
$self
Truth table66%2/3
A || B
A= tied %$selfB= $self
| |||||||||||||||||||||||||||||
| 220 | 2 | return($self->{packfile}); | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | 5 | 1; | |||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | __END__ | ||||||||||||||||||||||||||||