package Maintainers;
use strict;
+use warnings;
use lib "Porting";
# Please don't use post 5.008 features as this module is used by
@EXPORT_OK = qw(%Modules %Maintainers
get_module_files get_module_pat
show_results process_options files_to_modules
+ finish_tap_output
reload_manifest);
-$VERSION = 0.03;
+$VERSION = 0.12;
+
require Exporter;
use File::Find;
sub reload_manifest {
%MANIFEST = ();
- if (open(MANIFEST, "MANIFEST")) {
- while (<MANIFEST>) {
+
+ my $manifest_path = 'MANIFEST';
+ if (! -e $manifest_path) {
+ $manifest_path = "../MANIFEST";
+ }
+
+ if (open(my $manfh, '<', $manifest_path )) {
+ while (<$manfh>) {
if (/^(\S+)/) {
$MANIFEST{$1}++;
}
warn "MANIFEST:$.: malformed line: $_\n";
}
}
- close MANIFEST;
+ close $manfh;
} else {
- die "$0: Failed to open MANIFEST for reading: $!\n";
+ die "$0: Failed to open MANIFEST for reading: $!\n";
}
}
split ' ', $Modules{$m}{FILES};
}
-# exand dir/ or foo* into a full list of files
+# expand dir/ or foo* into a full list of files
#
sub expand_glob {
sort { lc $a cmp lc $b }
map {
- -f $_ ? # File as-is.
+ -f $_ && $_ !~ /[*?]/ ? # File as-is.
$_ :
- -d _ ? # Recurse into directories.
+ -d _ && $_ !~ /[*?]/ ? # Recurse into directories.
do {
my @files;
find(
}, $_);
@files;
}
+ # Not a glob, but doesn't exist
+ : $_ !~ /[*?{]/ ? $_
# The rest are globbable patterns; expand the glob, then
- # recurively perform directory expansion on any results
- : expand_glob(grep -e $_,glob($_))
+ # recursively perform directory expansion on any results
+ : expand_glob(glob($_))
} @_;
}
+sub filter_excluded {
+ my ($m, @files) = @_;
+
+ my $excluded = $Modules{$m}{EXCLUDED};
+ return @files
+ unless $excluded and @$excluded;
+
+ my ($pat) = map { qr/$_/ } join '|' => map {
+ ref $_ ? $_ : qr/\b\Q$_\E$/
+ } @{ $excluded };
+
+ return grep { $_ !~ $pat } @files;
+}
+
sub get_module_files {
my $m = shift;
- my %exclude;
- my @files;
- for (get_module_pat($m)) {
- if (s/^!//) {
- $exclude{$_}=1 for expand_glob($_);
- }
- else {
- push @files, expand_glob($_);
- }
- }
- return grep !$exclude{$_}, @files;
+ return filter_excluded $m => map { expand_glob($_) } get_module_pat($m);
}
my $Check;
my $Checkmani;
my $Opened;
+my $TestCounter = 0;
sub process_options {
usage()
if (@ToDo) {
# Try prefix matching.
- # Need to try longst prefixes first, else lib/CPAN may match
+ # Need to try longest prefixes first, else lib/CPAN may match
# lib/CPANPLUS/... and similar
my @OrderedModuleByPat
}
}
} elsif ($Check or $Checkmani) {
+ require Test::More;
+ Test::More->import;
if( @Files ) {
- missing_maintainers(
- $Checkmani
- ? sub { -f $_ and exists $MANIFEST{$File::Find::name} }
- : sub { /\.(?:[chty]|p[lm]|xs)\z/msx },
- @Files
- );
- }
- else {
- duplicated_maintainers();
- }
+ missing_maintainers(
+ $Checkmani
+ ? sub { -f $_ and exists $MANIFEST{$File::Find::name} }
+ : sub { /\.(?:[chty]|p[lm]|xs)\z/msx },
+ @Files
+ );
+ } else {
+ duplicated_maintainers();
+ superfluous_maintainers();
+ }
} elsif (@Files) {
my $ModuleByFile = files_to_modules(@Files);
for my $file (@Files) {
sub duplicated_maintainers {
maintainers_files();
- for my $f (keys %files) {
- if ($files{$f} > 1) {
- warn "File $f appears $files{$f} times in Maintainers.pl\n";
- }
+ for my $f (sort keys %files) {
+ cmp_ok($files{$f}, '<=', 1, "File $f appears $files{$f} times in Maintainers.pl");
}
}
sub warn_maintainer {
my $name = shift;
- warn "File $name has no maintainer\n" if not $files{$name};
+ ok($files{$name}, "$name has a maintainer (see Porting/Maintainer.pl)");
}
sub missing_maintainers {
maintainers_files();
my @dir;
for my $d (@path) {
- if( -d $d ) { push @dir, $d } else { warn_maintainer($d) }
+ if( -d $d ) { push @dir, $d } else { warn_maintainer($d) }
}
- find sub { warn_maintainer($File::Find::name) if $check->() }, @dir
- if @dir;
+ find sub { warn_maintainer($File::Find::name) if $check->() }, @dir if @dir;
+}
+
+sub superfluous_maintainers {
+ maintainers_files();
+ for my $f (sort keys %files) {
+ ok($MANIFEST{$f}, "File $f has a maintainer and is in MANIFEST");
+ }
+}
+
+sub finish_tap_output {
+ done_testing();
}
1;