blib/lib/Archive/TAP/Convert.pm

filter: Statementstmt 95.6% 44 / 46 Branchbran 58.3% 7 / 12 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod 100% 1 / 1 totaltotal 87.6% 64 / 73 CC 8 SCAR 15.6
CC
8
Cov
87%
convert_from_taparchive
8.5
BEGIN
1.0
BEGIN
1.0
CRAP 4.7
↑ Summary
1 # ABSTRACT: Read from a TAP archive and convert it for displaying
2  
3 package Archive::TAP::Convert;
4 3 $Archive::TAP::Convert::VERSION = '0.007';
5 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use Capture::Tiny qw( capture_merged );
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use TAP::Harness;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use TAP::Harness::Archive;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 3 require Exporter;
13 3 our @ISA = qw(Exporter);
14 3 our @EXPORT = qw(convert_from_taparchive);
15  
16 # one and only subroutine of this module
17 2 ▶sub convert_from_taparchive {
Subroutine convert_from_taparchive: called CC=8 SCAR=21.4
Pod documented
18  
19 2 my %args = @_;
20  
21 # Input Arguments: archive, formatter, force_inline
22 # Set default values:
23 die 'no archive specified'
24 2 ▶ unless (exists $args{archive});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"archive"} 0 2 2
25  
26 2 my $formatter;
27  
28 2 ▶ if ( exists $args{formatter} && ref ( $args{formatter} ) =~ /^TAP::Formatter::/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $args{'formatter'} and ref($args{'formatter'}) =~ /^TAP::Formatter::/) { } 1 1 2
Condition66%2/3
exists $args{"formatter"} and ref($args{"formatter"}) =~ /^TAP::Formatter::/
!ll&&!rl&&r
011
MC/DC50%1/2
exists $args{"formatter"} and ref($args{"formatter"}) =~ /^TAP::Formatter::/
exists $args{"formatter"} ref($args{"formatter"}) =~ /^TAP::Formatter::/
Truth table66%2/3
A and B
A= exists $args{"formatter"}B= ref($args{"formatter"}) =~ /^TAP::Formatter::/
ABresult
0X0
100
111
29 1 $formatter = $args{formatter};
30 }
31 else {
32 $args{formatter} = 'TAP::Formatter::HTML'
33 1 ▶ unless (exists $args{formatter});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"formatter"} 0 1 1
34 $args{force_inline} = 0
35 1 ▶ unless (exists $args{force_inline});
Branch: 1 branch
BranchTrueFalseTotal
unless exists $args{"force_inline"} 1 0 1
36  
37 # This is the complicate but flexible version to:
38 # use TAP::Formatter::HTML;
39 # my $formatter = TAP::Formatter::HTML->new;
40 1 (my $require_name = $args{formatter} . ".pm") =~ s{::}{/}g;
41 1 eval {
42 1 require $require_name;
43 1 $formatter = $args{formatter}->new();
44 };
45 1 ▶ die "Problems with formatter $args{formatter}"
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 1 1
46 . " at $require_name: $@"
47 if $@;
48 }
49  
50 # if set, include all CSS and JS in HTML file
51 2 ▶ if ($args{force_inline}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"force_inline"}) 0 2 2
52 0 $formatter->force_inline_css(1);
53 0 $formatter->force_inline_js (1);
54 }
55  
56 # Now we do a lot of magic to convert this stuff...
57  
58 2 my $harness = TAP::Harness->new({ formatter => $formatter });
59  
60 2 $formatter->really_quiet(1);
61 2 $formatter->prepare;
62  
63 2 my $session;
64 my $aggregator = TAP::Harness::Archive->aggregator_from_archive({
65 archive => $args{archive},
66 parser_callbacks => {
67 6 ▶ ALL => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 6 $session->result( $_[0] );
69 },
70 },
71 2 ▶ made_parser_callback => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
72 2 $session = $formatter->open_test( $_[1], $_[0] );
73 }
74 2 });
75  
76 2 $aggregator->start;
77 2 $aggregator->stop;
78  
79 # This code also prints to STDOUT but we will catch it!
80 2 ▶ return capture_merged { $formatter->summary($aggregator) };
Subroutine __ANON__: called CC=1 SCAR=0.0
81  
82 }
83  
84 3 1;
85  
86 __END__
↑ Summary