File: check-require

package info (click to toggle)
perl 5.24.1-3+deb9u5
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 103,716 kB
  • sloc: perl: 559,611; ansic: 293,886; sh: 67,316; pascal: 7,632; cpp: 3,895; makefile: 2,436; xml: 2,410; yacc: 989; sed: 6; lisp: 1
file content (89 lines) | stat: -rwxr-xr-x 1,990 bytes parent folder | download | duplicates (4)
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
85
86
87
88
89
#!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/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;

	s|^\./||;

	/\*/ 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|usr/lib/[^/]+/perl-base/||;

	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";
}