lib/Module/Install/Admin/Manifest.pm

filter: Statementstmt 18.7% 18 / 96 Branchbran 0.0% 0 / 52 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 6 / 10 Podpod 0.0% 0 / 2 totaltotal 15.0% 24 / 160 CC 30 SCAR 46.3
CC
30
Cov
12%
check_manifest
210.0
_find_files
72.0
_read_manifest
56.0
CRAP 102.4
« lib/Module/Install/PAR.pm ↑ Summary lib/inc/Module/Install.pm »
1 package Module::Install::Admin::Manifest;
2  
3 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use Module::Install::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 46 ▶use vars qw{$VERSION @ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
7 46 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
8 46 $VERSION = '1.21';
9 46 @ISA = qw{Module::Install::Base};
10 }
11  
12 46 ▶use Cwd ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 46 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # XXX I really want this method in Module::Install::Admin::Makefile
16 # But you can't call across Admin modules. Audrey??
17 0 ▶sub dist_preop {
Subroutine dist_preop: not called CC=4 SCAR=30.0
Pod undocumented
18 0 my ($self, $distdir) = @_;
19 0 ▶ return if $self->check_manifest;
Branch: 1 branch
BranchTrueFalseTotal
if $self->check_manifest 0 0 0
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 ▶ return if $self->prompt(
Branch: 1 branch
BranchTrueFalseTotal
if $self->prompt("Do you *really* want to continue making a distribution?", "n") =~ /^[Yy]/ 0 0 0
32 'Do you *really* want to continue making a distribution?', 'n'
33 ) =~ /^[Yy]/;
34  
35 0 ▶ if ( -d $distdir ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $distdir) 0 0 0
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 0 ▶sub check_manifest {
Subroutine check_manifest: not called CC=14 SCAR=53.5
Pod undocumented
45 0 my $self = shift;
46 0 my $prefix = $self->_top->{prefix};
47 0 ▶ my ($manifest, $manifest_path, $relative_path) = $self->_read_manifest or return;
Branch: 1 branch
BranchTrueFalseTotal
() = $self->_read_manifest or return 0 0 0
48 0 my $manifest_skip = "$manifest_path.SKIP";
49 0 my @skip;
50  
51 0 ▶ if ( -f "$manifest_path.SKIP" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "$manifest_path.SKIP") 0 0 0
52 0 ▶ open SKIP, $manifest_skip
Branch: 1 branch
BranchTrueFalseTotal
open SKIP, $manifest_skip or die "Can't open $manifest_skip for input:\n$!" 0 0 0
53 or die "Can't open $manifest_skip for input:\n$!";
54 0 @skip = map {chomp; $_} <SKIP>;
55 0 close SKIP;
56 }
57  
58 0 my %manifest;
59 0 ▶ for ( my $i = 0; $i < @$manifest; $i++ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$manifest) 0 0 0
60 0 my $path = $manifest->[$i];
61 0 $path =~ s/\s.*//;
62 0 $path =~ s/^\.[\\\/]//;
63 0 $path =~ s/[\\\/]/\//g;
64 0 ▶ next unless $path =~ m/^\Q$prefix\E\b/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $path =~ /^\Q$prefix\E\b/i 0 0 0
65 0 $manifest{$path} = \$manifest->[$i];
66 }
67  
68 ADDLOOP:
69 0 for my $pathname ( sort $self->_find_files($prefix) ) {
70 0 ▶ $pathname = "$relative_path/$pathname" if length($relative_path);
Branch: 1 branch
BranchTrueFalseTotal
if length $relative_path 0 0 0
71 0 $pathname =~ s!//+!/!g;
72 0 ▶ next unless -f $pathname;
Branch: 1 branch
BranchTrueFalseTotal
unless -f $pathname 0 0 0
73 0 ▶ if ( defined $manifest{$pathname} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $manifest{$pathname}) { } 0 0 0
74 0 delete $manifest{$pathname};
75 } else {
76 0 for ( @skip ) {
77 0 ▶ next ADDLOOP if $pathname =~ /$_/;
Branch: 1 branch
BranchTrueFalseTotal
if $pathname =~ /$_/ 0 0 0
78 }
79 0 return 0;
80 }
81 }
82 0 ▶ if ( keys %manifest ) {
Branch: 1 branch
BranchTrueFalseTotal
if (keys %manifest) 0 0 0
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 0 ▶sub _read_manifest {
Subroutine _read_manifest: not called CC=7 SCAR=40.3
92 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 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@cwd_dirs) 0 0 0
99 0 ▶ last unless -f File::Spec->catfile(@cwd_dirs, 'Makefile.PL');
Branch: 1 branch
BranchTrueFalseTotal
unless -f "File::Spec"->catfile(@cwd_dirs, "Makefile.PL") 0 0 0
100 0 my $path = File::Spec->catfile(@cwd_dirs, 'MANIFEST');
101 0 ▶ if ( -f $path ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $path) 0 0 0
102 0 $manifest_path = $path;
103 0 last;
104 }
105 0 unshift @relative_dirs, pop(@cwd_dirs);
106 }
107  
108 0 ▶ unless ( length($manifest_path) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (length $manifest_path) 0 0 0
109 0 warn "Can't locate the MANIFEST file for '$cwd'\n";
110 0 return;
111 }
112  
113 0 ▶ $relative_path = join '/', @relative_dirs if @relative_dirs;
Branch: 1 branch
BranchTrueFalseTotal
if @relative_dirs 0 0 0
114  
115 0 local *MANIFEST;
116 0 ▶ open MANIFEST, $manifest_path
Branch: 1 branch
BranchTrueFalseTotal
open MANIFEST, $manifest_path or die "Can't open $manifest_path for input:\n$!" 0 0 0
117 or die "Can't open $manifest_path for input:\n$!";
118 0 @$manifest = map { chomp; $_ } <MANIFEST>;
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 0 ▶sub _find_files {
Subroutine _find_files: not called CC=8 SCAR=42.8
127 0 my ($self, $file, $path) = @_;
128 0 ▶ $path = '' if not defined $path;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $path 0 0 0
129 0 ▶ $file = "$path/$file" if length($path);
Branch: 1 branch
BranchTrueFalseTotal
if length $path 0 0 0
130 0 ▶ if ( -f $file ) {
Branch: 2 branches
BranchTrueFalseTotal
if (-f $file) { } 0 0 0
elsif (-d $file) { } 0 0 0
131 0 return ( $file );
132 } elsif ( -d $file ) {
133 0 my @files = ();
134 0 local *DIR;
135 0 ▶ opendir(DIR, $file) or die "Can't opendir $file";
Branch: 1 branch
BranchTrueFalseTotal
opendir DIR, $file or die "Can't opendir $file" 0 0 0
136 0 ▶ while (defined(my $new_file = readdir(DIR))) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $new_file = readdir DIR)) 0 0 0
137 0 ▶ next if $new_file =~ /^(\.|\.\.)$/;
Branch: 1 branch
BranchTrueFalseTotal
if $new_file =~ /^(\.|\.\.)$/ 0 0 0
138 0 push @files, $self->_find_files($new_file, $file);
139 }
140 0 return @files;
141 }
142 0 return ();
143 }
144  
145 46 1;
146  
147 __END__
« lib/Module/Install/PAR.pm ↑ Summary lib/inc/Module/Install.pm »