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