File: check-require

package info (click to toggle)
perl 5.20.2-3%2Bdeb8u11
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 102,964 kB
  • sloc: perl: 555,553; ansic: 214,041; sh: 38,121; pascal: 8,783; cpp: 3,895; makefile: 2,393; xml: 2,325; yacc: 1,741
file content (84 lines) | stat: -rwxr-xr-x 1,909 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!perl

# check that the Perl modules listed in STDIN can be used with only
# modules under the current directory (or the one given as the
# only argument)

# Copyright 2010 Niko Tyni <ntyni@debian.org>
#
# This program is free software;
# you may redistribute it and/or modify it under the same terms as Perl
# itself.

# only look under the specified directory, default to cwd
BEGIN {
	my $dir = shift || '.';
	chdir $dir or die("chdir $dir: $!");
	@INC=map { qq{.$_} } grep m|^/|, @INC;
}

# unbuffer output
$| = 1;

# supported input format variations:
#  usr/share/perl/5.12/Tie/Hash.pm
#  usr/*/perl/*/Tie/Hash.pm
#  Tie::Hash
#  usr/*/perl/*/File/Glob
#  usr/share/perl/5.12/Config_heavy.pl
#  Config_heavy.pl
#  Config
#  unicore/heavy.pl
#  sys/ioctl.ph

sub canonicalize {
	local $_ = shift;
	/\*/ and do {
    		my @files = glob;
    		die("no files globbed by $_") if !@files;
		return map { canonicalize($_) } @files;
	};
	-d and do {
		return canonicalize("$_/*");
	};

	# usr/*/perl/*/auto/File/Glob/Glob.so and the like should be ignored
	return () if m|/| && !/\.p[hlm]$/;

	s|usr/share/perl/[^/]+/||;
	s|usr/lib/[^/]+/perl/[^/]+/||;

	s|/|::|g if s/\.pm$//;
	return ($_);
}

while (<>) {
	chomp;
	next if !/\S/ || /^\s*#/;
	check($_) for canonicalize($_);
}

my %seen;
sub check {
	local $_ = shift;
	return if $seen{$_}++;
	# "use IO" and "use re" are deprecated and/or useless
	return if $_ eq 'IO' || $_ eq 're';
	# "use feature" dies without an argument
	return if $_ eq 'feature';
	# this file does not return a true value, and is not to be used
	# directly
	return if $_ eq 'unicore/To/Isc.pl';
	if (m|([^/]+)_heavy\.pl|) {
		# bytes_heavy.pl needs bytes.pm loaded first
		check($1);
	};
	print "$_: ";
	if (/\.p[hl]$/) { #  require "unicore/To/Upper.pl";
		require $_;
	} else { # require Fcntl; Fcntl->import;
		eval qq{require $_; $_->import;};
		die $@ if $@; 
	}
	print "ok\n";
}