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

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

user image
2013-04-24T15:14:32 pq
Code (perl): (dl )
1
2
use ExtUtils::MM_Unix;
my $version = MM->parse_version($file);

Hab das Gefühl, das läuft auf ein ähnliches Problem mit ExtUtils raus.

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
62
63
#!/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} = ($fn =~ tr/://) / 2;
          }
        },
        $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} <=> $found{$b}} keys %found) {
  if ($found{$name}) {  # 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 (defined $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);
#open STDERR,'>',"error.txt"; # hier landen haufenweise Fehlermeldungen, insgesamt 9 KB bei 560 Modulen
foreach my $name (@modules) {
  my $v = MM->parse_version($name);
# eval "use $name";
# my $v = $name->VERSION;
  if (defined $v) {
    $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";


Ausgabe:
Quote
d:\arbeit>perl test_modulinventar.pl
Beginne mit Modulsuche in 'C:/strawberry/perl/lib;C:/strawberry/perl/site/lib;C:\strawberry\perl\vendor\lib;.'
Beginne mit Versionsermittlung fuer 560 Modul(e)
Could not open 'Fcntl': No such file or directory at C:/strawberry/perl/lib/ExtUtils/MM_Unix.pm line 2639.

Läuft obiges Script bei euch auf Linux?
10 print "Hallo"
20 goto 10

View full thread Module inventarisieren ohne ExtUtils::Installed