DOM/Archive.pm

filter: Statementstmt 96.9% 64 / 66 Branchbran 65.0% 13 / 20 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 88.6% 86 / 97 CC 13 SCAR 19.7
CC
13
Cov
89%
_read_tap_from_archive
10.3
new
4.0
BEGIN
1.0
CRAP 7.2
« DOM.pm ↑ Summary DOM/Entry.pm »
1 package TAP::DOM::Archive;
2 3 our $AUTHORITY = 'cpan:SCHWIGON';
3 # ABSTRACT: Handle TAP:Archive files
4 3 $TAP::DOM::Archive::VERSION = '1.002';
5 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 8 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
10 # hash or hash ref
11 8 my $class = shift;
12  
13 0 ▶ my %args = (@_ == 1) ? %{$_[0]} : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 8 8
14  
15 8 require TAP::DOM;
16  
17 # Drop arguments which don't make sense here and would confuse
18 # TAP::Parser called via TAP::DOM later.
19 8 delete $args{tap};
20 8 delete $args{sources};
21 8 delete $args{exec};
22  
23 8 my %tap_dom_args = ();
24 8 foreach (@TAP::DOM::tap_dom_args) {
25 144 ▶ if (defined $args{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $args{$_}) 5 139 144
26 5 $tap_dom_args{$_} = $args{$_};
27 5 delete $args{$_};
28 }
29 }
30  
31 8 my $tap_documents = _read_tap_from_archive(\%args, \%tap_dom_args);
32  
33 my $tap_dom_list = {
34 meta => $tap_documents->{meta},
35 dom => [
36 31 map { TAP::DOM->new(tap => $_, %tap_dom_args) }
37 31 grep { defined $_ }
38 8 @{$tap_documents->{tap}}
39 ],
40 };
41 8 return bless $tap_dom_list, $class;
42 }
43  
44 sub _read_tap_from_archive
45 8 ▶{
Subroutine _read_tap_from_archive: called CC=10 SCAR=23.3
46 8 my ($args, $tap_dom_args) = @_;
47  
48 8 require Archive::Tar;
49 8 require YAML::Tiny;
50 8 require IO::String;
51 8 require IO::Zlib;
52 8 require Scalar::Util;
53  
54 8 my $content;
55 8 ▶ if ($args->{filecontent}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($args->{'filecontent'}) { } 0 8 8
elsif (-z $args->{'source'} and $tap_dom_args->{'noempty_tap'}) { } 1 7 8
56 0 $content = $args->{filecontent};
57 ▶ } elsif (-z $args->{source} and $tap_dom_args->{noempty_tap}) {
Condition66%2/3
-z $args->{"source"} and $tap_dom_args->{"noempty_tap"}
!ll&&!rl&&r
701
MC/DC50%1/2
-z $args->{"source"} and $tap_dom_args->{"noempty_tap"}
-z $args->{"source"} $tap_dom_args->{"noempty_tap"}
Truth table66%2/3
A and B
A= -z $args->{"source"}B= $tap_dom_args->{"noempty_tap"}
ABresult
0X0
100
111
58 return ({
59 1 meta => {
60 file_order => [ 't/error-tap-archive-was-empty.t' ],
61 file_attributes => [{
62 start_time => '1.0',
63 end_time => '2.0',
64 description => 't/error-tap-archive-was-empty.t'
65 }],
66 'start_time' => '1',
67 'stop_time' => '2',
68 },
69 tap => [ $TAP::DOM::noempty_tap ],
70 });
71 } else {
72 7 $content = do {
73 7 local $/;
74 7 my $F = Scalar::Util::openhandle($args->{source});
75 7 ▶ if (!defined $F) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $F) 3 4 7
76 3 ▶ open $F, '<', $args->{source} or die 'Can not read '.$args->{source};
Branch: 1 branch
BranchTrueFalseTotal
open $F, "<", $args->{"source"} or die 'Can not read ' . $args->{"source"} 3 0 3
77 }
78 <$F>
79 7 };
80 }
81  
82 # some stacking to enable Archive::Tar read compressed in-memory string
83 7 my $TARSTR = IO::String->new($content);
84 7 my $TARZ = IO::Zlib->new($TARSTR, "rb");
85 7 my $tar = Archive::Tar->new($TARZ);
86  
87 7 my ($meta_yml) = grep { $tar->contains_file($_) } qw{meta.yml ./meta.yml};
88 7 my $meta = YAML::Tiny::Load($tar->get_content($meta_yml));
89  
90 my @tap_sections = map {
91 # try different variants of filenames that meta.yml gave us
92 30 my $f1 = $_; # original name as-is
93 30 my $f2 = $_; $f2 =~ s,^\./,,; # force no-leading-dot
94 30 my $f3 = $_; $f3 = "./$_"; # force leading-dot
95 30 local $Archive::Tar::WARN = 0;
96  
97 30 my $tap;
98 30 ▶ $tap = "# Bummer! No tar." unless defined $tar; # no error balloon hint
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tar 0 30 30
99 30 ▶ $tap = $tar->get_content($f1) unless defined $tap;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tap 30 0 30
100 30 ▶ $tap = $tar->get_content($f2) unless defined $tap;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tap 0 30 30
101 30 ▶ $tap = $tar->get_content($f3) unless defined $tap;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $tap 0 30 30
102 30 $tap;
103 7 } @{$meta->{file_order}};
104 return {
105 7 meta => $meta,
106 tap => \@tap_sections,
107 };
108 }
109  
110 3 1; # End of TAP::DOM::Archive
111  
112 __END__
« DOM.pm ↑ Summary DOM/Entry.pm »