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   3257 use warnings;
  7         11  
  7         307  
3 7     7   25 use strict;
  7         10  
  7         132  
4 7     7   20 use File::Spec::Functions qw(catfile);
  7         8  
  7         292  
5 7     7   2551 use Array::Diff;
  7         38313  
  7         56  
6              
7             our $VERSION = '1.03';
8             $VERSION =~ s/_//; ## no critic
9              
10 49     49 1 131 sub order { 100 }
11              
12             ##################################################################
13             # Analyse
14             ##################################################################
15              
16             sub analyse {
17 12     12 1 40 my $class = shift;
18 12         30 my $me = shift;
19              
20 12         240 my $distdir = $me->distdir;
21 12         112 my $manifest_file = catfile($distdir, 'MANIFEST');
22              
23 12 100       360 if (-e $manifest_file) {
24             # read manifest
25 4 50       142 open(my $fh, '<', $manifest_file) or die "cannot read MANIFEST $manifest_file: $!";
26 4         16 my %seen;
27 4         90 while (<$fh>) {
28 7         15 chomp;
29 7 50       21 next if /^\s*#/; # discard pure comments
30 7 50       15 if (s/^'(\\[\\']|.+)+'\s*.*/$1/) {
31 0         0 s/\\([\\'])/$1/g;
32             } else {
33 7         13 s/\s.*$//;
34             } # strip quotes and comments
35 7 50       14 next unless $_; # discard blank lines
36 7         39 $seen{$_}++;
37             }
38 4         32 close $fh;
39              
40 4         32 my @manifest = sort keys %seen;
41 4 50       9 my @files = sort keys %{$me->d->{files_hash} || {}};
  4         91  
42 4         37 my @dupes = grep {$seen{$_} > 1} @manifest;
  7         24  
43              
44 4         68 my $diff = Array::Diff->diff(\@manifest, \@files);
45 4 100 66     1510 if ($diff->count == 0 && !@dupes) {
46 1         19 $me->d->{manifest_matches_dist} = 1;
47             }
48             else {
49 3         57 $me->d->{manifest_matches_dist} = 0;
50 3         25 my @error = (
51             'MANIFEST ('.(@manifest + @dupes).') does not match dist ('.@files."):",
52             );
53 3 50       6 if (my @added = @{$diff->added}) {
  3         40  
54 3         43 push @error, "Missing in MANIFEST: ".join(', ', @added);
55             }
56 3 100       9 if (my @deleted = @{$diff->deleted}) {
  3         43  
57 1         9 push @error, "Missing in Dist: " . join(', ', @deleted);
58             }
59 3 50       15 if (@dupes) {
60 0         0 push @error, "Duplicates in MANIFEST: " . join(', ', @dupes);
61             }
62 3         39 $me->d->{error}{manifest_matches_dist} = \@error;
63             }
64              
65             # Tweak symlinks error for a local distribution (RT #97858)
66 4 100 100     67 if ($me->d->{is_local_distribution} && $me->d->{error}{symlinks}) {
67 1         28 my %manifested = map {$_ => 1} @manifest;
  1         16  
68 1         40 my @symlinks = grep {$manifested{$_}} split ',', $me->d->{error}{symlinks};
  1         20  
69 1 50       10 if (@symlinks) {
70 0         0 $me->d->{error}{symlinks} = join ',', @symlinks;
71             } else {
72 1         20 delete $me->d->{error}{symlinks};
73             }
74             }
75             }
76             else {
77 8         172 $me->d->{manifest_matches_dist} = 0;
78 8         160 $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 12 100   12   78 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 105 ];
101             }
102              
103              
104             q{Listening to: YAPC::Europe 2007};
105              
106             __END__