]> wagnertech.de Git - kivitendo-erp.git/commitdiff
Merge branch 'master' of git@lx-office.linet-services.de:lx-office-erp
authorSven Schöling <s.schoeling@linet-services.de>
Wed, 9 Feb 2011 14:16:17 +0000 (15:16 +0100)
committerSven Schöling <s.schoeling@linet-services.de>
Wed, 9 Feb 2011 14:16:17 +0000 (15:16 +0100)
1  2 
scripts/find-use.pl

diff --combined scripts/find-use.pl
index 778f11ba83dad5160954d740c3c051755cacfdf7,97f5ad2d08ef6f2e495e3fa658d8f701766308e3..778f11ba83dad5160954d740c3c051755cacfdf7
mode 100644,100755..100755
@@@ -1,37 -1,11 +1,37 @@@
  #!/usr/bin/perl -l
  use strict;
  #use warnings; # corelist and find throw tons of warnings
 -use Module::CoreList;
  use File::Find;
 +use Module::CoreList;
  use SL::InstallationCheck;
 -
 -my (%uselines, %modules, %supplied);
 +use Term::ANSIColor;
 +
 +my (%uselines, %modules, %supplied, %requires);
 +
 +# since the information which classes belong to a cpan distribution is not
 +# easily obtained, I'll just hard code the bigger ones we use here. the same
 +# hash will be filled later with information gathered from the source files.
 +%requires = (
 +  'DateTime' => {
 +    'DateTime::Duration'                 => 1,
 +    'DateTime::Infinite'                 => 1,
 +  },
 +  'Rose::DB::Object' => {
 +   'Rose::DB::Object::ConventionManager' => 1,
 +   'Rose::DB::Object::Manager'           => 1,
 +   'Rose::DB::Object::Metadata'          => 1,
 +  },
 +  'Rose::Object' => {
 +    'Rose::Object::MakeMethods::Generic' => 1,
 +  },
 +  'Template' => {
 +    'Template::Constants'                => 1,
 +    'Template::Exception'                => 1,
 +    'Template::Iterator'                 => 1,
 +    'Template::Plugin'                   => 1,
 +    'Template::Plugin::Filter'           => 1,
 +  },
 +);
  
  find(sub {
    return unless /(\.p[lm]|console)$/;
  
      my ($useline) = m/^use\s+(.*?)$/;
  
 -    next if  $useline =~ /^[\d.]+;/; # skip version requirements
 +    next if  $useline =~ /^[\d._]+;/; # skip version requirements
      next if !$useline;
  
 -    $uselines{$useline}++;
 +    $uselines{$useline} ||= [];
 +    push @{ $uselines{$useline} }, $File::Find::name;
    }
  }, '.');
  
  for my $useline (keys %uselines) {
    $useline =~ s/#.*//; # kill comments
  
 -  # modules can be loaded implicit with use base qw(Module) or use parent
 +  # modules can be loaded implicitly with use base qw(Module) or use parent
    # 'Module'. catch these:
    my ($module, $args) = $useline =~ /
      (?:
                      : $version               ? sprintf '%2.6f', $version
                      : is_documented($module) ? 'required'
                      : '!missing';
 +
 +  # build requirement tree
 +  for my $file (@{ $uselines{$useline} }) {
 +    next if $file =~ /\.pl$/;
 +    my $orig_module = modulize($file);
 +    $requires{$orig_module} ||= {};
 +    $requires{$orig_module}{$module}++;
 +  }
 +}
 +
 +# build transitive closure for documented dependancies
 +my $changed = 1;
 +while ($changed) {
 +  $changed = 0;
 +  for my $src_module (keys %requires) {
 +    for my $dst_module (keys %{ $requires{$src_module} }) {
 +      if (   $modules{$src_module} =~ /^required/
 +          && $modules{$dst_module} eq '!missing') {
 +        $modules{$dst_module} = "required"; # . ", via $src_module";
 +        $changed = 1;
 +      }
 +    }
 +  }
  }
  
 -print sprintf "%8s : %s", $modules{$_}, $_
 +print sprintf "%8s : %s", color_text($modules{$_}), $_
    for sort {
         $modules{$a} cmp $modules{$b}
      ||          $a  cmp $b
  sub modulize {
    for (my ($name) = @_) {
      s#^./modules/\w+/##;
 +    s#^./##;
      s#.pm$##;
      s#/#::#g;
      return $_;
  
  sub is_documented {
    my ($module) = @_;
 -  return grep { $_->{name} eq $module } @SL::InstallationCheck::required_modules;
 +  grep { $_->{name} eq $module } @SL::InstallationCheck::required_modules;
 +}
 +
 +sub color_text {
 +  my ($text) = @_;
 +  return color(get_color($text)) . $text . color('reset');
  }
  
 +sub get_color {
 +  for (@_) {
 +    return 'yellow' if /^5./ && $_ > 5.008;
 +    return 'green'  if /^5./;
 +    return 'green'  if /^included/;
 +    return 'red'    if /^!missing/;
 +    return 'yellow';
 +  }
 +}
 +
 +1;
 +
  __END__
  
  =head1 NAME
@@@ -155,39 -87,18 +155,39 @@@ find-us
  =head1 EXAMPLE
  
   # perl scipts/find-use.pl
 - missing : Perl::Tags
 - missing : Template::Constants
 - missing : DBI
 + !missing : Perl::Tags
 + !missing : Template::Constants
 + !missing : DBI
  
  =head1 EXPLANATION
  
  This util is useful for package builders to identify all the CPAN dependencies
 -we've made. It requires Module::CoreList (which is core, but is not in most
 -stable releases 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 module is not in core perl, and needs to be installed before
 -Lx-Office will operate.
 +we have. It requires Module::CoreList (which is core since 5.9) to determine if
 +a module is distributed with perl or not.  The output will be one of the
 +following:
 +
 +=over 4
 +
 +=item VERSION
 +
 +If a version string is displayed, the module is core since this version.
 +Everything up to 5.8 is alright. 5.10 (aka 5.010) is acceptable, but should be
 +documented. Please do not use 5.12 core modules without adding an explicit
 +requirement.
 +
 +=item included
 +
 +This module is included in C<modules/*>. Don't worry about it.
 +
 +=item required
 +
 +This module is documented in C<SL:InstallationCheck> to be necessary, or is a
 +dependancy of one of these. Everything alright.
 +
 += item !missing
 +
 +These modules are neither core, nor included, nor required. This is ok for
 +developer tools, but should never occur for modules the actual program uses.
  
  =head1 AUTHOR