Catmandu/Fix/import.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 60 CC 3 SCAR 16.7
CC
3
Cov
0%
_build_fixer
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.3
1 package Catmandu::Fix::import;
2  
3 use Catmandu::Sane;
4  
5 our $VERSION = '1.2025';
6  
7 use Catmandu;
8 use Catmandu::Util::Path qw(as_path);
9 use Moo;
10 use namespace::clean;
11 use Catmandu::Fix::Has;
12  
13 with 'Catmandu::Fix::Builder';
14  
15 has path => (fix_arg => 1);
16 has name => (fix_arg => 1);
17 has delete => (fix_opt => 1);
18 has ignore_404 => (fix_opt => 1);
19 has opts => (fix_opt => 'collect');
20  
21 sub _build_fixer {
22 my ($self) = @_;
23 my $path = as_path($self->path);
24 my $name = $self->name;
25 my $opts = $self->opts;
26 my $delete = $self->delete;
27 my $ignore_404 = $self->ignore_404;
28 $path->updater(
29 sub {
30 my $val = $_[0];
31 try {
32 $val = Catmandu->importer($name, variables => $val, %$opts)
33 ->first;
34 }
35 catch_case [
36 'Catmandu::HTTPError' => sub {
37 if ($_->code eq '404' && $ignore_404) {$val = undef}
38 else {$_->throw}
39 }
40 ];
41  
42 return $val if defined $val;
43 return undef, 1, $delete;
44 }
45 );
46 }
47  
48 1;
49  
50 __END__