Catmandu/Cmd/export.pm

filter: Statementstmt 86.0% 37 / 43 Branchbran 55.0% 11 / 20 Conditioncond 22.2% 4 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 100% 8 / 8 Podpod 100% 2 / 2 totaltotal 62.0% 62 / 100 CC 17 SCAR 34.8
CC
17
Cov
64%
command
45.2
BEGIN
1.0
BEGIN
1.0
CRAP 32.3
« Catmandu/Fix.pm ↑ Summary Catmandu/Fix/Condition/in.pm »
1 package Catmandu::Cmd::export;
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::ArrayIterator;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 14 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶sub command_opt_spec {
Subroutine command_opt_spec: called CC=1 SCAR=0.0
Pod documented
13 (
14 2 ["verbose|v", ""],
15 ["fix=s@", ""],
16 ["var=s%", ""],
17 ["preprocess|pp", ""],
18 ["start=i", ""],
19 ["limit=i", ""],
20 ["total=i", ""],
21 ["cql-query|q=s", ""],
22 ["query=s", ""],
23 ["sru-sortkeys=s", ""],
24 ["sort=s", ""],
25 ["id=s@", ""],
26 ["id-file=s", "A line-delimited file containing the id's to export."],
27 );
28 }
29  
30 2 ▶sub command {
Subroutine command: called CC=17 SCAR=38.1
Pod documented
31 2 my ($self, $opts, $args) = @_;
32  
33 2 my ($from_args, $from_opts, $into_args, $into_opts)
34 = $self->_parse_options($args);
35  
36 2 my $from_bag = delete $from_opts->{bag};
37 2 my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag);
38 2 my $into = Catmandu->exporter($into_args->[0], $into_opts);
39  
40 2 ▶ if ($opts->id_file) {
Branch: 4 branches
BranchTrueFalseTotal
if ($opts->id_file) { } 1 1 2
elsif (my $ids = $opts->id) { } 0 1 1
elsif ((($opts->query // $opts->cql_query) // $opts->sort) // $opts->sru_sortkeys) { } 0 1 1
elsif ($opts->start // $opts->total) { } 1 0 1
41 1 my $bag = $from;
42 $from = Catmandu->importer('Text', file => $opts->id_file)
43 1 ▶ ->map(sub {$bag->get($_[0]->{text})});
Subroutine __ANON__: called CC=1 SCAR=0.0
44 }
45 elsif (my $ids = $opts->id) {
46 0 my $bag = $from;
47 0 $from = Catmandu::ArrayIterator->new([map {$bag->get($_)} @$ids]);
48 }
49 ▶ elsif ($opts->query // $opts->cql_query // $opts->sort
Condition33%3/9
(($opts->query // $opts->cql_query) // $opts->sort) // $opts->sru_sortkeys
l!l&&r!l&&!r
001
($opts->query // $opts->cql_query) // $opts->sort
l!l&&r!l&&!r
001
$opts->query // $opts->cql_query
l!l&&r!l&&!r
001
MC/DC0%0/4
(($opts->query // $opts->cql_query) // $opts->sort) // $opts->sru_sortkeys
$opts->query $opts->cql_query $opts->sort $opts->sru_sortkeys
Truth table20%1/5
A // B // C // D
A= $opts->queryB= $opts->cql_queryC= $opts->sortD= $opts->sru_sortkeys
ABCDresult
1XXX1
01XX1
001X1
00011
00000
50 // $opts->sru_sortkeys)
51 {
52 0 ▶ $self->usage_error("Bag isn't searchable")
Branch: 1 branch
BranchTrueFalseTotal
unless $from->does("Catmandu::Searchable") 0 0 0
53 if !$from->does('Catmandu::Searchable');
54 0 ▶ $self->usage_error("Bag isn't CQL searchable")
Branch: 1 branch
BranchTrueFalseTotal
if $opts->cql_query // $opts->sru_sortkeys and not $from->does("Catmandu::CQLSearchable") 0 0 0
Condition0%0/6
$opts->cql_query // $opts->sru_sortkeys and not $from->does("Catmandu::CQLSearchable")
!ll&&!rl&&r
000
$opts->cql_query // $opts->sru_sortkeys
l!l&&r!l&&!r
000
MC/DC0%0/3
$opts->cql_query // $opts->sru_sortkeys and not $from->does("Catmandu::CQLSearchable")
$opts->cql_query $opts->sru_sortkeys not $from->does("Catmandu::CQLSearchable")
Truth table0%0/5
A // B and not(C)
A= $opts->cql_queryB= $opts->sru_sortkeysC= not $from->does("Catmandu::CQLSearchable")
ABCresult
00X0
1X00
0100
1X11
0111
55 if ($opts->cql_query // $opts->sru_sortkeys)
56 && !$from->does('Catmandu::CQLSearchable');
57 0 $from = $from->searcher(
58 cql_query => $opts->cql_query,
59 query => $opts->query,
60 sru_sortkeys => $opts->sru_sortkeys,
61 sort => $opts->sort,
62 start => $opts->start,
63 total => $opts->total,
64 limit => $opts->limit,
65 );
66 }
67 ▶ elsif ($opts->start // $opts->total) {
Condition33%1/3
$opts->start // $opts->total
l!l&&r!l&&!r
010
MC/DC0%0/2
$opts->start // $opts->total
$opts->start $opts->total
Truth table33%1/3
A // B
A= $opts->startB= $opts->total
ABresult
1X1
011
000
68 1 $from = $from->slice($opts->start, $opts->total);
69 }
70  
71 2 ▶ if ($opts->fix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->fix) 1 1 2
72 1 $from = $self->_build_fixer($opts)->fix($from);
73 }
74  
75 2 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 2 0 2
76 2 $from = $from->benchmark;
77 }
78  
79 2 my $n = $into->add_many($from);
80 2 $into->commit;
81 2 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 2 0 2
82 2 ▶ say STDERR $n == 1 ? "exported 1 item" : "exported $n items";
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 1 1 2
83 2 say STDERR "done";
84 }
85 }
86  
87 14 1;
88  
89 __END__
« Catmandu/Fix.pm ↑ Summary Catmandu/Fix/Condition/in.pm »