Catmandu/Cmd/convert.pm

filter: Statementstmt 97.5% 39 / 40 Branchbran 81.2% 13 / 16 Conditioncond 66.6% 4 / 6 MC/DCmcdc 50.0% 2 / 4 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 89.6% 69 / 77 CC 12 SCAR 19.1
CC
12
Cov
90%
command
11.3
__ANON__
2.1
BEGIN
1.0
CRAP 6.8
« Catmandu/Fix/Condition/SimpleCompareTest.pm ↑ Summary Catmandu/Cmd/run.pm »
1 package Catmandu::Cmd::convert;
2  
3 14 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 14 our $VERSION = '1.2025';
6  
7 14 ▶use parent 'Catmandu::Cmd';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 14 ▶use Catmandu;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 14 ▶use Catmandu::Util qw(array_includes);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 15 ▶sub command_opt_spec {
Subroutine command_opt_spec: called CC=1 SCAR=0.0
Pod documented
13 (
14 15 ["verbose|v", ""],
15 ["fix=s@", ""],
16 ["var=s%", ""],
17 ["preprocess|pp", ""],
18 ["start=i", ""],
19 ["total=i", ""],
20 ["id=s@", ""],
21 [
22 "id-file=s",
23 "A line-delimited file containing the id's to include in the conversion. Other records will be ignored."
24 ],
25 );
26 }
27  
28 15 ▶sub command {
Subroutine command: called CC=11 SCAR=24.3
Pod documented
29 15 my ($self, $opts, $args) = @_;
30  
31 15 my ($from_args, $from_opts, $into_args, $into_opts)
32 = $self->_parse_options($args);
33  
34 15 my $from = Catmandu->importer($from_args->[0], $from_opts);
35 14 my $into = Catmandu->exporter($into_args->[0], $into_opts);
36  
37 12 ▶ if ($opts->id // $opts->id_file) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->id // $opts->id_file) { } 1 11 12
elsif ($opts->start // $opts->total) { } 1 10 11
Condition66%2/3
$opts->id // $opts->id_file
l!l&&r!l&&!r
0111
MC/DC50%1/2
$opts->id // $opts->id_file
$opts->id $opts->id_file
Truth table66%2/3
A // B
A= $opts->idB= $opts->id_file
ABresult
1X1
011
000
38 1 my $id_map = {};
39 1 ▶ if (my $ids = $opts->id) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $ids = $opts->id) { } 0 1 1
40 0 $id_map->{$_} = 1 for @$ids;
41 }
42 else {
43 Catmandu->importer('Text', file => $opts->id_file)->each(
44 3 ▶ sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
45 3 $id_map->{$_[0]->{text}} = 1;
46 }
47 1 );
48 }
49 $from = $from->select(
50 1 ▶ sub {defined $_[0]->{_id} && exists $id_map->{$_[0]->{_id}}});
Subroutine __ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0]{"_id"} and exists $$id_map{$_[0]{"_id"}} 4 0 4
51 }
52 ▶ elsif ($opts->start // $opts->total) {
Condition66%2/3
$opts->start // $opts->total
l!l&&r!l&&!r
1010
MC/DC50%1/2
$opts->start // $opts->total
$opts->start $opts->total
Truth table66%2/3
A // B
A= $opts->startB= $opts->total
ABresult
1X1
011
000
53 1 $from = $from->slice($opts->start, $opts->total);
54 }
55  
56 12 ▶ if ($opts->fix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->fix) 5 7 12
57 5 $from = $self->_build_fixer($opts)->fix($from);
58 }
59  
60 9 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 2 7 9
61 2 $from = $from->benchmark;
62 }
63  
64 9 my $n = $into->add_many($from);
65 7 $into->commit;
66 7 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 2 5 7
67 2 ▶ say STDERR $n == 1 ? "converted 1 item" : "converted $n items";
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 2 0 2
68 2 say STDERR "done";
69 }
70 }
71  
72 14 1;
73  
74 __END__
« Catmandu/Fix/Condition/SimpleCompareTest.pm ↑ Summary Catmandu/Cmd/run.pm »