File Coverage

blib/lib/Module/Install/Admin/Manifest.pm
Criterion Covered Total %
statement 17 95 17.8
branch 0 46 0.0
condition n/a
subroutine 6 10 60.0
pod 0 2 0.0
total 23 153 15.0


line stmt bran cond sub pod time code
1             package Module::Install::Admin::Manifest;
2              
3 1     1   1349 use strict;
  1         2  
  1         27  
4 1     1   4 use Module::Install::Base;
  1         2  
  1         19  
5              
6 1     1   4 use vars qw{$VERSION @ISA};
  1         1  
  1         49  
7             BEGIN {
8 1     1   2 $VERSION = '1.19';
9 1         42 @ISA = qw{Module::Install::Base};
10             }
11              
12 1     1   6 use Cwd ();
  1         1  
  1         12  
13 1     1   5 use File::Spec;
  1         1  
  1         828  
14              
15             # XXX I really want this method in Module::Install::Admin::Makefile
16             # But you can't call across Admin modules. Audrey??
17             sub dist_preop {
18 0     0 0   my ($self, $distdir) = @_;
19 0 0         return if $self->check_manifest;
20 0           print <<"END_MESSAGE";
21              
22             It appears that your MANIFEST does not contain the same components that
23             are currently in the 'inc' directory.
24              
25             Please try running 'make manifest' and then run 'make dist' again.
26              
27             Remember to use the MANIFEST.SKIP file to control things that should not
28             end up in your MANIFEST. See 'perldoc ExtUtils::Manifest' for details.
29              
30             END_MESSAGE
31 0 0         return if $self->prompt(
32             'Do you *really* want to continue making a distribution?', 'n'
33             ) =~ /^[Yy]/;
34              
35 0 0         if ( -d $distdir ) {
36 0           require File::Path;
37 0           File::Path::rmtree($distdir);
38             }
39              
40 0           exit(1);
41             }
42              
43             # XXX Needs a refactoring.
44             sub check_manifest {
45 0     0 0   my $self = shift;
46 0           my $prefix = $self->_top->{prefix};
47 0 0         my ($manifest, $manifest_path, $relative_path) = $self->_read_manifest or return;
48 0           my $manifest_skip = "$manifest_path.SKIP";
49 0           my @skip;
50              
51 0 0         if ( -f "$manifest_path.SKIP" ) {
52 0 0         open SKIP, $manifest_skip
53             or die "Can't open $manifest_skip for input:\n$!";
54 0           @skip = map {chomp; $_} ;
  0            
  0            
55 0           close SKIP;
56             }
57              
58 0           my %manifest;
59 0           for ( my $i = 0; $i < @$manifest; $i++ ) {
60 0           my $path = $manifest->[$i];
61 0           $path =~ s/\s.*//;
62 0           $path =~ s/^\.[\\\/]//;
63 0           $path =~ s/[\\\/]/\//g;
64 0 0         next unless $path =~ m/^\Q$prefix\E\b/i;
65 0           $manifest{$path} = \$manifest->[$i];
66             }
67              
68             ADDLOOP:
69 0           for my $pathname ( sort $self->_find_files($prefix) ) {
70 0 0         $pathname = "$relative_path/$pathname" if length($relative_path);
71 0           $pathname =~ s!//+!/!g;
72 0 0         next unless -f $pathname;
73 0 0         if ( defined $manifest{$pathname} ) {
74 0           delete $manifest{$pathname};
75             } else {
76 0           for ( @skip ) {
77 0 0         next ADDLOOP if $pathname =~ /$_/;
78             }
79 0           return 0;
80             }
81             }
82 0 0         if ( keys %manifest ) {
83 0           foreach ( keys %manifest ) {
84 0           print "Found extra file $_\n";
85             }
86 0           return 0;
87             }
88 0           return 1;
89             }
90              
91             sub _read_manifest {
92 0     0     my $manifest = [];
93 0           my $manifest_path = '';
94 0           my $relative_path = '';
95 0           my @relative_dirs = ();
96 0           my $cwd = Cwd::getcwd();
97 0           my @cwd_dirs = File::Spec->splitdir($cwd);
98 0           while ( @cwd_dirs ) {
99 0 0         last unless -f File::Spec->catfile(@cwd_dirs, 'Makefile.PL');
100 0           my $path = File::Spec->catfile(@cwd_dirs, 'MANIFEST');
101 0 0         if ( -f $path ) {
102 0           $manifest_path = $path;
103 0           last;
104             }
105 0           unshift @relative_dirs, pop(@cwd_dirs);
106             }
107              
108 0 0         unless ( length($manifest_path) ) {
109 0           warn "Can't locate the MANIFEST file for '$cwd'\n";
110 0           return;
111             }
112              
113 0 0         $relative_path = join '/', @relative_dirs if @relative_dirs;
114              
115 0           local *MANIFEST;
116 0 0         open MANIFEST, $manifest_path
117             or die "Can't open $manifest_path for input:\n$!";
118 0           @$manifest = map { chomp; $_ } ;
  0            
  0            
119 0           close MANIFEST;
120              
121 0           return ($manifest, $manifest_path, $relative_path);
122             }
123              
124             # XXX I copied this from M::I::A::Find because I can't call that one. Please
125             # refactor/fix.
126             sub _find_files {
127 0     0     my ($self, $file, $path) = @_;
128 0 0         $path = '' if not defined $path;
129 0 0         $file = "$path/$file" if length($path);
130 0 0         if ( -f $file ) {
    0          
131 0           return ( $file );
132             } elsif ( -d $file ) {
133 0           my @files = ();
134 0           local *DIR;
135 0 0         opendir(DIR, $file) or die "Can't opendir $file";
136 0           while (defined(my $new_file = readdir(DIR))) {
137 0 0         next if $new_file =~ /^(\.|\.\.)$/;
138 0           push @files, $self->_find_files($new_file, $file);
139             }
140 0           return @files;
141             }
142 0           return ();
143             }
144              
145             1;
146              
147             __END__