| 1 |
#!perl |
| 2 |
|
| 3 |
# check that the Perl modules listed in STDIN can be used with only |
| 4 |
# modules under the current directory (or the one given as the |
| 5 |
# only argument) |
| 6 |
|
| 7 |
# Copyright 2010 Niko Tyni <[email protected]> |
| 8 |
# |
| 9 |
# This program is free software; |
| 10 |
# you may redistribute it and/or modify it under the same terms as Perl |
| 11 |
# itself. |
| 12 |
|
| 13 |
# only look under the specified directory, default to cwd |
| 14 |
BEGIN { |
| 15 |
my $dir = shift || '.'; |
| 16 |
chdir $dir or die("chdir $dir: $!"); |
| 17 |
@INC=map { qq{.$_} } grep m|^/|, @INC; |
| 18 |
} |
| 19 |
|
| 20 |
# unbuffer output |
| 21 |
$| = 1; |
| 22 |
|
| 23 |
# supported input format variations: |
| 24 |
# ./usr/share/perl/5.12/Tie/Hash.pm |
| 25 |
# usr/share/perl/5.12/Tie/Hash.pm |
| 26 |
# usr/*/perl/*/Tie/Hash.pm |
| 27 |
# Tie::Hash |
| 28 |
# usr/*/perl/*/File/Glob |
| 29 |
# usr/share/perl/5.12/Config_heavy.pl |
| 30 |
# Config_heavy.pl |
| 31 |
# Config |
| 32 |
# unicore/heavy.pl |
| 33 |
# sys/ioctl.ph |
| 34 |
|
| 35 |
sub canonicalize { |
| 36 |
local $_ = shift; |
| 37 |
|
| 38 |
s|^\./||; |
| 39 |
|
| 40 |
/\*/ and do { |
| 41 |
my @files = glob; |
| 42 |
die("no files globbed by $_") if !@files; |
| 43 |
return map { canonicalize($_) } @files; |
| 44 |
}; |
| 45 |
-d and do { |
| 46 |
return canonicalize("$_/*"); |
| 47 |
}; |
| 48 |
|
| 49 |
# usr/*/perl/*/auto/File/Glob/Glob.so and the like should be ignored |
| 50 |
return () if m|/| && !/\.p[hlm]$/; |
| 51 |
|
| 52 |
s|usr/share/perl/[^/]+/||; |
| 53 |
s|usr/lib/[^/]+/perl/[^/]+/||; |
| 54 |
s|usr/lib/[^/]+/perl-base/||; |
| 55 |
|
| 56 |
s|/|::|g if s/\.pm$//; |
| 57 |
return ($_); |
| 58 |
} |
| 59 |
|
| 60 |
while (<>) { |
| 61 |
chomp; |
| 62 |
next if !/\S/ || /^\s*#/; |
| 63 |
check($_) for canonicalize($_); |
| 64 |
} |
| 65 |
|
| 66 |
my %seen; |
| 67 |
sub check { |
| 68 |
local $_ = shift; |
| 69 |
return if $seen{$_}++; |
| 70 |
# "use IO" and "use re" are deprecated and/or useless |
| 71 |
return if $_ eq 'IO' || $_ eq 're'; |
| 72 |
# "use feature" dies without an argument |
| 73 |
return if $_ eq 'feature'; |
| 74 |
# builtin only works at compile time, and is always built in |
| 75 |
return if $_ eq 'builtin'; |
| 76 |
# this file does not return a true value, and is not to be used |
| 77 |
# directly |
| 78 |
return if $_ eq 'unicore/To/Isc.pl'; |
| 79 |
print "$_: "; |
| 80 |
if (/\.p[hl]$/) { # require "unicore/To/Upper.pl"; |
| 81 |
require $_; |
| 82 |
} else { # require Fcntl; Fcntl->import; |
| 83 |
eval qq{require $_; $_->import;}; |
| 84 |
die $@ if $@; |
| 85 |
} |
| 86 |
print "ok\n"; |
| 87 |
} |