File Coverage

blib/lib/TAP/Parser/Metrics.pm
Criterion Covered Total %
statement 61 69 88.4
branch 24 32 75.0
condition 7 14 50.0
subroutine 7 7 100.0
pod 2 4 50.0
total 101 126 80.1


line stmt bran cond sub pod time code
1             package TAP::Parser::Metrics;
2 1     1   1037 use parent qw/TAP::Parser/;
  1         2  
  1         11  
3              
4 1     1   46684 use strict;
  1         3  
  1         31  
5 1     1   6 use warnings;
  1         2  
  1         1345  
6              
7             our $VERSION='0.0.4';
8              
9             my $METRICS='__METRICS__'.int(1e6+rand(9e6));
10              
11             sub configure {
12 22     22 0 179 my ($self,%opt)=@_;
13 22 50       167 if($opt{callback}) { $$self{callback}=$opt{callback} }
  22         62  
14 22         114 return $self;
15             }
16              
17             sub new {
18 22     22 1 3893 my ($ref,$argref)=@_;
19 22   33     244 my $class=ref($ref)||$ref;
20 22         99 my $self=$class->SUPER::new($argref);
21 22         217851 $$self{$METRICS}={path=>[],log=>[],source=>$$argref{source}};
22 22         519 return $self;
23             }
24              
25             sub log {
26 68     68 0 417 my ($self,$pass,$file,$label,@path)=@_;
27 68         176 push @{$$self{$METRICS}{log}},{
  68         874  
28             file=>$file,
29             pass=>$pass,
30             path=>[@path],
31             label=>$label,
32             };
33             }
34              
35             sub next {
36 180     180 1 12984 my ($self,@args)=@_;
37 180         762 my $next=$self->SUPER::next(@args);
38 180 100       14547984 if(!$next) {
39 22 50       101 if($$self{callback}) { &{$$self{callback}}(@{$$self{$METRICS}{log}}) }
  22         42  
  22         130  
  22         115  
40 22         117 return $next;
41             }
42 158         581 my $metrics=$$self{$METRICS};
43 158 50       525 if(my $raw=$next->raw()) {
44 158 100       2328 if($raw=~/^(?\s*)# Subtest:\s+(?.*)$/) { # subtest begin
    100          
    100          
    100          
45 34         1159 my $indent=length($+{indent})/4;
46 34 50       98 if($#{$$metrics{path}}>$indent) { splice(@{$$metrics{path}},$indent) }
  34         216  
  0         0  
  0         0  
47 34         91 push @{$$metrics{path}},$+{name};
  34         283  
48             }
49             elsif($raw=~/^(?\s*)not ok\s+\d+\s+-\s*No tests run for subtest "(?
50 2         25 my $indent=length($+{indent})/4;
51 2 50       12 if($#{$$metrics{path}}>$indent) { splice(@{$$metrics{path}},$indent) }
  2         18  
  0         0  
  0         0  
52 2   50     240 $self->log(0,$$metrics{source},undef,@{$$metrics{path}//[]});
  2         32  
53 2         5 pop(@{$$metrics{path}});
  2         5  
54             }
55             elsif($raw=~/^(?\s*)(?not )?ok\s+\d+\s+-\s*(?
56 64         799 my $indent=length($+{indent})/4;
57 64 100 66     172 if(($#{$$metrics{path}}>=$indent)&&($$metrics{path}[-1] eq $+{label})) { # subtest result
  64         651  
58 32 100 50     216 $self->log(($+{not}?0:1),$$metrics{source},undef,@{$$metrics{path}//[]});
  32         180  
59 32         82 splice(@{$$metrics{path}},$indent);
  32         91  
60             }
61             else { # assertion result
62 32 50       50 if($#{$$metrics{path}}>=$indent) { splice(@{$$metrics{path}},$indent) }
  32         119  
  0         0  
  0         0  
63 32 100 50     334 $self->log(($+{not}?0:1),$$metrics{source},$+{label},@{$$metrics{path}//[]});
  32         221  
64             }
65             }
66             elsif($raw=~/^(?\s*)(?not )?ok\s+\d+$/) { # unlabeled assertion
67 2         30 my $indent=length($+{indent})/4;
68 2 50       11 if($#{$$metrics{path}}>=$indent) { splice(@{$$metrics{path}},$indent) }
  2         36  
  0         0  
  0         0  
69 2 50 50     28 $self->log(($+{not}?0:1),$$metrics{source},'',@{$$metrics{path}//[]});
  2         32  
70             }
71             }
72 158         743 return $next;
73             }
74              
75             1;
76              
77             __END__