blib/lib/Catmandu/Cmd/delete.pm

filter: Statementstmt 86.2% 25 / 29 Branchbran 50.0% 2 / 4 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 78.7% 37 / 47 CC 5 SCAR 13.4
CC
5
Cov
78%
command
7.2
BEGIN
1.0
BEGIN
1.0
CRAP 3.8
« blib/lib/Catmandu/Plugin/Versioning.pm ↑ Summary blib/lib/Catmandu/Importer/TSV.pm »
1 package Catmandu::Cmd::delete;
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 Catmandu::Util qw(check_able);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub command_opt_spec {
13 1 ▶ (["cql-query|q=s", ""], ["query=s", ""], ["id=s@", ""],);
Subroutine command_opt_spec: called CC=1 SCAR=0.0
Pod documented
14 }
15  
16 sub command {
17 1 ▶ my ($self, $opts, $args) = @_;
Subroutine command: called CC=5 SCAR=19.7
Pod documented
18  
19 1 my ($from_args, $from_opts) = $self->_parse_options($args);
20  
21 1 my $from_bag = delete $from_opts->{bag};
22 1 my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag);
23 1 ▶ if ($opts->id) {
Branch: 2 branches
BranchTrueFalseTotal
if ($opts->id) { } 0 1 1
elsif ($opts->query // $opts->cql_query) { } 0 1 1
24 0 $from->delete($_) for @{$opts->id};
25 }
26 ▶ elsif ($opts->query // $opts->cql_query) {
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
27 0 check_able($from, 'delete_by_query');
28 0 $from->delete_by_query(
29 cql_query => $opts->cql_query,
30 query => $opts->query,
31 );
32 }
33 else {
34 1 $from->delete_all;
35 }
36  
37 1 $from->commit;
38 }
39  
40 13 1;
41  
42 __END__
43  
44 =pod
45  
46 =head1 NAME
47  
48 Catmandu::Cmd::delete - delete objects from a store
49  
50 =head1 EXAMPLES
51  
52 catmandu delete <STORE> <OPTIONS>
53  
54
55 # delete items with matching _id
56 catmandu delete ElasticSearch --index-name items --bag book \
57 --id 1234 --id 2345
58  
59 # delete items matching the query
60 catmandu delete ElasticSearch --index-name items --bag book \
61 --query 'title:"My Rabbit"'
62  
63 # delete all items
64 catmandu delete ElasticSearch --index-name items --bag book
65  
66 catmandu help store ElasticSearch
67  
68 =cut
« blib/lib/Catmandu/Plugin/Versioning.pm ↑ Summary blib/lib/Catmandu/Importer/TSV.pm »