| 1 | # ABSTRACT: Look into TAP-Archives | ||||||||||||||
| 2 | |||||||||||||||
| 3 | package Archive::TAP::Peek; | ||||||||||||||
| 4 | { | ||||||||||||||
| 5 | 2 | $Archive::TAP::Peek::VERSION = '0.002'; | |||||||||||||
| 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 Archive::Extract; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 2 | ▶ | use File::Temp qw( tempdir ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | 2 | ▶ | use TAP::Parser; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 14 | |||||||||||||||
| 15 | 2 | ▶ | sub new { | ||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.2
Pod
undocumented
| |||||||||||||||
| 16 | 2 | my $class = shift; | |||||||||||||
| 17 | |||||||||||||||
| 18 | 2 | my %args = @_; | |||||||||||||
| 19 | |||||||||||||||
| 20 | 2 | my $self = { error_found => 0 }; | |||||||||||||
| 21 | |||||||||||||||
| 22 | 2 | ▶ | die "Parameter 'archive' needed" unless exists $args{archive}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 23 | |||||||||||||||
| 24 | 2 | ▶ | die "$args{archive} not found" unless -f $args{archive}; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 25 | |||||||||||||||
| 26 | my $ae = Archive::Extract->new( archive => $args{archive}, | ||||||||||||||
| 27 | 2 | type => 'tgz' | |||||||||||||
| 28 | ); | ||||||||||||||
| 29 | |||||||||||||||
| 30 | 2 | ▶ | die "$args{archive} is not of type 'tgz'" unless $ae->is_tgz; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 31 | |||||||||||||||
| 32 | 2 | my $tmpdir = tempdir( CLEANUP => 1 ); | |||||||||||||
| 33 | |||||||||||||||
| 34 | 2 | ▶ | $ae->extract( to => $tmpdir ) or die $ae->error; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 35 | |||||||||||||||
| 36 | 2 | my $files = $ae->files; | |||||||||||||
| 37 | |||||||||||||||
| 38 | 2 | my $outdir = $ae->extract_path; | |||||||||||||
| 39 | |||||||||||||||
| 40 | 2 | foreach my $f (@{$files}) { | |||||||||||||
| 41 | |||||||||||||||
| 42 | 10 | ▶ | next unless ( $f =~ /.*\.t$/); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 43 | |||||||||||||||
| 44 | # code from here: | ||||||||||||||
| 45 | # http://stackoverflow.com/questions/13781443/capture-and-split-tap-output-result | ||||||||||||||
| 46 | 8 | my $tap_file = $outdir . '/' . $f; | |||||||||||||
| 47 | 8 | ▶ | open my $tap_fh, $tap_file or die $!; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 48 | |||||||||||||||
| 49 | # Can't just pass in the .t file, it will try to execute it. | ||||||||||||||
| 50 | 8 | my $parser = TAP::Parser->new({ | |||||||||||||
| 51 | source => $tap_fh | ||||||||||||||
| 52 | }); | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 8 | ▶ | while ( my $result = $parser->next ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 55 | # do whatever you like with the $result, like print it back out | ||||||||||||||
| 56 | 63 | my $line = $result->as_string; | |||||||||||||
| 57 | |||||||||||||||
| 58 | 63 | ▶ | if ($line =~ /^ok/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 59 | # everything is fine... keep going on | ||||||||||||||
| 60 | } | ||||||||||||||
| 61 | elsif ($line =~ /^not ok/) { | ||||||||||||||
| 62 | # oops! error. | ||||||||||||||
| 63 | 1 | $self->{error_found} = 1; | |||||||||||||
| 64 | |||||||||||||||
| 65 | # we break here... since we already know there are failures | ||||||||||||||
| 66 | 1 | last; | |||||||||||||
| 67 | } | ||||||||||||||
| 68 | else { | ||||||||||||||
| 69 | # some other lines we don't need | ||||||||||||||
| 70 | } | ||||||||||||||
| 71 | } | ||||||||||||||
| 72 | |||||||||||||||
| 73 | } | ||||||||||||||
| 74 | |||||||||||||||
| 75 | 2 | bless ($self, $class); | |||||||||||||
| 76 | |||||||||||||||
| 77 | 2 | return $self; | |||||||||||||
| 78 | } | ||||||||||||||
| 79 | |||||||||||||||
| 80 | 2 | ▶ | sub all_ok { | ||||||||||||
|
Subroutine
all_ok: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||
| 81 | 2 | my $self = shift; | |||||||||||||
| 82 | |||||||||||||||
| 83 | 2 | ▶ | if( $self->{error_found} ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 84 | 1 | return; | |||||||||||||
| 85 | } | ||||||||||||||
| 86 | else { | ||||||||||||||
| 87 | 1 | return 1; | |||||||||||||
| 88 | } | ||||||||||||||
| 89 | } | ||||||||||||||
| 90 | |||||||||||||||
| 91 | 2 | 1; | |||||||||||||
| 92 | |||||||||||||||
| 93 | __END__ | ||||||||||||||