« blib/lib/auto/share/dist/Perl-Dist/default/perl-5.8.8/lib/ExtUtils/MM_Win32.pm
↑ Summary
blib/lib/Perl/Dist/Asset/Website.pm »
| 1 | package ExtUtils::Packlist; | ||
| 2 | |||
| 3 | use 5.00503; | ||
| 4 | use strict; | ||
| 5 | use Carp qw(); | ||
| 6 | use Config; | ||
| 7 | use vars qw($VERSION $Relocations); | ||
| 8 | $VERSION = '1.43'; | ||
| 9 | $VERSION = eval $VERSION; | ||
| 10 | |||
| 11 | # Used for generating filehandle globs. IO::File might not be available! | ||
| 12 | 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 | no strict; | ||
| 25 | my $fh = \*{$fhname++}; | ||
| 26 | use strict; | ||
| 27 | 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 | my %paths; | ||
| 42 | while (my ($raw_key, $raw_val) = each %Config) { | ||
| 43 | my $exp_key = $raw_key . "exp"; | ||
| 44 | next unless exists $Config{$exp_key}; | ||
| 45 | next unless $raw_val =~ m!\.\.\./!; | ||
| 46 | $paths{$Config{$exp_key}}++; | ||
| 47 | } | ||
| 48 | # Longest prefixes go first in the alternatives | ||
| 49 | my $alternations = join "|", map {quotemeta $_} | ||
| 50 | sort {length $b <=> length $a} keys %paths; | ||
| 51 | qr/^($alternations)/o; | ||
| 52 | } | ||
| 53 | |||
| 54 | sub new($$) | ||
| 55 | { | ||
| 56 | my ($class, $packfile) = @_; | ||
| 57 | $class = ref($class) || $class; | ||
| 58 | my %self; | ||
| 59 | tie(%self, $class, $packfile); | ||
| 60 | return(bless(\%self, $class)); | ||
| 61 | } | ||
| 62 | |||
| 63 | sub TIEHASH | ||
| 64 | { | ||
| 65 | my ($class, $packfile) = @_; | ||
| 66 | my $self = { packfile => $packfile }; | ||
| 67 | bless($self, $class); | ||
| 68 | $self->read($packfile) if (defined($packfile) && -f $packfile); | ||
| 69 | return($self); | ||
| 70 | } | ||
| 71 | |||
| 72 | sub STORE | ||
| 73 | { | ||
| 74 | $_[0]->{data}->{$_[1]} = $_[2]; | ||
| 75 | } | ||
| 76 | |||
| 77 | sub FETCH | ||
| 78 | { | ||
| 79 | return($_[0]->{data}->{$_[1]}); | ||
| 80 | } | ||
| 81 | |||
| 82 | sub FIRSTKEY | ||
| 83 | { | ||
| 84 | my $reset = scalar(keys(%{$_[0]->{data}})); | ||
| 85 | return(each(%{$_[0]->{data}})); | ||
| 86 | } | ||
| 87 | |||
| 88 | sub NEXTKEY | ||
| 89 | { | ||
| 90 | return(each(%{$_[0]->{data}})); | ||
| 91 | } | ||
| 92 | |||
| 93 | sub EXISTS | ||
| 94 | { | ||
| 95 | return(exists($_[0]->{data}->{$_[1]})); | ||
| 96 | } | ||
| 97 | |||
| 98 | sub DELETE | ||
| 99 | { | ||
| 100 | return(delete($_[0]->{data}->{$_[1]})); | ||
| 101 | } | ||
| 102 | |||
| 103 | sub CLEAR | ||
| 104 | { | ||
| 105 | %{$_[0]->{data}} = (); | ||
| 106 | } | ||
| 107 | |||
| 108 | sub DESTROY | ||
| 109 | { | ||
| 110 | } | ||
| 111 | |||
| 112 | sub read($;$) | ||
| 113 | { | ||
| 114 | my ($self, $packfile) = @_; | ||
| 115 | $self = tied(%$self) || $self; | ||
| 116 | |||
| 117 | if (defined($packfile)) { $self->{packfile} = $packfile; } | ||
| 118 | else { $packfile = $self->{packfile}; } | ||
| 119 | Carp::croak("No packlist filename specified") if (! defined($packfile)); | ||
| 120 | my $fh = mkfh(); | ||
| 121 | open($fh, "<$packfile") || Carp::croak("Can't open file $packfile: $!"); | ||
| 122 | $self->{data} = {}; | ||
| 123 | my ($line); | ||
| 124 | while (defined($line = <$fh>)) | ||
| 125 | { | ||
| 126 | chomp $line; | ||
| 127 | my ($key, $data) = $line; | ||
| 128 | if ($key =~ /^(.*?)( \w+=.*)$/) | ||
| 129 | { | ||
| 130 | $key = $1; | ||
| 131 | $data = { map { split('=', $_) } split(' ', $2)}; | ||
| 132 | |||
| 133 | if ($Config{userelocatableinc} && $data->{relocate_as}) | ||
| 134 | { | ||
| 135 | require File::Spec; | ||
| 136 | require Cwd; | ||
| 137 | my ($vol, $dir) = File::Spec->splitpath($packfile); | ||
| 138 | my $newpath = File::Spec->catpath($vol, $dir, $data->{relocate_as}); | ||
| 139 | $key = Cwd::realpath($newpath); | ||
| 140 | } | ||
| 141 | } | ||
| 142 | $key =~ s!/\./!/!g; # Some .packlists have spurious '/./' bits in the paths | ||
| 143 | $self->{data}->{$key} = $data; | ||
| 144 | } | ||
| 145 | close($fh); | ||
| 146 | } | ||
| 147 | |||
| 148 | sub write($;$) | ||
| 149 | { | ||
| 150 | my ($self, $packfile) = @_; | ||
| 151 | $self = tied(%$self) || $self; | ||
| 152 | if (defined($packfile)) { $self->{packfile} = $packfile; } | ||
| 153 | else { $packfile = $self->{packfile}; } | ||
| 154 | Carp::croak("No packlist filename specified") if (! defined($packfile)); | ||
| 155 | my $fh = mkfh(); | ||
| 156 | open($fh, ">$packfile") || Carp::croak("Can't open file $packfile: $!"); | ||
| 157 | foreach my $key (sort(keys(%{$self->{data}}))) | ||
| 158 | { | ||
| 159 | my $data = $self->{data}->{$key}; | ||
| 160 | if ($Config{userelocatableinc}) { | ||
| 161 | $Relocations ||= __find_relocations(); | ||
| 162 | if ($packfile =~ $Relocations) { | ||
| 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 | my $prefix = $1; | ||
| 166 | if (File::Spec->no_upwards(File::Spec->abs2rel($key, $prefix))) | ||
| 167 | { | ||
| 168 | # The relocated path is within the found prefix | ||
| 169 | my $packfile_prefix; | ||
| 170 | (undef, $packfile_prefix) | ||
| 171 | = File::Spec->splitpath($packfile); | ||
| 172 | |||
| 173 | my $relocate_as | ||
| 174 | = File::Spec->abs2rel($key, $packfile_prefix); | ||
| 175 | |||
| 176 | if (!ref $data) { | ||
| 177 | $data = {}; | ||
| 178 | } | ||
| 179 | $data->{relocate_as} = $relocate_as; | ||
| 180 | } | ||
| 181 | } | ||
| 182 | } | ||
| 183 | print $fh ("$key"); | ||
| 184 | if (ref($data)) | ||
| 185 | { | ||
| 186 | foreach my $k (sort(keys(%$data))) | ||
| 187 | { | ||
| 188 | print $fh (" $k=$data->{$k}"); | ||
| 189 | } | ||
| 190 | } | ||
| 191 | print $fh ("\n"); | ||
| 192 | } | ||
| 193 | close($fh); | ||
| 194 | } | ||
| 195 | |||
| 196 | sub validate($;$) | ||
| 197 | { | ||
| 198 | my ($self, $remove) = @_; | ||
| 199 | $self = tied(%$self) || $self; | ||
| 200 | my @missing; | ||
| 201 | foreach my $key (sort(keys(%{$self->{data}}))) | ||
| 202 | { | ||
| 203 | if (! -e $key) | ||
| 204 | { | ||
| 205 | push(@missing, $key); | ||
| 206 | delete($self->{data}{$key}) if ($remove); | ||
| 207 | } | ||
| 208 | } | ||
| 209 | return(@missing); | ||
| 210 | } | ||
| 211 | |||
| 212 | sub packlist_file($) | ||
| 213 | { | ||
| 214 | my ($self) = @_; | ||
| 215 | $self = tied(%$self) || $self; | ||
| 216 | return($self->{packfile}); | ||
| 217 | } | ||
| 218 | |||
| 219 | 1; | ||
| 220 | |||
| 221 | __END__ |