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