Revision 165fae20
Von Sven Schöling vor fast 14 Jahren hinzugefügt
scripts/find-use.pl | ||
---|---|---|
1 |
#!/usr/bin/perl -w |
|
1 |
#!/usr/bin/perl -l |
|
2 |
use strict; |
|
3 |
#use warnings; # corelist and find throw tons of warnings |
|
4 |
use Module::CoreList; |
|
5 |
use File::Find; |
|
6 |
use SL::InstallationCheck; |
|
7 |
|
|
8 |
my (%uselines, %modules, %supplied); |
|
9 |
|
|
10 |
find(sub { |
|
11 |
return unless /(\.p[lm]|console)$/; |
|
12 |
|
|
13 |
# remember modules shipped with Lx-Office |
|
14 |
$supplied{modulize($File::Find::name)}++ |
|
15 |
if $File::Find::dir =~ m#modules/#; |
|
16 |
|
|
17 |
open my $fh, '<', $_ or warn "can't open $_: $!"; |
|
18 |
while (<$fh>) { |
|
19 |
chomp; |
|
20 |
next if !/^use /; |
|
21 |
next if /SL::/; |
|
22 |
next if /Support::Files/; # our own test support module |
|
23 |
next if /use (warnings|strict|vars|lib|constant|utf8)/; |
|
24 |
|
|
25 |
my ($useline) = m/^use\s+(.*?)$/; |
|
26 |
|
|
27 |
next if $useline =~ /^[\d.]+;/; # skip version requirements |
|
28 |
next if !$useline; |
|
29 |
|
|
30 |
$uselines{$useline}++; |
|
31 |
} |
|
32 |
}, '.'); |
|
33 |
|
|
34 |
for my $useline (keys %uselines) { |
|
35 |
$useline =~ s/#.*//; # kill comments |
|
36 |
|
|
37 |
# modules can be loaded implicit with use base qw(Module) or use parent |
|
38 |
# 'Module'. catch these: |
|
39 |
my ($module, $args) = $useline =~ / |
|
40 |
(?: |
|
41 |
(?:base|parent) |
|
42 |
\s |
|
43 |
(?:'|"|qw.) |
|
44 |
)? # optional parent block |
|
45 |
([\w:]+) # the module |
|
46 |
(.*) # args |
|
47 |
/ix; |
|
48 |
|
|
49 |
# some comments looks very much like use lines |
|
50 |
# try to get rid of them |
|
51 |
next if $useline =~ /^it like a normal Perl node/; # YAML::Dump comment |
|
52 |
next if $useline =~ /^most and offer that in a small/; # YAML |
|
53 |
|
|
54 |
my $version = Module::CoreList->first_release($module); |
|
55 |
$modules{$module} = $supplied{$module} ? 'included' |
|
56 |
: $version ? sprintf '%2.6f', $version |
|
57 |
: is_documented($module) ? 'required' |
|
58 |
: '!missing'; |
|
59 |
} |
|
60 |
|
|
61 |
print sprintf "%8s : %s", $modules{$_}, $_ |
|
62 |
for sort { |
|
63 |
$modules{$a} cmp $modules{$b} |
|
64 |
|| $a cmp $b |
|
65 |
} keys %modules; |
|
66 |
|
|
67 |
sub modulize { |
|
68 |
for (my ($name) = @_) { |
|
69 |
s#^./modules/\w+/##; |
|
70 |
s#.pm$##; |
|
71 |
s#/#::#g; |
|
72 |
return $_; |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
sub is_documented { |
|
77 |
my ($module) = @_; |
|
78 |
return grep { $_->{name} eq $module } @SL::InstallationCheck::required_modules; |
|
79 |
} |
|
80 |
|
|
81 |
__END__ |
|
82 |
|
|
2 | 83 |
=head1 NAME |
3 | 84 |
|
4 | 85 |
find-use |
5 | 86 |
|
6 | 87 |
=head1 EXAMPLE |
7 | 88 |
|
8 |
~/ledgersmb # utils/devel/find-use |
|
9 |
0.000000 : HTML::Entities |
|
10 |
0.000000 : Locale::Maketext::Lexicon |
|
11 |
0.000000 : Module::Build |
|
12 |
... |
|
89 |
# perl scipts/find-use.pl |
|
90 |
missing : Perl::Tags |
|
91 |
missing : Template::Constants |
|
92 |
missing : DBI |
|
13 | 93 |
|
14 |
=head1 EXPLINATION
|
|
94 |
=head1 EXPLANATION
|
|
15 | 95 |
|
16 |
This util is useful for package builders to identify all the CPAN dependencies we've made. It required Module::CoreList (which is core, but is not yet in any stable |
|
17 |
release of perl) to determine if a module is distributed with perl or not. The output reports which version of perl the module is in. If it reports 0.000000, then the |
|
18 |
module is not in core perl, and needs to be installed before Lx-Office will operate. |
|
96 |
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. |
|
19 | 102 |
|
20 | 103 |
=head1 AUTHOR |
21 | 104 |
|
22 | 105 |
http://www.ledgersmb.org/ - The LedgerSMB team |
106 |
Sven Schöling E<lt>s.schoeling@linet-services.deE<gt> |
|
23 | 107 |
|
24 | 108 |
=head1 LICENSE |
25 | 109 |
|
26 | 110 |
Distributed under the terms of the GNU General Public License v2. |
27 |
=cut |
|
28 |
|
|
29 | 111 |
|
30 |
use strict; |
|
31 |
use warnings; |
|
32 |
|
|
33 |
open GREP, "grep -r '^use ' . |"; |
|
34 |
use Module::CoreList; |
|
35 |
|
|
36 |
my %uselines; |
|
37 |
while(<GREP>) { |
|
38 |
next if /SL::/; |
|
39 |
next if /LX::/; |
|
40 |
next if /use warnings/; |
|
41 |
next if /use strict/; |
|
42 |
next if /use vars/; |
|
43 |
chomp; |
|
44 |
my ($file, $useline) = m/^([^:]+):use\s(.*?)$/; |
|
45 |
$uselines{$useline}||=[]; |
|
46 |
push @{$uselines{$useline}}, $file; |
|
47 |
} |
|
48 |
|
|
49 |
my %modules; |
|
50 |
foreach my $useline (keys %uselines) { |
|
51 |
|
|
52 |
my ($module) = grep { $_ } $useline =~ /(?:base ['"]([a-z:]+)|([a-z:]+)(?:\s|;))/i; |
|
53 |
my $version = Module::CoreList->first_release($module); |
|
54 |
$modules{$module} = $version||0; |
|
55 |
} |
|
112 |
=cut |
|
56 | 113 |
|
57 |
foreach my $mod (sort { $modules{$a} == 0 ? -1 : $modules{$b} == 0 ? 1 : 0 or $a cmp $b } keys %modules) { |
|
58 |
printf "%2.6f : %s\n", $modules{$mod}, $mod; |
|
59 |
} |
|
60 | 114 |
|
Auch abrufbar als: Unified diff
find-use erneuert, die alte Version war ledgersmb spezifisch.