Thread Module inventarisieren ohne ExtUtils::Installed (26 answers)
Opened by bianca at 2013-04-24 11:25

bianca
 2013-04-24 17:51
#167261 #167261
User since
2009-09-13
6977 Artikel
BenutzerIn

user image
2013-04-24T15:36:21 pq
parse_version() braucht den (vollen) dateinamen, nicht den modulnamen.

Du bist ja schon ein Schatz!

Lösung:

Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl -w
use strict;
use warnings;
use File::Find;
use ExtUtils::MM_Unix;

my $scan = sub {
  my %found;
  for my $dir (@_) {
    if (-d $dir) {
      my $topdir = $dir;
      find(
        sub {
          if (-f $File::Find::name && $File::Find::name =~ /\.pm$/ ) {
            my $fn = $File::Find::name;
            $fn =~ s/\Q$topdir//g;
            $fn =~ s/\//::/g;
            $fn =~ s/^:://g;
            $fn =~ s/\.pm//g;
            $found{$fn}{hirarchie} = ($fn =~ tr/://) / 2;
            $found{$fn}{pfad_name} = $File::Find::name;
          }
        },
        $dir
      );
    }
  }
  %found;
};

print "Beginne mit Modulsuche in '".join(';',@INC)."'\n";
my %found = $scan->(@INC);  # erstmal alle Unterverzeichniss einlesen
my @modules;
foreach my $name (sort {$found{$a}{hirarchie} <=> $found{$b}{hirarchie}} keys %found) {
  if ($found{$name}{hirarchie}) { # untere Hirarchien nicht mehr inventarisieren, z.B. nur Authen::SASL und nicht Authen::SASL::CRAM_MD5
    my @temp = split /::/,$name;
    my $flag = 0;
    for (my $z = 0; $z < scalar @temp - 1; $z ++) {
      if (exists $found{join('::',@temp[0..$z])}) { # z.B. App::Packer::PAR hat nur die dritte Hirarchie
        $flag = 1;
        last;
      }
    }
    push @modules,$name if !$flag;
  }
  else { push @modules,$name; }
}

print "Beginne mit Versionsermittlung fuer ".(scalar @modules)." Modul(e)\n";
my (%ver,@fehler);
foreach my $name (@modules) {
  my $v = MM->parse_version($found{$name}{pfad_name});
  if (defined $v && $v ne 'undef') {
    $ver{$name} = $v
  }
  else { push @fehler,$name; }
}
foreach my $name (sort {lc $a cmp lc $b} keys %ver) { # hier funktioniert das sort{} schon nicht mehr
  print "$name -> $ver{$name}\n";
}
print "\nFehlerhafte (".(scalar @fehler)." Stueck):\n".join("\n",@fehler)."\n";


DANKE DANKE DANKE!!
10 print "Hallo"
20 goto 10

View full thread Module inventarisieren ohne ExtUtils::Installed