File Coverage

blib/lib/TAP/Parser/Metrics.pm
Criterion Covered Total %
statement 43 45 95.5
branch 14 18 77.7
condition 2 5 40.0
subroutine 6 6 100.0
pod 2 3 66.6
total 67 77 87.0


line stmt bran cond sub pod time code
1             package TAP::Parser::Metrics;
2 1     1   891 use parent qw/TAP::Parser/;
  1         3  
  1         10  
3              
4 1     1   33585 use strict;
  1         3  
  1         16  
5 1     1   4 use warnings;
  1         1  
  1         471  
6              
7             our $VERSION='0.0.2';
8              
9             my $METRICS='__METRICS__'.int(1e6+rand(9e6));
10              
11             sub configure {
12 10     10 0 86 my ($self,%opt)=@_;
13 10 50       82 if($opt{callback}) { $$self{callback}=$opt{callback} }
  10         34  
14 10         33 return $self;
15             }
16              
17             sub new {
18 10     10 1 2117 my ($ref,$argref)=@_;
19 10   33     93 my $class=ref($ref)||$ref;
20 10         102 my $self=$class->SUPER::new($argref);
21 10         746920 $$self{$METRICS}={path=>[],log=>[],source=>$$argref{source}};
22 10         194 return $self;
23             }
24              
25             sub next {
26 88     88 1 31580 my ($self,@args)=@_;
27 88         376 my $next=$self->SUPER::next(@args);
28 88 100       8118495 if(!$next) {
29 10 50       49 if($$self{callback}) { &{$$self{callback}}(@{$$self{$METRICS}{log}}) }
  10         29  
  10         94  
  10         51  
30 10         56 return $next;
31             }
32 78         239 my $metrics=$$self{$METRICS};
33 78 50       246 if(my $raw=$next->raw()) {
34 78 100       1923 if($raw=~/^(?\s*)# Subtest:\s+(?.*)$/) {
    100          
35 18         2574 my $indent=length($+{indent})/4;
36 18 50       102 if($#{$$metrics{path}}>$indent) { splice(@{$$metrics{path}},$indent) }
  18         98  
  0         0  
  0         0  
37 18         42 push @{$$metrics{path}},$+{name};
  18         212  
38             }
39             elsif($raw=~/^(?\s*)(?not )?ok\s+\d+\s+-\s*(?
40 32         416 my $indent=length($+{indent})/4;
41 32 100       90 if($#{$$metrics{path}}>=$indent) { splice(@{$$metrics{path}},$indent) }
  32         220  
  18         39  
  18         57  
42 32         239 push @{$$metrics{log}},{
43             file=>$$metrics{source},
44             pass=>($+{not}?0:1),
45 32   50     476 path=>[@{$$metrics{path}//[]}],
46             label=>$+{label},
47 32 100       59 };
48             }
49             }
50 78         2714 return $next;
51             }
52              
53             1;
54              
55             __END__