PerlBench/Results.pm untested

filter: Statementstmt 0.0% 0 / 89 Branchbran 0.0% 0 / 30 Conditioncond 0.0% 0 / 13 MC/DCmcdc 0.0% 0 / 7 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 153 CC 16 SCAR 42.0
CC
16
Cov
0%
_scan
132.0
perls
12.0
new
6.0
CRAP 66.5
1 package PerlBench::Results;
2  
3 use strict;
4 use File::Find ();
5  
6 sub new {
7 my $class = shift;
8 my $resdir = shift || "perlbench-results";
9 return undef unless -d $resdir;
10 my $self = bless {}, $class;
11 $self->_scan($resdir);
12 return $self;
13 }
14  
15 sub _scan {
16 my($self, $dir) = @_;
17 $self->{dir} = $dir;
18  
19 # locate result files
20 my @res;
21 File::Find::find(sub {
22 if (/\.pb$/) {
23 my $f = $File::Find::name;
24 $f = substr($f, length($dir) + 1);
25 $f =~ s,\\,/,g if $^O eq "MSWin32";
26 push(@res, $f);
27 }
28 }, $dir);
29  
30 # read results
31 for my $f (@res) {
32 #print "$f\n";
33 my($hostname, $perls, $perl, $tests) = split("/", $f);
34 die unless $perls eq "perls";
35 die unless $tests eq "tests";
36 my $res = _read_pb_file("$dir/$f");
37 push(@{$self->{h}{$hostname}{p}{$perl}{t}}, $res);
38 }
39  
40 # fill in additional information about hosts and perls
41 while(my($hostname, $hosthash) = each %{$self->{h} || {}}) {
42 #print "host $hostname\n";
43 while (my($perl, $perlhash) = each %{$hosthash->{p}}) {
44 #print " perl $perl\n";
45 my $perldir = "$dir/$hostname/perls/$perl";
46 my $version_txt = "$perldir/version.txt";
47 open(my $fh, "<", $version_txt) || die "Can't open $version_txt: $!";
48 local($_);
49 while (<$fh>) {
50 if (/^This is perl, v(\S+)/) {
51 $perlhash->{version} = $1;
52 $perlhash->{name} = "perl-$1";
53 }
54 if (/^Binary build (\d+.*) provided by ActiveState/) {
55 $perlhash->{name} .= " build $1";
56 $perlhash->{name} =~ s/^perl/ActivePerl/;
57 }
58 }
59 die "Can't determine perl version from $version_txt" unless $perlhash->{version};
60 close($fh);
61  
62 if (open(my $fh, "<", "$perldir/config-summary.txt")) {
63 while (<$fh>) {
64 if (/^Summary of/ && / patch\s+(\d+)/) {
65 $perlhash->{version} .= "-p$1";
66 $perlhash->{name} .= " patch $1";
67 }
68 elsif (/\bDEBUGGING\b/) {
69 $perlhash->{name} .= " (DEBUGGING)";
70 }
71 }
72 close($fh);
73 }
74  
75 $perlhash->{dir} = $perldir;
76 $perlhash->{host} = $hostname;
77 }
78 }
79 }
80  
81 sub _read_pb_file {
82 my $file = shift;
83 open(my $fh, "<", $file) || die "Can't open '$file': $!";
84 my %hash;
85 local($_);
86 while (<$fh>) {
87 if (/^(\w[\w-]*)\s*:\s*(.*)/) {
88 my($k, $v) = ($1, $2);
89 $k = lc($k);
90 $k =~ s/-/_/g;
91 $hash{$k} = $v;
92 }
93 else {
94 warn "$file: $_";
95 }
96 }
97 close($fh);
98 #$hash{file} = $file;
99 return \%hash;
100 }
101  
102 sub hosts {
103 my $self = shift;
104 die unless wantarray;
105 return sort keys %{$self->{h} || {}};
106 }
107  
108 sub perls {
109 my($self, @hosts) = @_;
110 die unless wantarray;
111 @hosts = $self->hosts unless @hosts;
112 my @p;
113 for my $h (@hosts) {
114 push(@p, values %{$self->{h}{$h}{p}});
115 }
116 @p = sort { _vers_cmp($a->{version}, $b->{version}) } @p;
117 return @p;
118 }
119  
120 sub _vers_cmp {
121 my($v1, $v2) = @_;
122 return $v1 cmp $v2;
123 }
124  
125 1;