Revision e92ff87c
Von Sven Schöling vor fast 14 Jahren hinzugefügt
scripts/find-use.pl | ||
---|---|---|
1 | 1 |
#!/usr/bin/perl -l |
2 | 2 |
use strict; |
3 | 3 |
#use warnings; # corelist and find throw tons of warnings |
4 |
use Module::CoreList; |
|
5 | 4 |
use File::Find; |
5 |
use Module::CoreList; |
|
6 | 6 |
use SL::InstallationCheck; |
7 |
|
|
8 |
my (%uselines, %modules, %supplied); |
|
7 |
use Term::ANSIColor; |
|
8 |
|
|
9 |
my (%uselines, %modules, %supplied, %requires); |
|
10 |
|
|
11 |
# since the information which classes belong to a cpan distribution is not |
|
12 |
# easily obtained, I'll just hard code the bigger ones we use here. the same |
|
13 |
# hash will be filled later with information gathered from the source files. |
|
14 |
%requires = ( |
|
15 |
'Rose::DB::Object' => { |
|
16 |
'Rose::DB::Object::ConventionManager' => 1, |
|
17 |
'Rose::DB::Object::Manager' => 1, |
|
18 |
'Rose::DB::Object::Metadata' => 1, |
|
19 |
}, |
|
20 |
'Rose::Object' => { |
|
21 |
'Rose::Object::MakeMethods::Generic' => 1, |
|
22 |
}, |
|
23 |
'Template' => { |
|
24 |
'Template::Constants' => 1, |
|
25 |
'Template::Exception' => 1, |
|
26 |
'Template::Iterator' => 1, |
|
27 |
'Template::Plugin' => 1, |
|
28 |
'Template::Plugin::Filter' => 1, |
|
29 |
}, |
|
30 |
); |
|
9 | 31 |
|
10 | 32 |
find(sub { |
11 | 33 |
return unless /(\.p[lm]|console)$/; |
... | ... | |
27 | 49 |
next if $useline =~ /^[\d.]+;/; # skip version requirements |
28 | 50 |
next if !$useline; |
29 | 51 |
|
30 |
$uselines{$useline}++; |
|
52 |
$uselines{$useline} ||= []; |
|
53 |
push @{ $uselines{$useline} }, $File::Find::name; |
|
31 | 54 |
} |
32 | 55 |
}, '.'); |
33 | 56 |
|
34 | 57 |
for my $useline (keys %uselines) { |
35 | 58 |
$useline =~ s/#.*//; # kill comments |
36 | 59 |
|
37 |
# modules can be loaded implicit with use base qw(Module) or use parent |
|
60 |
# modules can be loaded implicitly with use base qw(Module) or use parent
|
|
38 | 61 |
# 'Module'. catch these: |
39 | 62 |
my ($module, $args) = $useline =~ / |
40 | 63 |
(?: |
... | ... | |
56 | 79 |
: $version ? sprintf '%2.6f', $version |
57 | 80 |
: is_documented($module) ? 'required' |
58 | 81 |
: '!missing'; |
82 |
|
|
83 |
# build requirement tree |
|
84 |
for my $file (@{ $uselines{$useline} }) { |
|
85 |
next if $file =~ /\.pl$/; |
|
86 |
my $orig_module = modulize($file); |
|
87 |
$requires{$orig_module} ||= {}; |
|
88 |
$requires{$orig_module}{$module}++; |
|
89 |
} |
|
90 |
} |
|
91 |
|
|
92 |
# build transitive closure for documented dependancies |
|
93 |
my $changed = 1; |
|
94 |
while ($changed) { |
|
95 |
$changed = 0; |
|
96 |
for my $src_module (keys %requires) { |
|
97 |
for my $dst_module (keys %{ $requires{$src_module} }) { |
|
98 |
if ( $modules{$src_module} =~ /^required/ |
|
99 |
&& $modules{$dst_module} eq '!missing') { |
|
100 |
$modules{$dst_module} = "required"; # . ", via $src_module"; |
|
101 |
$changed = 1; |
|
102 |
} |
|
103 |
} |
|
104 |
} |
|
59 | 105 |
} |
60 | 106 |
|
61 |
print sprintf "%8s : %s", $modules{$_}, $_
|
|
107 |
print sprintf "%8s : %s", color_text($modules{$_}), $_
|
|
62 | 108 |
for sort { |
63 | 109 |
$modules{$a} cmp $modules{$b} |
64 | 110 |
|| $a cmp $b |
... | ... | |
67 | 113 |
sub modulize { |
68 | 114 |
for (my ($name) = @_) { |
69 | 115 |
s#^./modules/\w+/##; |
116 |
s#^./##; |
|
70 | 117 |
s#.pm$##; |
71 | 118 |
s#/#::#g; |
72 | 119 |
return $_; |
... | ... | |
75 | 122 |
|
76 | 123 |
sub is_documented { |
77 | 124 |
my ($module) = @_; |
78 |
return grep { $_->{name} eq $module } @SL::InstallationCheck::required_modules; |
|
125 |
grep { $_->{name} eq $module } @SL::InstallationCheck::required_modules; |
|
126 |
} |
|
127 |
|
|
128 |
sub color_text { |
|
129 |
my ($text) = @_; |
|
130 |
return color(get_color($text)) . $text . color('reset'); |
|
79 | 131 |
} |
80 | 132 |
|
133 |
sub get_color { |
|
134 |
for (@_) { |
|
135 |
return 'yellow' if /^5./ && $_ > 5.008; |
|
136 |
return 'green' if /^5./; |
|
137 |
return 'green' if /^included/; |
|
138 |
return 'red' if /^!missing/; |
|
139 |
return 'yellow'; |
|
140 |
} |
|
141 |
} |
|
142 |
|
|
143 |
1; |
|
144 |
|
|
81 | 145 |
__END__ |
82 | 146 |
|
83 | 147 |
=head1 NAME |
... | ... | |
87 | 151 |
=head1 EXAMPLE |
88 | 152 |
|
89 | 153 |
# perl scipts/find-use.pl |
90 |
missing : Perl::Tags |
|
91 |
missing : Template::Constants |
|
92 |
missing : DBI |
|
154 |
!missing : Perl::Tags
|
|
155 |
!missing : Template::Constants
|
|
156 |
!missing : DBI
|
|
93 | 157 |
|
94 | 158 |
=head1 EXPLANATION |
95 | 159 |
|
96 | 160 |
This util is useful for package builders to identify all the CPAN dependencies |
97 |
we've made. It requires Module::CoreList (which is core, but is not in most |
|
98 |
stable releases of perl) to determine if a module is distributed with perl or |
|
99 |
not. The output reports which version of perl the module is in. If it reports |
|
100 |
0.000000, then the module is not in core perl, and needs to be installed before |
|
101 |
Lx-Office will operate. |
|
161 |
we have. It requires Module::CoreList (which is core since 5.9) to determine if |
|
162 |
a module is distributed with perl or not. The output will be one of the |
|
163 |
following: |
|
164 |
|
|
165 |
=over 4 |
|
166 |
|
|
167 |
=item VERSION |
|
168 |
|
|
169 |
If a version string is displayed, the module is core since this version. |
|
170 |
Everything up to 5.8 is alright. 5.10 (aka 5.010) is acceptable, but should be |
|
171 |
documented. Please do not use 5.12 core modules without adding an explicit |
|
172 |
requirement. |
|
173 |
|
|
174 |
=item included |
|
175 |
|
|
176 |
This module is included in C<modules/*>. Don't worry about it. |
|
177 |
|
|
178 |
=item required |
|
179 |
|
|
180 |
This module is documented in C<SL:InstallationCheck> to be necessary, or is a |
|
181 |
dependancy of one of these. Everything alright. |
|
182 |
|
|
183 |
= item !missing |
|
184 |
|
|
185 |
These modules are neither core, nor included, nor required. This is ok for |
|
186 |
developer tools, but should never occur for modules the actual program uses. |
|
102 | 187 |
|
103 | 188 |
=head1 AUTHOR |
104 | 189 |
|
Auch abrufbar als: Unified diff
find-use, erweiterung.
- transitive Hülle von Abhängigkeiten berücksichtigen
- Ausgabe mit Term::ANSIColor eingefärbt zum besseren Verständnis