1 | #!/usr/bin/perl -w
|
---|
2 | #
|
---|
3 | # Get perl modules required by mindi and mondo and that should be on the restore media
|
---|
4 | #
|
---|
5 | use strict;
|
---|
6 |
|
---|
7 | use File::Find;
|
---|
8 |
|
---|
9 | my $file = get_perl_modules(@ARGV) if (defined $ARGV[0]);
|
---|
10 |
|
---|
11 | foreach my $f (sort keys %$file) {
|
---|
12 | print "$f\n";
|
---|
13 | }
|
---|
14 |
|
---|
15 | sub get_perl_modules {
|
---|
16 |
|
---|
17 | my %files;
|
---|
18 |
|
---|
19 | #print "Searching in ";
|
---|
20 | #print join "\n", @INC;
|
---|
21 |
|
---|
22 | my $require = process_file(@_);
|
---|
23 |
|
---|
24 | my @includes;
|
---|
25 |
|
---|
26 | # Remove non exiting directories from @INC
|
---|
27 | # and thus avoid perl warnings
|
---|
28 | #
|
---|
29 | foreach my $d (@INC) {
|
---|
30 | push @includes,$d if (-d $d);
|
---|
31 | }
|
---|
32 |
|
---|
33 | find(
|
---|
34 | sub {
|
---|
35 | if ((-f $File::Find::name)
|
---|
36 | && (/\.pm$/)
|
---|
37 | && (not defined $files{$File::Find::name})) {
|
---|
38 | foreach my $m (keys %$require,"warnings") {
|
---|
39 | (my $mod = $m) =~ s|::|/|g;
|
---|
40 | #print "Looking at $mod in $File::Find::name\n";
|
---|
41 | if (index($File::Find::name,"$mod.pm") ne -1) {
|
---|
42 | $files{$File::Find::name} = $mod;
|
---|
43 | #push @files, $File::Find::name;
|
---|
44 | #print "Found $mod in $File::Find::name\n";
|
---|
45 | last;
|
---|
46 | }
|
---|
47 | }
|
---|
48 | }
|
---|
49 | },
|
---|
50 | @includes);
|
---|
51 |
|
---|
52 | return(\%files);
|
---|
53 | }
|
---|
54 |
|
---|
55 | # Adapted From /usr/lib/rpm/mandriva/perl.req
|
---|
56 | # by Ken Estes Mail.com kestes@staff.mail.com
|
---|
57 |
|
---|
58 | sub process_file {
|
---|
59 |
|
---|
60 | my %line;
|
---|
61 | my %require;
|
---|
62 | my $current_line;
|
---|
63 | my $tag;
|
---|
64 |
|
---|
65 | foreach my $file (@_) {
|
---|
66 |
|
---|
67 | open(FILE, "<$file") || return(\%require);
|
---|
68 |
|
---|
69 | while (<FILE>) {
|
---|
70 |
|
---|
71 | # skip the "= <<" block
|
---|
72 |
|
---|
73 | if ( ( m/^\s*\$(.*)\s*=\s*<<\s*["'](.*)['"]/i) ||
|
---|
74 | ( m/^\s*\$(.*)\s*=\s*<<\s*(.*);/i) ) {
|
---|
75 | $tag = $2;
|
---|
76 | while (<FILE>) {
|
---|
77 | ( $_ =~ /^$tag/) && last;
|
---|
78 | }
|
---|
79 | }
|
---|
80 |
|
---|
81 | # skip the documentation
|
---|
82 |
|
---|
83 | # we should not need to have item in this if statement (it
|
---|
84 | # properly belongs in the over/back section) but people do not
|
---|
85 | # read the perldoc.
|
---|
86 |
|
---|
87 | if ( (m/^=(head1|head2|pod|item)/) .. (m/^=(cut)/) ) {
|
---|
88 | next;
|
---|
89 | }
|
---|
90 |
|
---|
91 | if ( (m/^=(over)/) .. (m/^=(back)/) ) {
|
---|
92 | next;
|
---|
93 | }
|
---|
94 |
|
---|
95 | # skip the data section
|
---|
96 | if (m/^__(DATA|END)__$/) {
|
---|
97 | last;
|
---|
98 | }
|
---|
99 |
|
---|
100 | # Each keyword can appear multiple times. Don't
|
---|
101 | # bother with datastructures to store these strings,
|
---|
102 | # if we need to print it print it now.
|
---|
103 |
|
---|
104 | if ( m/^\s*\$RPM_Requires\s*=\s*["'](.*)['"]/i) {
|
---|
105 | foreach $_ (split(/\s+/, $1)) {
|
---|
106 | print "$_\n";
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | if (
|
---|
111 |
|
---|
112 | # ouch could be in a eval, perhaps we do not want these since we catch
|
---|
113 | # an exception they must not be required
|
---|
114 |
|
---|
115 | # eval { require Term::ReadLine } or die $@;
|
---|
116 | # eval "require Term::Rendezvous;" or die $@;
|
---|
117 | # eval { require Carp } if defined $^S; # If error/warning during compilation,
|
---|
118 |
|
---|
119 |
|
---|
120 | (m/^(\s*) # we hope the inclusion starts the line
|
---|
121 | (require|use)\s+(?!\{) # do not want 'do {' loops
|
---|
122 | # quotes around name are always legal
|
---|
123 | [\'\"]?([^\;\ \'\"\t]*)[\'\"]?[\t\;\ ]
|
---|
124 | # the syntax for 'use' allows version requirements
|
---|
125 | \s*([.0-9]*)
|
---|
126 | /x)
|
---|
127 | ) {
|
---|
128 | my ($whitespace, $statement, $module, $version) = ($1, $2, $3,$4);
|
---|
129 | my $usebase;
|
---|
130 |
|
---|
131 | # we only consider require statements that are flush against
|
---|
132 | # the left edge. any other require statements give too many
|
---|
133 | # false positives, as they are usually inside of an if statement
|
---|
134 | # as a fallback module or a rarely used option
|
---|
135 |
|
---|
136 | ($whitespace ne "" && $statement eq "require") && next;
|
---|
137 |
|
---|
138 | # if there is some interpolation of variables just skip this
|
---|
139 | # dependency, we do not want
|
---|
140 | # do "$ENV{LOGDIR}/$rcfile";
|
---|
141 |
|
---|
142 | ($module =~ m/\$/) && next;
|
---|
143 |
|
---|
144 | # skip if the phrase was "use of" -- shows up in gimp-perl, et al
|
---|
145 | next if $module eq 'of';
|
---|
146 |
|
---|
147 | # if the module ends in a comma we probaly caught some
|
---|
148 | # documentation of the form 'check stuff,\n do stuff, clean
|
---|
149 | # stuff.' there are several of these in the perl distribution
|
---|
150 |
|
---|
151 | ($module =~ m/[,>]$/) && next;
|
---|
152 |
|
---|
153 | # if the module name starts in a dot it is not a module name.
|
---|
154 | # Is this necessary? Please give me an example if you turn this
|
---|
155 | # back on.
|
---|
156 |
|
---|
157 | # ($module =~ m/^\./) && next;
|
---|
158 |
|
---|
159 | # if the module ends with .pm strip it to leave only basename.
|
---|
160 | # starts with /, which means its an absolute path to a file
|
---|
161 | if ($module =~ m(^/)) {
|
---|
162 | print "$module\n";
|
---|
163 | next;
|
---|
164 | }
|
---|
165 |
|
---|
166 | # as seen in some perl scripts
|
---|
167 | # use base qw(App::CLI Class::Accessor::Chained::Fast App::CLI::Command);
|
---|
168 | if ($module eq 'base') {
|
---|
169 | $require{$module} = $version;
|
---|
170 | $line{$module} = $current_line;
|
---|
171 | ($module = $_) =~ s/use\s*base\s*//;
|
---|
172 | $module =~ s/qw\((.*)\)\s*;/$1/;
|
---|
173 | $module =~ s/qw(.)(.*)\1\s*;/$2/;
|
---|
174 | $module =~ s/\s*;$//;
|
---|
175 | $module =~ s/#.*//;
|
---|
176 | $usebase = 1;
|
---|
177 | }
|
---|
178 | # sometimes people do use POSIX qw(foo), or use POSIX(qw(foo)) etc
|
---|
179 | # we can strip qw.*$, as well as (.*$:
|
---|
180 | $module =~ s/qw.*$//;
|
---|
181 | $module =~ s/\(.*$//;
|
---|
182 |
|
---|
183 | $module =~ s/\.pm$//;
|
---|
184 |
|
---|
185 | # some perl programmers write 'require URI/URL;' when
|
---|
186 | # they mean 'require URI::URL;'
|
---|
187 |
|
---|
188 | $module =~ s/\//::/;
|
---|
189 |
|
---|
190 | # trim off trailing parenthesis if any. Sometimes people pass
|
---|
191 | # the module an empty list.
|
---|
192 |
|
---|
193 | $module =~ s/\(\s*\)$//;
|
---|
194 |
|
---|
195 | # if module is a number then both require and use interpret that
|
---|
196 | # to mean that a particular version of perl is specified. Don't
|
---|
197 | # add a dependency, though, since the rpm will already require
|
---|
198 | # perl-base at the build version (via find-requires)
|
---|
199 | next if $module =~ /^v?\d/;
|
---|
200 |
|
---|
201 | # ph files do not use the package name inside the file.
|
---|
202 | # perlmodlib documentation says:
|
---|
203 | # the .ph files made by h2ph will probably end up as
|
---|
204 | # extension modules made by h2xs.
|
---|
205 | # so do not spend much effort on these.
|
---|
206 |
|
---|
207 | # there is no easy way to find out if a file named systeminfo.ph
|
---|
208 | # will be included with the name sys/systeminfo.ph so only use the
|
---|
209 | # basename of *.ph files
|
---|
210 |
|
---|
211 | ($module =~ m/\.ph$/) && next;
|
---|
212 |
|
---|
213 | # if the module was loaded trough base, we need to split the list
|
---|
214 | if ($usebase) {
|
---|
215 | my $current_line = $_;
|
---|
216 | foreach (split(/\s+/, $module)) {
|
---|
217 | next unless $_;
|
---|
218 | $require{$_} = $version;
|
---|
219 | $line{$_} = $current_line;
|
---|
220 | }
|
---|
221 | } else {
|
---|
222 | $require{$module}=$version;
|
---|
223 | $line{$module}=$current_line;
|
---|
224 | }
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | close(FILE) ||
|
---|
229 | die("$0: Could not close file: '$file' : $!\n");
|
---|
230 | }
|
---|
231 |
|
---|
232 | return(\%require);
|
---|
233 | }
|
---|