corpus/lib/Alien/Build/Plugin/Fetch/Corpus.pm

filter: Statementstmt 89.8% 53 / 59 Branchbran 71.4% 10 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.9% 10 / 11 Podpod 100% 1 / 1 totaltotal 84.4% 76 / 90 CC 9 SCAR 17.3
CC
9
Cov
86%
__ANON__
10.7
__ANON__
2.0
init
1.0
CRAP 5.7
« blib/lib/Alien/Build/Plugin/Probe/CBuilder.pm ↑ Summary blib/lib/Alien/Build/Plugin/Digest/Negotiate.pm »
1 package Alien::Build::Plugin::Fetch::Corpus;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Alien::Build::Plugin;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 10 ▶sub _path { Path::Tiny::path(@_) }
Subroutine _path: called CC=1 SCAR=0.0
10  
11 0 ▶has '+url' => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
12 0 Carp::croak "url is required";
13 1 };
14  
15 1 has return_listing_as => 'list'; # or html or dir_listing
16 1 has return_file_as => 'content'; # or path
17  
18 1 has regex => qr/\.tar\.gz$/;
19  
20 sub init
21 5 ▶{
Subroutine init: called CC=1 SCAR=0.1
Pod documented
22 5 my($self, $meta) = @_;
23  
24 my $list = {
25 type => 'list',
26 protocol => 'https',
27 list => [
28 map {
29 530 my %h = (
30 filename => $_,
31 url => "https://test1.test/foo/bar/baz/$_",
32 );
33 530 \%h;
34 5 } ((map { $_->basename } grep { -f $_ } _path('corpus/dist')->children), map { sprintf "foo-0.%02d.tar.gz", $_ } 0..99),
35 ],
36 };
37  
38 5 $meta->prop->{start_url} = 'https://test1.test/foo/bar/baz/';
39  
40 $meta->register_hook(
41 8 ▶ fetch => sub {
Subroutine __ANON__: called CC=9 SCAR=23.7
42 8 my(undef, $url) = @_;
43  
44 8 ▶ $url ||= $self->url;
Condition66%2/3
$url ||= $self->url
l!l&&r!l&&!r
350
MC/DC0%0/2
$url ||= $self->url
$url $self->url
Truth table66%2/3
A ||= B
A= $urlB= $self->url
ABresult
1X1
011
000
45  
46 8 ▶ if($url =~ qr!^https://test1\.test/foo/bar/baz/?$!)
Branch: 2 branches
BranchTrueFalseTotal
if ($url =~ qr"^https://test1\.test/foo/bar/baz/?$") { } 3 5 8
elsif ($url =~ qr"^https://test1\.test/foo/bar/baz/(.*)$") { } 5 0 5
47 {
48 3 ▶ if($self->return_listing_as eq 'list')
Branch: 2 branches
BranchTrueFalseTotal
if ($self->return_listing_as eq 'list') { } 1 2 3
elsif ($self->return_listing_as =~ /^(?:html|dir_listing)$/) { } 2 0 2
49 {
50 1 return $list;
51 }
52 elsif($self->return_listing_as =~ /^(?:html|dir_listing)$/)
53 {
54 return {
55 2 type => $self->return_listing_as,
56 base => 'https://test1.test/foo/bar/baz/',
57 content => 'test content',
58 protocol => 'https',
59 };
60 }
61 else
62 {
63 0 die "todo: @{[ $self->return_listing_as ]}";
64 }
65 }
66 elsif($url =~ qr!^https://test1\.test/foo/bar/baz/(.*)$!)
67 {
68 5 my $path = _path "corpus/dist/$1";
69 5 ▶ if(-f $path)
Branch: 1 branch
BranchTrueFalseTotal
if (-f $path) { } 5 0 5
70 {
71 5 my %hash = (
72 type => 'file',
73 filename => $path->basename,
74 );
75 5 ▶ if($self->return_file_as eq 'content')
Branch: 2 branches
BranchTrueFalseTotal
if ($self->return_file_as eq 'content') { } 4 1 5
elsif ($self->return_file_as eq 'path') { } 1 0 1
76 {
77 4 $hash{content} = $path->slurp_raw;
78 }
79 elsif($self->return_file_as eq 'path')
80 {
81 1 $hash{path} = $path->stringify;
82 }
83 5 $hash{protocol} = 'https';
84 5 return \%hash;
85 }
86 else
87 {
88 0 die "bad file: @{[ $path->basename ]}";
89 }
90 }
91 else
92 {
93 0 die "bad url: $url";
94 }
95 },
96 5 );
97  
98 $meta->register_hook(
99 2 ▶ decode => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
100 2 return $list;
101 }
102 5 );
103  
104 $meta->register_hook(
105 3 ▶ prefer => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
106 3 my(undef, $res) = @_;
107  
108 342 my @list = sort { $b->{filename} cmp $a->{filename} }
109 318 grep { $_->{filename} =~ $self->regex }
110 3 @{ $res->{list} };
111  
112 return {
113 3 type => 'list',
114 list => \@list,
115 };
116 }
117 5 );
118 }
119  
120 1 1;
« blib/lib/Alien/Build/Plugin/Probe/CBuilder.pm ↑ Summary blib/lib/Alien/Build/Plugin/Digest/Negotiate.pm »