| 1 | package Catmandu::Cmd::copy; | ||||||||||||||||||||||||||||||||
| 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 | ▶ | ["verbose|v", ""], | ||||||||||||||||||||||||||||||
|
Subroutine
command_opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 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 | ["delete", "delete existing objects first"], | ||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||
| 26 | sub command { | ||||||||||||||||||||||||||||||||
| 27 | 1 | ▶ | my ($self, $opts, $args) = @_; | ||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=11 SCAR=30.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||
| 29 | 1 | my ($from_args, $from_opts, $into_args, $into_opts) | |||||||||||||||||||||||||||||||
| 30 | = $self->_parse_options($args); | ||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||
| 32 | 1 | my $from_bag = delete $from_opts->{bag}; | |||||||||||||||||||||||||||||||
| 33 | 1 | my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag); | |||||||||||||||||||||||||||||||
| 34 | 1 | my $into_bag = delete $into_opts->{bag}; | |||||||||||||||||||||||||||||||
| 35 | 1 | my $into = Catmandu->store($into_args->[0], $into_opts)->bag($into_bag); | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 1 | ▶ | if ($opts->query // $opts->cql_query) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
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
| |||||||||||||||||||||||||||||||||
| 38 | 0 | ▶ | $self->usage_error("Bag isn't searchable") | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 39 | unless $from->can('searcher'); | ||||||||||||||||||||||||||||||||
| 40 | 0 | $from = $from->searcher( | |||||||||||||||||||||||||||||||
| 41 | cql_query => $opts->cql_query, | ||||||||||||||||||||||||||||||||
| 42 | query => $opts->query, | ||||||||||||||||||||||||||||||||
| 43 | start => $opts->start, | ||||||||||||||||||||||||||||||||
| 44 | total => $opts->total, | ||||||||||||||||||||||||||||||||
| 45 | limit => $opts->limit, | ||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||
| 48 | ▶ | elsif ($opts->start // $opts->total) { | |||||||||||||||||||||||||||||||
|
Condition33%1/3
$opts->start // $opts->total
MC/DC0%0/2
$opts->start // $opts->total
$opts->start
$opts->total
Truth table33%1/3
A // B
A= $opts->startB= $opts->total
| |||||||||||||||||||||||||||||||||
| 49 | 0 | $from = $from->slice($opts->start, $opts->total); | |||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||
| 51 | 1 | ▶ | if ($opts->fix) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 52 | 0 | $from = $self->_build_fixer($opts)->fix($from); | |||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||
| 54 | 1 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 55 | 1 | $from = $from->benchmark; | |||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||
| 58 | 1 | ▶ | if ($opts->delete) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 59 | 0 | $into->delete_all; | |||||||||||||||||||||||||||||||
| 60 | 0 | $into->commit; | |||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||
| 63 | 1 | my $n = $into->add_many($from); | |||||||||||||||||||||||||||||||
| 64 | 1 | $into->commit; | |||||||||||||||||||||||||||||||
| 65 | 1 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 66 | 1 | ▶ | say STDERR $n == 1 ? "copied 1 object" : "copied $n objects"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 1 | say STDERR "done"; | |||||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||
| 71 | 13 | 1; | |||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||
| 75 | =pod | ||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||
| 77 | =head1 NAME | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | Catmandu::Cmd::copy - copy objects from one store to another | ||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||
| 81 | =head1 EXAMPLES | ||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | catmandu copy <STORE> <OPTIONS> to <STORE> <OPTIONS> | ||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||
| 85 | catmandu copy MongoDB --database_name items --bag book to \ | ||||||||||||||||||||||||||||||||
| 86 | ElasticSearch --index_name items --bag book | ||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||
| 88 | catmandu help store MongoDB | ||||||||||||||||||||||||||||||||
| 89 | catmandu help store ElasticSearch | ||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||
| 91 | =cut | ||||||||||||||||||||||||||||||||