Catmandu/Cmd/copy.pm

filter: Statementstmt 80.9% 34 / 42 Branchbran 40.0% 8 / 20 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 65.4% 53 / 81 CC 13 SCAR 24.3
CC
13
Cov
65%
command
19.3
__ANON__
4.7
BEGIN
1.0
CRAP 11.4
« Catmandu/Cmd/info.pm ↑ Summary Catmandu/TabularExporter.pm »
1 package Catmandu::Cmd::copy;
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 namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub command_opt_spec {
Subroutine command_opt_spec: called CC=1 SCAR=0.0
Pod documented
12 (
13 1 ["verbose|v", ""],
14 ["fix=s@", ""],
15 ["var=s%", ""],
16 ["preprocess|pp", ""],
17 ["start=i", ""],
18 ["limit=i", ""],
19 ["total=i", ""],
20 ["cql-query|q=s", ""],
21 ["query=s", ""],
22 ["sru-sortkeys=s", ""],
23 ["sort=s", ""],
24 ["delete", "delete existing items first"],
25 ["transaction|tx", "wrap in a transaction"],
26 );
27 }
28  
29 1 ▶sub command {
Subroutine command: called CC=10 SCAR=29.6
Pod documented
30 1 my ($self, $opts, $args) = @_;
31  
32 1 my ($from_args, $from_opts, $into_args, $into_opts)
33 = $self->_parse_options($args);
34  
35 1 my $from_bag = delete $from_opts->{bag};
36 1 my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag);
37 1 my $into_bag = delete $into_opts->{bag};
38 1 my $into = Catmandu->store($into_args->[0], $into_opts)->bag($into_bag);
39  
40 1 ▶ if ($opts->query // $opts->cql_query) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->query // $opts->cql_query) { } 0 1 1
elsif ($opts->start // $opts->total) { } 0 1 1
Condition33%1/3
$opts->query // $opts->cql_query
l!l&&r!l&&!r
001
MC/DC0%0/2
$opts->query // $opts->cql_query
$opts->query $opts->cql_query
Truth table33%1/3
A // B
A= $opts->queryB= $opts->cql_query
ABresult
1X1
011
000
41 0 ▶ $self->usage_error("Bag isn't searchable")
Branch: 1 branch
BranchTrueFalseTotal
unless $from->can("searcher") 0 0 0
42 unless $from->can('searcher');
43 0 $from = $from->searcher(
44 cql_query => $opts->cql_query,
45 query => $opts->query,
46 start => $opts->start,
47 total => $opts->total,
48 limit => $opts->limit,
49 );
50 }
51 ▶ elsif ($opts->start // $opts->total) {
Condition33%1/3
$opts->start // $opts->total
l!l&&r!l&&!r
001
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
52 0 $from = $from->slice($opts->start, $opts->total);
53 }
54 1 ▶ if ($opts->fix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->fix) 0 1 1
55 0 $from = $self->_build_fixer($opts)->fix($from);
56 }
57 1 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 1 0 1
58 1 $from = $from->benchmark;
59 }
60  
61 1 ▶ my $tx = sub {
Subroutine __ANON__: called CC=4 SCAR=15.5
62 1 ▶ if ($opts->delete) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->delete) 0 1 1
63 0 $into->delete_all;
64 0 $into->commit;
65 }
66  
67 1 my $n = $into->add_many($from);
68 1 $into->commit;
69 1 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 1 0 1
70 1 ▶ say STDERR $n == 1 ? "copied 1 item" : "copied $n items";
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 0 1 1
71 1 say STDERR "done";
72 }
73 1 };
74  
75 1 ▶ if ($opts->transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->transaction) { } 0 1 1
76 0 ▶ $self->usage_error("Bag isn't transactional")
Branch: 1 branch
BranchTrueFalseTotal
unless $into->store->does("Catmandu::Transactional") 0 0 0
77 if !$into->store->does('Catmandu::Transactional');
78 0 $into->store->transaction($tx);
79 }
80 else {
81 1 $tx->();
82 }
83 }
84  
85 14 1;
86  
87 __END__
« Catmandu/Cmd/info.pm ↑ Summary Catmandu/TabularExporter.pm »