| 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
| |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | if ( /^INCLUDE/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | 0 | ▶ | while( substr($_,-2) eq "\\\n" ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | 0 | $_ = substr($_,0,-2); | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | filter_read() || return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if( $1 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 50 | 0 | local $/ = undef; | |||||||||||||||||||||||||||
| 51 | 0 | ▶ | open my $fh, $uri || die "$uri: $!"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$uri || die("${uri}: $!")
MC/DC0%0/1
$uri || die("${uri}: $!")
$uri
Truth table0%0/2
A
A= $uri
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 75 | 0 | ▶ | next if exists $exclude->{$op}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | next if keys %$include && ! exists $include->{$op}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
keys %$include and not exists $include->{$op}
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}
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | if ( $merge && exists $ops{$op} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$merge and exists $ops{$op}
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}
| |||||||||||||||||||||||||||||
| 78 | 0 | my $sref = $ops{$op}; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | if ( $op =~ /^(ENV|LABEL)$/ ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||