blib/lib/Filter/Dockerfile.pm

filter: Statementstmt 33.3% 25 / 75 Branchbran 10.0% 3 / 30 Conditioncond 0.0% 0 / 8 MC/DCmcdc 0.0% 0 / 5 Subroutinesub 87.5% 7 / 8 Podpod 0.0% 0 / 2 totaltotal 27.3% 35 / 128 CC 23 SCAR 46.3
CC
23
Cov
25%
merge
156.0
filter
99.2
BEGIN
1.0
CRAP 102.3
↑ Summary
1 package Filter::Dockerfile;
2 1 ▶use Filter::Util::Call;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use version;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 our $VERSION = version->declare("0.0.2");
8  
9 1 ▶sub import {
Subroutine import: called CC=1 SCAR=0.0
10 1 my ($type) = @_;
11 1 my ($ref) = {
12 ua => LWP::UserAgent->new()
13 };
14 1 filter_add(bless $ref);
15 }
16  
17 3 ▶sub filter {
Subroutine filter: called CC=12 SCAR=46.0
Pod undocumented
18 3 my ($self) = @_;
19 3 ▶ filter_read() || return 0;
Branch: 1 branch
BranchTrueFalseTotal
&filter_read() or return 0 2 1 3
20 2 ▶ if ( /^INCLUDE/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^INCLUDE/) { } 0 2 2
21 0 ▶ while( substr($_,-2) eq "\\\n" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (substr($_, -2) eq "\\\n") 0 0 0
22 0 $_ = substr($_,0,-2);
23 0 ▶ filter_read() || return 0;
Branch: 1 branch
BranchTrueFalseTotal
&filter_read() or return 0 0 0 0
24 }
25 0 my @args = split(/\s+/, $_);
26 0 shift @args;
27 0 my $merge = 0;
28 0 my $exclude = {};
29 0 my $include = {};
30 0 ▶ if ( $args[0] eq 'MERGE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] eq "MERGE") 0 0 0
31 0 $merge++;
32 0 shift @args;
33 }
34 0 my @uris = ();
35 0 for my $arg ( @args ) {
36 0 ▶ if ( $arg =~ /^(-)?(ADD|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|INCLUDE|LABEL|MAINTAINER|ONBUILD|RUN|USER|VOLUME|WORKDIR)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^(-)?(ADD|CMD|COPY|ENTRYPOINT|ENV|EXPOSE|FROM|INCLUDE|LABEL|MAINTAINER|ONBUILD|RUN|USER|VOLUME|WORKDIR)$/) 0 0 0
37 0 ▶ if( $1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1) { } 0 0 0
38 0 $exclude->{$2}++;
39 } else {
40 0 $include->{$2}++;
41 }
42 0 next;
43 }
44 0 push @uris, $arg;
45 }
46  
47 0 my @content = ();
48 0 for my $uri ( @uris ) {
49 0 ▶ if ( -f $uri ) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $uri) { } 0 0 0
50 0 local $/ = undef;
51 0 ▶ open my $fh, $uri || die "$uri: $!";
Condition0%0/2
$uri || die("${uri}: $!")
l!l
00
MC/DC0%0/1
$uri || die("${uri}: $!")
$uri
Truth table0%0/2
A
A= $uri
Aresult
11
00
52 0 push @content, join("", <$fh>);
53 } else {
54 0 push @content, $self->{ua}->get($uri)->decoded_content();
55 }
56 }
57 0 chomp(@content);
58 0 @content = merge($merge, \@content, $include, $exclude);
59 0 $_ = "print <<'EOM';\n".join("\n", @content)."\nEOM\n";
60 } else {
61 2 $_ = "print <<'EOM';\n${_}EOM\n";
62 }
63 2 return 1;
64 }
65  
66 0 ▶sub merge {
Subroutine merge: not called CC=12 SCAR=50.5
Pod undocumented
67 0 my ($merge, $docs, $include, $exclude) = @_;
68 0 my @result = ();
69 0 my %ops = ();
70 0 for my $doc (@$docs) {
71 0 my @lines = split( /(?<!\\)\n/, $doc);
72 0 for my $line (@lines) {
73 0 my ($op, $details) = split(/\s+/, $line, 2);
74 0 ▶ next unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 0 0
75 0 ▶ next if exists $exclude->{$op};
Branch: 1 branch
BranchTrueFalseTotal
if exists $exclude->{$op} 0 0 0
76 0 ▶ next if keys %$include && ! exists $include->{$op};
Branch: 1 branch
BranchTrueFalseTotal
if keys %$include and not exists $include->{$op} 0 0 0
Condition0%0/3
keys %$include and not exists $include->{$op}
!ll&&!rl&&r
000
MC/DC0%0/2
keys %$include and not exists $include->{$op}
keys %$include not exists $include->{$op}
Truth table0%0/3
A and not(B)
A= keys %$includeB= not exists $include->{$op}
ABresult
0X0
100
111
77 0 ▶ if ( $merge && exists $ops{$op} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($merge and exists $ops{$op}) { } 0 0 0
Condition0%0/3
$merge and exists $ops{$op}
!ll&&!rl&&r
000
MC/DC0%0/2
$merge and exists $ops{$op}
$merge exists $ops{$op}
Truth table0%0/3
A and B
A= $mergeB= exists $ops{$op}
ABresult
0X0
100
111
78 0 my $sref = $ops{$op};
79 0 ▶ if ( $op =~ /^(ENV|LABEL)$/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($op =~ /^(ENV|LABEL)$/) { } 0 0 0
elsif ($op eq 'RUN') { } 0 0 0
80 0 $$sref .= " \\\n" . " "x(length($1)+1) . "$details";
81 } elsif ( $op eq "RUN" ) {
82 0 $$sref .= " && \\\n $details";
83 0 ▶ while( (my $ix = index($$sref, "apt-get update", index($$sref, "apt-get update")+1)) > 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ((my $ix = index($$sref, "apt-get update", index($$sref, "apt-get update") + 1)) > 0) 0 0 0
84 0 substr($$sref, $ix, 14) = "echo skipping redundent apt-get-update";
85 }
86 } else {
87 0 push @result, $line;
88 }
89 } else {
90 0 push @result, $line;
91 0 $ops{$op} = \$result[-1];
92 }
93 }
94 }
95 0 return @result;
96 }
97  
98 1 1;
99  
100 __END__
↑ Summary