WIP: be less chatty
[andk-cpan-tools.git] / bin / add-perl-meta.pl
blob7ad0db620b83c6c2168a1405213fce6ea308baa2
1 #!/usr/local/bin/perl
3 =pod
5 Part of "megainstall"
7 $0 --logs=megainstalldir
9 looks at one dirent that tells us which perl we are talking about
11 Ask that perl for its config and store it as perl-V.txt
13 =cut
16 use strict;
17 use warnings;
19 use FindBin ();
20 use Getopt::Long;
21 use XML::LibXML;
22 our %Opt;
24 sub Usage (){
25 "Usage: $0 [--logs=logsdirector]";
28 GetOptions(\%Opt, "logs=s"
29 ) or die Usage;
31 my $logdir = $Opt{logs} || "$FindBin::Bin/../logs";
32 opendir my $dh, $logdir or die "cannot opendir '$logdir': $!";
34 my $p = XML::LibXML->new;
35 for my $dirent (sort readdir $dh) {
36 next if $dirent =~ /^\./;
37 my $abs = "$logdir/$dirent";
38 next unless $abs =~ /(?:^|\/)megainstall\.(\d+T\d+)\.d(?:\/|$)/;
39 my $time = $1;
40 my $xfile = sprintf "%s/%s", $logdir, $dirent;
41 next unless $xfile =~ /\.xml$/;
42 next unless -e $xfile;
43 my $xml = $p->parse_file($xfile);
44 my($ok,$seq,$perl);
45 $ok = $xml->findvalue("/distro/\@ok");
46 $seq = $xml->findvalue("/distro/\@seq") || 0;
47 $perl = $xml->findvalue("/distro/\@perl");
48 $perl .= "/bin/perl";
49 unless (-e $perl) {
50 die "perl[$perl] n'exists";
52 open my $fh, ">", "$logdir/perl-V.txt" or die "Could not open >$logdir/perl-V.txt: $!";
53 open my $pfh, "-|", $perl, "-V" or die "cannot fork: $!";
54 while (<$pfh>) {
55 print $fh $_;
57 close $pfh or die "perl died during -V";
58 close $fh or die "could not write: $!";
59 last;