File Coverage

blib/lib/Archive/TAP/Convert.pm
Criterion Covered Total %
statement 39 41 95.1
branch 7 12 58.3
condition 2 3 66.6
subroutine 9 9 100.0
pod 1 1 100.0
total 58 66 87.8


line stmt bran cond sub pod time code
1             # ABSTRACT: Read from a TAP archive and convert it for displaying
2              
3             package Archive::TAP::Convert;
4             $Archive::TAP::Convert::VERSION = '0.007'; # TRIAL
5 3     3   31810 use strict;
  3         7  
  3         114  
6 3     3   12 use warnings;
  3         3  
  3         84  
7              
8 3     3   1527 use Capture::Tiny qw( capture_merged );
  3         70309  
  3         201  
9 3     3   1666 use TAP::Harness;
  3         13919  
  3         80  
10 3     3   1451 use TAP::Harness::Archive;
  3         399151  
  3         1118  
11              
12             require Exporter;
13             our @ISA = qw(Exporter);
14             our @EXPORT = qw(convert_from_taparchive);
15              
16             # one and only subroutine of this module
17             sub convert_from_taparchive {
18              
19 2     2 1 19147 my %args = @_;
20              
21             # Input Arguments: archive, formatter, force_inline
22             # Set default values:
23 2 50       8 die 'no archive specified'
24             unless (exists $args{archive});
25              
26 2         4 my $formatter;
27              
28 2 100 66     23 if ( exists $args{formatter} && ref ( $args{formatter} ) =~ /^TAP::Formatter::/ ) {
29 1         2 $formatter = $args{formatter};
30             }
31             else {
32 1 50       6 $args{formatter} = 'TAP::Formatter::HTML'
33             unless (exists $args{formatter});
34 1 50       6 $args{force_inline} = 0
35             unless (exists $args{force_inline});
36              
37             # This is the complicate but flexible version to:
38             # use TAP::Formatter::HTML;
39             # my $formatter = TAP::Formatter::HTML->new;
40 1         8 (my $require_name = $args{formatter} . ".pm") =~ s{::}{/}g;
41 1         2 eval {
42 1         600 require $require_name;
43 1         38432 $formatter = $args{formatter}->new();
44             };
45 1 50       30080 die "Problems with formatter $args{formatter}"
46             . " at $require_name: $@"
47             if $@;
48             }
49              
50             # if set, include all CSS and JS in HTML file
51 2 50       14 if ($args{force_inline}) {
52 0         0 $formatter->force_inline_css(1);
53 0         0 $formatter->force_inline_js (1);
54             }
55              
56             # Now we do a lot of magic to convert this stuff...
57              
58 2         28 my $harness = TAP::Harness->new({ formatter => $formatter });
59              
60 2         391 $formatter->really_quiet(1);
61 2         32 $formatter->prepare;
62              
63 2         45 my $session;
64             my $aggregator = TAP::Harness::Archive->aggregator_from_archive({
65             archive => $args{archive},
66             parser_callbacks => {
67             ALL => sub {
68 6     6   2909 $session->result( $_[0] );
69             },
70             },
71             made_parser_callback => sub {
72 2     2   44235 $session = $formatter->open_test( $_[1], $_[0] );
73             }
74 2         40 });
75              
76 2         2238 $aggregator->start;
77 2         68 $aggregator->stop;
78              
79             # This code also prints to STDOUT but we will catch it!
80 2     2   106 return capture_merged { $formatter->summary($aggregator) };
  2         2153  
81              
82             }
83              
84             1;
85              
86             __END__