cpm/Worker/Installer/Custom.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 56 CC 4 SCAR 16.4
CC
4
Cov
0%
new_from_file
12.0
config
6.0
new
2.0
CRAP 5.2
1 package App::cpm::Worker::Installer::Custom;
2 use v5.24;
3 use warnings;
4 use experimental qw(lexical_subs signatures);
5  
6 use JSON::PP ();
7  
8 sub new ($class, %argv) {
9 bless { custom => [], %argv }, $class;
10 }
11  
12 sub new_from_file ($class, $path) {
13 open my $fh, "<:utf8", $path or die "$path: $!\n";
14 my $content = do { local $/; <$fh> };
15 my $data = eval { JSON::PP->new->decode($content) };
16 die "invalid json file, $path: $@" if $@;
17 my @custom = $data->{distribution_custom} ? $data->{distribution_custom}->@* : ();
18 for my $c (@custom) {
19 $c->{match} = qr/$c->{match}/;
20 }
21 $class->new(custom => \@custom);
22 }
23  
24 sub config ($self, $dist_uri) {
25 for my $c ($self->{custom}->@*) {
26 if ($dist_uri =~ $c->{match}) {
27 return $c->{config};
28 }
29 }
30 return;
31 }
32  
33 sub merge ($self, $other) {
34 my $class = ref $self;
35 $class->new(custom => [ $self->{custom}->@*, $other->{custom}->@* ]);
36 }
37  
38 sub default ($class) {
39 $class->new(custom => [
40 {
41 match => qr{/G/GR/GRANTM/XML-SAX-[\d.]+\.tar\.gz$},
42 config => {
43 prebuilt => 0,
44 use_install_command => 1,
45 },
46 },
47 ]);
48 }
49  
50 1;