ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/Perl-LibExtractor/LibExtractor.pm
(Generate patch)

Comparing cvsroot/Perl-LibExtractor/LibExtractor.pm (file contents):
Revision 1.14 by root, Wed Jan 25 21:27:54 2012 UTC vs.
Revision 1.15 by root, Thu Jan 26 01:24:25 2012 UTC

149 ? qr<$re>i 149 ? qr<$re>i
150 : qr<$re> 150 : qr<$re>
151} 151}
152 152
153sub _read_packlist { 153sub _read_packlist {
154 my ($self, $root, $path) = @_; 154 my ($self, $path) = @_;
155 155
156 my $pfxmatch = $self->{pfxmatch};
156 my $lib = $self->{lib}; 157 my $lib = $self->{lib};
157 158
158 my @packlist; 159 my @packlist;
159 160
160 open my $fh, "<:perlio", "$root/$path" 161 open my $fh, "<:perlio", $path
161 or die "$root/$path: $!"; 162 or die "$path: $!";
162
163 $root = _path2match $root;
164 163
165 while (<$fh>) { 164 while (<$fh>) {
166 chomp; 165 chomp;
167 s/ .*$//; # newer-style .packlists might contain key=value pairs 166 s/ .*$//; # newer-style .packlists might contain key=value pairs
168 167
169 s/$root// and exists $lib->{$_} 168 s/$pfxmatch// and exists $lib->{$_}
170 or next; 169 or next;
171 170
172 push @packlist, canonpath $_; 171 push @packlist, canonpath $_;
173 } 172 }
174 173
176} 175}
177 176
178sub _set_inc { 177sub _set_inc {
179 my ($self) = @_; 178 my ($self) = @_;
180 179
181 my $matchprefix = _path2match @{ $self->{inc }}; 180 my $pfxmatch = _path2match @{ $self->{inc }};
182 181
183 my %lib; 182 my %lib;
184 my @packlists; 183 my @packlists;
185 184
186 # find all files in all libdirs, earlier ones overwrite later ones 185 # find all files in all libdirs, earlier ones overwrite later ones
198 }) { 197 }) {
199 if (-d "$root/$dir/$_/.") { 198 if (-d "$root/$dir/$_/.") {
200 $lib{"$pfx$_/"} = "$root/$pfx$_"; 199 $lib{"$pfx$_/"} = "$root/$pfx$_";
201 push @scan, [$root, "$pfx$_"]; 200 push @scan, [$root, "$pfx$_"];
202 } elsif ($_ eq ".packlist" && $pfx =~ m%^auto/%) { 201 } elsif ($_ eq ".packlist" && $pfx =~ m%^auto/%) {
203 push @packlists, [$root, $pfx]; 202 push @packlists, "$root/$pfx.packlist";
204 } elsif (/\.bs$/ && $pfx =~ m%^auto/% && !-s "$root/$dir/$_") { 203 } elsif (/\.bs$/ && $pfx =~ m%^auto/% && !-s "$root/$dir/$_") {
205 # skip empty .bs files 204 # skip empty .bs files
206# } elsif (/\.(?:pod|h|html)$/) { 205# } elsif (/\.(?:pod|h|html)$/) {
207# # not interested in those 206# # not interested in those
208 } else { 207 } else {
212 } 211 }
213 212
214 #$lib{"$_[1]/"} = [\@dirs, \@files]; # won't work nice with overwrite 213 #$lib{"$_[1]/"} = [\@dirs, \@files]; # won't work nice with overwrite
215 } 214 }
216 215
217 $self->{lib} = \%lib; 216 $self->{lib} = \%lib;
218 $self->{matchprefix} = $matchprefix; 217 $self->{pfxmatch} = $pfxmatch;
219 218
220 my %packlist; 219 my %packlist;
221 220
222 # need to go forward here 221 # need to go forward here
223 for (@packlists) { 222 for (@packlists) {
224 my $packlist = $self->_read_packlist ($_->[0], "$_->[1]/.packlist"); 223 my $packlist = $self->_read_packlist ($_);
225 224
226 $packlist{$_} = $packlist 225 $packlist{$_} = $packlist
227 for @$packlist; 226 for @$packlist;
228 } 227 }
229 228
405 or croak "$dir/out: $!"; 404 or croak "$dir/out: $!";
406 local $/; 405 local $/;
407 scalar readline $fh 406 scalar readline $fh
408 }; 407 };
409 408
410 my $matchprefix = $self->{matchprefix}; 409 my $pfxmatch = $self->{pfxmatch};
411 410
412 # remove the library directory prefix, hope for the best 411 # remove the library directory prefix, hope for the best
413 s/$matchprefix// 412 s/$pfxmatch//
414 or croak "$_: file outside any library directory" 413 or croak "$_: file outside any library directory"
415 for @inc; 414 for @inc;
416 415
417 $self->_add (\@inc); 416 $self->_add (\@inc);
418 } 417 }
637 my ($self) = @_; 636 my ($self) = @_;
638 637
639 my $lib = $self->{lib}; 638 my $lib = $self->{lib};
640 639
641 for (@{ 640 for (@{
642 $self->_read_packlist ($Config{privlibexp}, ".packlist") 641 $self->_read_packlist (".packlist")
643 }) { 642 }) {
644 $self->{set}{$_} ||= [ 643 $self->{set}{$_} ||= [
645 "lib/" 644 "lib/"
646 . ($lib->{$_} or croak "$_: unable to locate file in perl library") 645 . ($lib->{$_} or croak "$_: unable to locate file in perl library")
647 ]; 646 ];

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines