summaryrefslogtreecommitdiff
path: root/utils/devel/find-use
blob: fa2014f02a42ae633469303251dd3a6127b25703 (plain)
  1. #!/usr/bin/perl -w
  2. =head1 NAME
  3. find-use
  4. =head1 EXAMPLE
  5. ~/ledgersmb # utils/devel/find-use
  6. 0.000000 : HTML::Entities
  7. 0.000000 : Locale::Maketext::Lexicon
  8. 0.000000 : Module::Build
  9. ...
  10. =head1 EXPLINATION
  11. 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
  12. 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
  13. module is not in core perl, and needs to be installed before LedgerSMB will operate.
  14. =head1 AUTHOR
  15. http://www.ledgersmb.org/ - The LedgerSMB team
  16. =head1 LICENSE
  17. Distributed under the terms of the LedgerSMB code.
  18. =cut
  19. use strict;
  20. use warnings;
  21. open GREP, "grep -r '^use ' . |";
  22. use Module::CoreList;
  23. my %uselines;
  24. while(<GREP>) {
  25. next if /LedgerSMB::/;
  26. next if /use warnings/;
  27. next if /use strict/;
  28. next if /use vars/;
  29. chomp;
  30. my ($file, $useline) = m/^([^:]+):use\s(.*?)$/;
  31. $uselines{$useline}||=[];
  32. push @{$uselines{$useline}}, $file;
  33. }
  34. my %modules;
  35. foreach my $useline (keys %uselines) {
  36. my ($module) = grep { $_ } $useline =~ /(?:base ['"]([a-z:]+)|([a-z:]+)(?:\s|;))/i;
  37. my $version = Module::CoreList->first_release($module);
  38. $modules{$module} = $version||0;
  39. }
  40. foreach my $mod (sort { $modules{$a} == 0 ? -1 : $modules{$b} == 0 ? 1 : 0 or $a cmp $b } keys %modules) {
  41. printf "%2.6f : %s\n", $modules{$mod}, $mod;
  42. }