blib/lib/Catmandu/Cmd/data.pm

filter: Statementstmt 30.0% 15 / 50 Branchbran 0.0% 0 / 32 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 83.3% 5 / 6 Podpod 100% 2 / 2 totaltotal 20.9% 22 / 105 CC 20 SCAR 58.2
CC
20
Cov
16%
command
420.0
BEGIN
1.0
BEGIN
1.0
CRAP 336.2
↑ Summary blib/lib/Catmandu/Cmd/export.pm »
1 package Catmandu::Cmd::data;
2  
3 13 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 our $VERSION = '1.0201_02';
6  
7 13 ▶use parent 'Catmandu::Cmd';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Catmandu;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 sub command_opt_spec {
12 (
13 1 ▶ ["from-store=s", "", {default => Catmandu->default_store}],
Subroutine command_opt_spec: called CC=1 SCAR=0.0
Pod documented
14 ["from-importer=s", ""],
15 ["from-bag=s", ""],
16 ["count", ""],
17 ["into-exporter=s", ""],
18 ["into-store=s", "", {default => Catmandu->default_store}],
19 ["into-bag=s", ""],
20 ["start=i", ""],
21 ["limit=i", ""],
22 ["total=i", ""],
23 ["cql-query|q=s", ""],
24 ["query=s", ""],
25 ["fix=s@", "fix expression(s) or fix file(s)"],
26 ["var=s%", ""],
27 ["preprocess|pp", ""],
28 ["replace", ""],
29 ["verbose|v", ""],
30 );
31 }
32  
33 sub command {
34 0 ▶ my ($self, $opts, $args) = @_;
Subroutine command: not called CC=20 SCAR=60.4
Pod documented
35  
36 0 my $from_opts = {};
37 0 my $into_opts = {};
38 0 ▶ for (my $i = 0; $i < @$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$args) 0 0 0
39 0 my $arg = $args->[$i];
40 0 ▶ if (my ($for, $key) = $arg =~ /^--(from|into)-([\w\-]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = $arg =~ /^--(from|into)-([\w\-]+)$/) 0 0 0
41 0 ▶ if (defined(my $val = $args->[++$i])) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $val = $$args[++$i])) 0 0 0
42 0 $key =~ s/-/_/g;
43 0 ▶ ($for eq 'from' ? $from_opts : $into_opts)->{$key} = $val;
Branch: 1 branch
BranchTrueFalseTotal
$for eq 'from' ? : 0 0 0
44 }
45 }
46 }
47  
48 0 my $from;
49 my $into;
50  
51 0 ▶ if ($opts->from_bag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->from_bag) { } 0 0 0
52 0 $from = Catmandu->store($opts->from_store, $from_opts)
53 ->bag($opts->from_bag);
54 }
55 else {
56 0 $from = Catmandu->importer($opts->from_importer, $from_opts);
57 }
58  
59 0 ▶ if ($opts->query || $opts->cql_query) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->query or $opts->cql_query) { } 0 0 0
elsif (defined $opts->limit) { } 0 0 0
Condition0%0/3
$opts->query or $opts->cql_query
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->query or $opts->cql_query
$opts->query $opts->cql_query
Truth table0%0/3
A or B
A= $opts->queryB= $opts->cql_query
ABresult
1X1
011
000
60 0 ▶ $self->usage_error("Bag isn't searchable")
Branch: 1 branch
BranchTrueFalseTotal
unless $from->can("searcher") 0 0 0
61 unless $from->can('searcher');
62 0 $from = $from->searcher(
63 cql_query => $opts->cql_query,
64 query => $opts->query,
65 limit => $opts->limit,
66 );
67 }
68 elsif (defined $opts->limit) {
69 0 $from = $from->take($opts->limit);
70 }
71  
72 0 ▶ if ($opts->start || defined $opts->total) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->start or defined $opts->total) 0 0 0
Condition0%0/3
$opts->start or defined $opts->total
l!l&&r!l&&!r
000
MC/DC0%0/2
$opts->start or defined $opts->total
$opts->start defined $opts->total
Truth table0%0/3
A or B
A= $opts->startB= defined $opts->total
ABresult
1X1
011
000
73 0 $from = $from->slice($opts->start, $opts->total);
74 }
75  
76 0 ▶ if ($opts->count) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->count) 0 0 0
77 0 return say $from->count;
78 }
79  
80 0 ▶ if ($opts->into_bag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->into_bag) { } 0 0 0
81 0 $into = Catmandu->store($opts->into_store, $into_opts)
82 ->bag($opts->into_bag);
83 }
84 else {
85 0 $into = Catmandu->exporter($opts->into_exporter, $into_opts);
86 }
87  
88 0 ▶ if ($opts->fix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->fix) 0 0 0
89 0 $from = $self->_build_fixer($opts)->fix($from);
90 }
91  
92 0 ▶ if ($opts->replace && $into->can('delete_all')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->replace and $into->can("delete_all")) 0 0 0
Condition0%0/3
$opts->replace and $into->can("delete_all")
!ll&&!rl&&r
000
MC/DC0%0/2
$opts->replace and $into->can("delete_all")
$opts->replace $into->can("delete_all")
Truth table0%0/3
A and B
A= $opts->replaceB= $into->can("delete_all")
ABresult
0X0
100
111
93 0 $into->delete_all;
94 }
95  
96 0 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 0 0 0
97 0 $from = $from->benchmark;
98 }
99  
100 0 my $n = $into->add_many($from);
101 0 $into->commit;
102  
103 0 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 0 0 0
104 0 ▶ say STDERR $n == 1 ? "added 1 object" : "added $n objects";
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 0 0 0
105 0 say STDERR "done";
106 }
107 }
108  
109 13 1;
110  
111 __END__
112  
113 =pod
114  
115 =head1 NAME
116  
117 Catmandu::Cmd::data - store, index, search, import, export or convert (deprecated)
118  
119 =head1 DEPRECIATION NOTICE
120  
121 This fix is deprecated, Please use these commands instead:
122  
123 =over 4
124  
125 =item L<Catmandu::Cmd::convert>
126  
127 =item L<Catmandu::Cmd::copy>
128  
129 =item L<Catmandu::Cmd::import>
130  
131 =item L<Catmandu::Cmd::export>
132  
133 =item L<Catmandu::Cmd::count>
134  
135 =item L<Catmandu::Cmd::delete>
136  
137 =back
138  
139 =cut
↑ Summary blib/lib/Catmandu/Cmd/export.pm »