| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package ExtUtils::Packlist; | 
| 2 | 4 |  |  | 4 |  | 71526 | use strict; | 
|  | 4 |  |  |  |  | 17 |  | 
|  | 4 |  |  |  |  | 175 |  | 
| 3 |  |  |  |  |  |  |  | 
| 4 | 4 |  |  | 4 |  | 27 | use Carp qw(); | 
|  | 4 |  |  |  |  | 8 |  | 
|  | 4 |  |  |  |  | 67 |  | 
| 5 | 4 |  |  | 4 |  | 16 | use Config; | 
|  | 4 |  |  |  |  | 16 |  | 
|  | 4 |  |  |  |  | 400 |  | 
| 6 |  |  |  |  |  |  | our $Relocations; | 
| 7 |  |  |  |  |  |  | our $VERSION = '2.18'; | 
| 8 |  |  |  |  |  |  | $VERSION = eval $VERSION; | 
| 9 |  |  |  |  |  |  |  | 
| 10 |  |  |  |  |  |  | # Used for generating filehandle globs.  IO::File might not be available! | 
| 11 |  |  |  |  |  |  | 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 |  |  |  |  |  |  | { | 
| 25 | 4 |  |  | 4 |  | 29 | no strict; | 
|  | 4 |  |  |  |  | 7 |  | 
|  | 4 |  |  |  |  | 205 |  | 
| 26 | 333 |  |  | 333 | 1 | 4127 | local $^W; | 
| 27 | 333 |  |  |  |  | 506 | my $fh = \*{$fhname++}; | 
|  | 333 |  |  |  |  | 2588 |  | 
| 28 | 4 |  |  | 4 |  | 25 | use strict; | 
|  | 4 |  |  |  |  | 14 |  | 
|  | 4 |  |  |  |  | 5902 |  | 
| 29 | 333 |  |  |  |  | 2682 | 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 |  |  |  |  |  |  | { | 
| 45 | 0 |  |  | 0 |  | 0 | my %paths; | 
| 46 | 0 |  |  |  |  | 0 | while (my ($raw_key, $raw_val) = each %Config) { | 
| 47 | 0 |  |  |  |  | 0 | my $exp_key = $raw_key . "exp"; | 
| 48 | 0 | 0 |  |  |  | 0 | next unless exists $Config{$exp_key}; | 
| 49 | 0 | 0 |  |  |  | 0 | next unless $raw_val =~ m!\.\.\./!; | 
| 50 | 0 |  |  |  |  | 0 | $paths{$Config{$exp_key}}++; | 
| 51 |  |  |  |  |  |  | } | 
| 52 |  |  |  |  |  |  | # Longest prefixes go first in the alternatives | 
| 53 | 0 |  |  |  |  | 0 | my $alternations = join "|", map {quotemeta $_} | 
| 54 | 0 |  |  |  |  | 0 | sort {length $b <=> length $a} keys %paths; | 
|  | 0 |  |  |  |  | 0 |  | 
| 55 | 0 |  |  |  |  | 0 | qr/^($alternations)/o; | 
| 56 |  |  |  |  |  |  | } | 
| 57 |  |  |  |  |  |  |  | 
| 58 |  |  |  |  |  |  | sub new($$) | 
| 59 |  |  |  |  |  |  | { | 
| 60 | 326 |  |  | 326 | 1 | 748 | my ($class, $packfile) = @_; | 
| 61 | 326 |  | 33 |  |  | 1081 | $class = ref($class) || $class; | 
| 62 | 326 |  |  |  |  | 540 | my %self; | 
| 63 | 326 |  |  |  |  | 1138 | tie(%self, $class, $packfile); | 
| 64 | 326 |  |  |  |  | 2760 | return(bless(\%self, $class)); | 
| 65 |  |  |  |  |  |  | } | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | sub TIEHASH | 
| 68 |  |  |  |  |  |  | { | 
| 69 | 327 |  |  | 327 |  | 1848 | my ($class, $packfile) = @_; | 
| 70 | 327 |  |  |  |  | 941 | my $self = { packfile => $packfile }; | 
| 71 | 327 |  |  |  |  | 591 | bless($self, $class); | 
| 72 | 327 | 100 | 100 |  |  | 8041 | $self->read($packfile) if (defined($packfile) && -f $packfile); | 
| 73 | 327 |  |  |  |  | 1270 | return($self); | 
| 74 |  |  |  |  |  |  | } | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | sub STORE | 
| 77 |  |  |  |  |  |  | { | 
| 78 | 18 |  |  | 18 |  | 1514 | $_[0]->{data}->{$_[1]} = $_[2]; | 
| 79 |  |  |  |  |  |  | } | 
| 80 |  |  |  |  |  |  |  | 
| 81 |  |  |  |  |  |  | sub FETCH | 
| 82 |  |  |  |  |  |  | { | 
| 83 | 18 |  |  | 18 |  | 838 | return($_[0]->{data}->{$_[1]}); | 
| 84 |  |  |  |  |  |  | } | 
| 85 |  |  |  |  |  |  |  | 
| 86 |  |  |  |  |  |  | sub FIRSTKEY | 
| 87 |  |  |  |  |  |  | { | 
| 88 | 1 |  |  | 1 |  | 3 | my $reset = scalar(keys(%{$_[0]->{data}})); | 
|  | 1 |  |  |  |  | 4 |  | 
| 89 | 1 |  |  |  |  | 3 | return(each(%{$_[0]->{data}})); | 
|  | 1 |  |  |  |  | 5 |  | 
| 90 |  |  |  |  |  |  | } | 
| 91 |  |  |  |  |  |  |  | 
| 92 |  |  |  |  |  |  | sub NEXTKEY | 
| 93 |  |  |  |  |  |  | { | 
| 94 | 1 |  |  | 1 |  | 2 | return(each(%{$_[0]->{data}})); | 
|  | 1 |  |  |  |  | 6 |  | 
| 95 |  |  |  |  |  |  | } | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | sub EXISTS | 
| 98 |  |  |  |  |  |  | { | 
| 99 | 300 |  |  | 300 |  | 1970 | return(exists($_[0]->{data}->{$_[1]})); | 
| 100 |  |  |  |  |  |  | } | 
| 101 |  |  |  |  |  |  |  | 
| 102 |  |  |  |  |  |  | sub DELETE | 
| 103 |  |  |  |  |  |  | { | 
| 104 | 1 |  |  | 1 |  | 4 | return(delete($_[0]->{data}->{$_[1]})); | 
| 105 |  |  |  |  |  |  | } | 
| 106 |  |  |  |  |  |  |  | 
| 107 |  |  |  |  |  |  | sub CLEAR | 
| 108 |  |  |  |  |  |  | { | 
| 109 | 1 |  |  | 1 |  | 2 | %{$_[0]->{data}} = (); | 
|  | 1 |  |  |  |  | 5 |  | 
| 110 |  |  |  |  |  |  | } | 
| 111 |  |  |  |  |  |  |  | 
| 112 |  |  |  |  |  |  | sub DESTROY | 
| 113 |  |  |  | 0 |  |  | { | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | sub read($;$) | 
| 117 |  |  |  |  |  |  | { | 
| 118 | 315 |  |  | 315 | 1 | 6367 | my ($self, $packfile) = @_; | 
| 119 | 315 |  | 66 |  |  | 1108 | $self = tied(%$self) || $self; | 
| 120 |  |  |  |  |  |  |  | 
| 121 | 315 | 100 |  |  |  | 696 | if (defined($packfile)) { $self->{packfile} = $packfile; } | 
|  | 314 |  |  |  |  | 739 |  | 
| 122 | 1 |  |  |  |  | 3 | else { $packfile = $self->{packfile}; } | 
| 123 | 315 | 100 |  |  |  | 731 | Carp::croak("No packlist filename specified") if (! defined($packfile)); | 
| 124 | 314 |  |  |  |  | 633 | my $fh = mkfh(); | 
| 125 | 314 | 100 |  |  |  | 11002 | open($fh, "<$packfile") || Carp::croak("Can't open file $packfile: $!"); | 
| 126 | 313 |  |  |  |  | 1547 | $self->{data} = {}; | 
| 127 | 313 |  |  |  |  | 526 | my ($line); | 
| 128 | 313 |  |  |  |  | 4128 | while (defined($line = <$fh>)) | 
| 129 |  |  |  |  |  |  | { | 
| 130 | 4246 |  |  |  |  | 6412 | chomp $line; | 
| 131 | 4246 |  |  |  |  | 7314 | my ($key, $data) = $line; | 
| 132 | 4246 | 100 |  |  |  | 11281 | if ($key =~ /^(.*?)( \w+=.*)$/) | 
| 133 |  |  |  |  |  |  | { | 
| 134 | 1600 |  |  |  |  | 3099 | $key = $1; | 
| 135 | 1600 |  |  |  |  | 3269 | $data = { map { split('=', $_) } split(' ', $2)}; | 
|  | 1604 |  |  |  |  | 5078 |  | 
| 136 |  |  |  |  |  |  |  | 
| 137 | 1600 | 0 | 33 |  |  | 7552 | if ($Config{userelocatableinc} && $data->{relocate_as}) | 
| 138 |  |  |  |  |  |  | { | 
| 139 | 0 |  |  |  |  | 0 | require File::Spec; | 
| 140 | 0 |  |  |  |  | 0 | require Cwd; | 
| 141 | 0 |  |  |  |  | 0 | my ($vol, $dir) = File::Spec->splitpath($packfile); | 
| 142 | 0 |  |  |  |  | 0 | my $newpath = File::Spec->catpath($vol, $dir, $data->{relocate_as}); | 
| 143 | 0 |  |  |  |  | 0 | $key = Cwd::realpath($newpath); | 
| 144 |  |  |  |  |  |  | } | 
| 145 |  |  |  |  |  |  | } | 
| 146 | 4246 |  |  |  |  | 7876 | $key =~ s!/\./!/!g;   # Some .packlists have spurious '/./' bits in the paths | 
| 147 | 4246 |  |  |  |  | 22171 | $self->{data}->{$key} = $data; | 
| 148 |  |  |  |  |  |  | } | 
| 149 | 313 |  |  |  |  | 3113 | close($fh); | 
| 150 |  |  |  |  |  |  | } | 
| 151 |  |  |  |  |  |  |  | 
| 152 |  |  |  |  |  |  | sub write($;$) | 
| 153 |  |  |  |  |  |  | { | 
| 154 | 18 |  |  | 18 | 1 | 2010 | my ($self, $packfile) = @_; | 
| 155 | 18 |  | 66 |  |  | 116 | $self = tied(%$self) || $self; | 
| 156 | 18 | 100 |  |  |  | 59 | if (defined($packfile)) { $self->{packfile} = $packfile; } | 
|  | 17 |  |  |  |  | 82 |  | 
| 157 | 1 |  |  |  |  | 2 | else { $packfile = $self->{packfile}; } | 
| 158 | 18 | 100 |  |  |  | 266 | Carp::croak("No packlist filename specified") if (! defined($packfile)); | 
| 159 | 17 |  |  |  |  | 79 | my $fh = mkfh(); | 
| 160 | 17 | 50 |  |  |  | 1241 | open($fh, ">$packfile") || Carp::croak("Can't open file $packfile: $!"); | 
| 161 | 17 |  |  |  |  | 95 | foreach my $key (sort(keys(%{$self->{data}}))) | 
|  | 17 |  |  |  |  | 244 |  | 
| 162 |  |  |  |  |  |  | { | 
| 163 | 28 |  |  |  |  | 83 | my $data = $self->{data}->{$key}; | 
| 164 | 28 | 50 |  |  |  | 341 | if ($Config{userelocatableinc}) { | 
| 165 | 0 |  | 0 |  |  | 0 | $Relocations ||= __find_relocations(); | 
| 166 | 0 | 0 |  |  |  | 0 | if ($packfile =~ $Relocations) { | 
| 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 |  |  |  |  | 0 | my $prefix = $1; | 
| 170 | 0 | 0 |  |  |  | 0 | if (File::Spec->no_upwards(File::Spec->abs2rel($key, $prefix))) | 
| 171 |  |  |  |  |  |  | { | 
| 172 |  |  |  |  |  |  | # The relocated path is within the found prefix | 
| 173 | 0 |  |  |  |  | 0 | my $packfile_prefix; | 
| 174 | 0 |  |  |  |  | 0 | (undef, $packfile_prefix) | 
| 175 |  |  |  |  |  |  | = File::Spec->splitpath($packfile); | 
| 176 |  |  |  |  |  |  |  | 
| 177 | 0 |  |  |  |  | 0 | my $relocate_as | 
| 178 |  |  |  |  |  |  | = File::Spec->abs2rel($key, $packfile_prefix); | 
| 179 |  |  |  |  |  |  |  | 
| 180 | 0 | 0 |  |  |  | 0 | if (!ref $data) { | 
| 181 | 0 |  |  |  |  | 0 | $data = {}; | 
| 182 |  |  |  |  |  |  | } | 
| 183 | 0 |  |  |  |  | 0 | $data->{relocate_as} = $relocate_as; | 
| 184 |  |  |  |  |  |  | } | 
| 185 |  |  |  |  |  |  | } | 
| 186 |  |  |  |  |  |  | } | 
| 187 | 28 |  |  |  |  | 206 | print $fh ("$key"); | 
| 188 | 28 | 100 |  |  |  | 94 | if (ref($data)) | 
| 189 |  |  |  |  |  |  | { | 
| 190 | 1 |  |  |  |  | 5 | foreach my $k (sort(keys(%$data))) | 
| 191 |  |  |  |  |  |  | { | 
| 192 | 2 |  |  |  |  | 7 | print $fh (" $k=$data->{$k}"); | 
| 193 |  |  |  |  |  |  | } | 
| 194 |  |  |  |  |  |  | } | 
| 195 | 28 |  |  |  |  | 62 | print $fh ("\n"); | 
| 196 |  |  |  |  |  |  | } | 
| 197 | 17 |  |  |  |  | 1235 | close($fh); | 
| 198 |  |  |  |  |  |  | } | 
| 199 |  |  |  |  |  |  |  | 
| 200 |  |  |  |  |  |  | sub validate($;$) | 
| 201 |  |  |  |  |  |  | { | 
| 202 | 2 |  |  | 2 | 1 | 2782 | my ($self, $remove) = @_; | 
| 203 | 2 |  | 33 |  |  | 20 | $self = tied(%$self) || $self; | 
| 204 | 2 |  |  |  |  | 6 | my @missing; | 
| 205 | 2 |  |  |  |  | 6 | foreach my $key (sort(keys(%{$self->{data}}))) | 
|  | 2 |  |  |  |  | 21 |  | 
| 206 |  |  |  |  |  |  | { | 
| 207 | 4 | 100 |  |  |  | 111 | if (! -e $key) | 
| 208 |  |  |  |  |  |  | { | 
| 209 | 2 |  |  |  |  | 13 | push(@missing, $key); | 
| 210 | 2 | 100 |  |  |  | 11 | delete($self->{data}{$key}) if ($remove); | 
| 211 |  |  |  |  |  |  | } | 
| 212 |  |  |  |  |  |  | } | 
| 213 | 2 |  |  |  |  | 13 | return(@missing); | 
| 214 |  |  |  |  |  |  | } | 
| 215 |  |  |  |  |  |  |  | 
| 216 |  |  |  |  |  |  | sub packlist_file($) | 
| 217 |  |  |  |  |  |  | { | 
| 218 | 2 |  |  | 2 | 1 | 18 | my ($self) = @_; | 
| 219 | 2 |  | 66 |  |  | 18 | $self = tied(%$self) || $self; | 
| 220 | 2 |  |  |  |  | 34 | return($self->{packfile}); | 
| 221 |  |  |  |  |  |  | } | 
| 222 |  |  |  |  |  |  |  | 
| 223 |  |  |  |  |  |  | 1; | 
| 224 |  |  |  |  |  |  |  | 
| 225 |  |  |  |  |  |  | __END__ |