| 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
| |||||||||||||||||||||
| 24 | 0 | $from->delete($_) for @{$opts->id}; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | ▶ | elsif ($opts->query // $opts->cql_query) { | |||||||||||||||||||
|
Condition33%1/3
$opts->query // $opts->cql_query
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
| |||||||||||||||||||||
| 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 | ||||||||||||||||||||