File Coverage

blib/lib/Module/CPANTS/Kwalitee/Manifest.pm
Criterion Covered Total %
statement 57 64 89.0
branch 18 28 64.2
condition 5 6 83.3
subroutine 8 9 88.8
pod 3 3 100.0
total 91 110 82.7


line stmt bran cond sub pod time code
1             package Module::CPANTS::Kwalitee::Manifest;
2 7     7   3506 use warnings;
  7         18  
  7         214  
3 7     7   36 use strict;
  7         17  
  7         149  
4 7     7   35 use File::Spec::Functions qw(catfile);
  7         15  
  7         267  
5 7     7   2873 use Array::Diff;
  7         41271  
  7         49  
6              
7             our $VERSION = '1.01';
8             $VERSION =~ s/_//; ## no critic
9              
10 56     56 1 116 sub order { 100 }
11              
12             ##################################################################
13             # Analyse
14             ##################################################################
15              
16             sub analyse {
17 11     11 1 33 my $class = shift;
18 11         37 my $me = shift;
19              
20 11         257 my $distdir = $me->distdir;
21 11         96 my $manifest_file = catfile($distdir, 'MANIFEST');
22              
23 11 100       199 if (-e $manifest_file) {
24             # read manifest
25 4 50       135 open(my $fh, '<', $manifest_file) or die "cannot read MANIFEST $manifest_file: $!";
26 4         10 my %seen;
27 4         67 while (<$fh>) {
28 7         17 chomp;
29 7 50       16 next if /^\s*#/; # discard pure comments
30 7 50       16 if (s/^'(\\[\\']|.+)+'\s*.*/$1/) {
31 0         0 s/\\([\\'])/$1/g;
32             } else {
33 7         16 s/\s.*$//;
34             } # strip quotes and comments
35 7 50       11 next unless $_; # discard blank lines
36 7         54 $seen{$_}++;
37             }
38 4         31 close $fh;
39              
40 4         21 my @manifest = sort keys %seen;
41 4 50       9 my @files = sort keys %{$me->d->{files_hash} || {}};
  4         86  
42 4         34 my @dupes = grep {$seen{$_} > 1} @manifest;
  7         16  
43              
44 4         54 my $diff = Array::Diff->diff(\@manifest, \@files);
45 4 100 66     1838 if ($diff->count == 0 && !@dupes) {
46 1         22 $me->d->{manifest_matches_dist} = 1;
47             }
48             else {
49 3         75 $me->d->{manifest_matches_dist} = 0;
50 3         30 my @error = (
51             'MANIFEST ('.(@manifest + @dupes).') does not match dist ('.@files."):",
52             );
53 3 50       11 if (my @added = @{$diff->added}) {
  3         50  
54 3         37 push @error, "Missing in MANIFEST: ".join(', ', @added);
55             }
56 3 100       15 if (my @deleted = @{$diff->deleted}) {
  3         73  
57 1         16 push @error, "Missing in Dist: " . join(', ', @deleted);
58             }
59 3 50       19 if (@dupes) {
60 0         0 push @error, "Duplicates in MANIFEST: " . join(', ', @dupes);
61             }
62 3         48 $me->d->{error}{manifest_matches_dist} = \@error;
63             }
64              
65             # Tweak symlinks error for a local distribution (RT #97858)
66 4 100 100     85 if ($me->d->{is_local_distribution} && $me->d->{error}{symlinks}) {
67 1         35 my %manifested = map {$_ => 1} @manifest;
  1         8  
68 1         27 my @symlinks = grep {$manifested{$_}} split ',', $me->d->{error}{symlinks};
  1         12  
69 1 50       14 if (@symlinks) {
70 0         0 $me->d->{error}{symlinks} = join ',', @symlinks;
71             } else {
72 1         23 delete $me->d->{error}{symlinks};
73             }
74             }
75             }
76             else {
77 7         171 $me->d->{manifest_matches_dist} = 0;
78 7         178 $me->d->{error}{manifest_matches_dist} = q{Cannot find MANIFEST in dist.};
79             }
80             }
81              
82             ##################################################################
83             # Kwalitee Indicators
84             ##################################################################
85              
86             sub kwalitee_indicators {
87             return [
88             {
89             name => 'manifest_matches_dist',
90             error => q{MANIFEST does not match the contents of this distribution.},
91             remedy => q{Run a proper command ("make manifest" or "./Build manifest", maybe with a force option), or use a distribution builder to generate the MANIFEST. Or update MANIFEST manually.},
92 11 100   11   117 code => sub { shift->{manifest_matches_dist} ? 1 : 0 },
93             details => sub {
94 0     0   0 my $d = shift;
95 0         0 my $error = $d->{error}{manifest_matches_dist};
96 0 0       0 return $error unless ref $error;
97 0         0 return join "\n", @$error;
98             },
99             }
100 8     8 1 103 ];
101             }
102              
103              
104             q{Listening to: YAPC::Europe 2007};
105              
106             __END__