line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
14
|
|
|
14
|
|
116233
|
|
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
76
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use parent 'Catmandu::Cmd'; |
7
|
14
|
|
|
14
|
|
95
|
use Catmandu; |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
65
|
|
8
|
14
|
|
|
14
|
|
872
|
use namespace::clean; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
65
|
|
9
|
14
|
|
|
14
|
|
4074
|
|
|
14
|
|
|
|
|
24
|
|
|
14
|
|
|
|
|
67
|
|
10
|
|
|
|
|
|
|
( |
11
|
|
|
|
|
|
|
["verbose|v", ""], |
12
|
|
|
|
|
|
|
["fix=s@", ""], |
13
|
1
|
|
|
1
|
1
|
22
|
["var=s%", ""], |
14
|
|
|
|
|
|
|
["preprocess|pp", ""], |
15
|
|
|
|
|
|
|
["start=i", ""], |
16
|
|
|
|
|
|
|
["limit=i", ""], |
17
|
|
|
|
|
|
|
["total=i", ""], |
18
|
|
|
|
|
|
|
["cql-query|q=s", ""], |
19
|
|
|
|
|
|
|
["query=s", ""], |
20
|
|
|
|
|
|
|
["sru-sortkeys=s", ""], |
21
|
|
|
|
|
|
|
["sort=s", ""], |
22
|
|
|
|
|
|
|
["delete", "delete existing items first"], |
23
|
|
|
|
|
|
|
["transaction|tx", "wrap in a transaction"], |
24
|
|
|
|
|
|
|
); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my ($self, $opts, $args) = @_; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my ($from_args, $from_opts, $into_args, $into_opts) |
30
|
1
|
|
|
1
|
1
|
4
|
= $self->_parse_options($args); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
7
|
my $from_bag = delete $from_opts->{bag}; |
33
|
|
|
|
|
|
|
my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag); |
34
|
|
|
|
|
|
|
my $into_bag = delete $into_opts->{bag}; |
35
|
1
|
|
|
|
|
3
|
my $into = Catmandu->store($into_args->[0], $into_opts)->bag($into_bag); |
36
|
1
|
|
|
|
|
20
|
|
37
|
1
|
|
|
|
|
15
|
if ($opts->query // $opts->cql_query) { |
38
|
1
|
|
|
|
|
10
|
$self->usage_error("Bag isn't searchable") |
39
|
|
|
|
|
|
|
unless $from->can('searcher'); |
40
|
1
|
50
|
33
|
|
|
23
|
$from = $from->searcher( |
|
|
50
|
33
|
|
|
|
|
41
|
0
|
0
|
|
|
|
0
|
cql_query => $opts->cql_query, |
42
|
|
|
|
|
|
|
query => $opts->query, |
43
|
0
|
|
|
|
|
0
|
start => $opts->start, |
44
|
|
|
|
|
|
|
total => $opts->total, |
45
|
|
|
|
|
|
|
limit => $opts->limit, |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
elsif ($opts->start // $opts->total) { |
49
|
|
|
|
|
|
|
$from = $from->slice($opts->start, $opts->total); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
if ($opts->fix) { |
52
|
0
|
|
|
|
|
0
|
$from = $self->_build_fixer($opts)->fix($from); |
53
|
|
|
|
|
|
|
} |
54
|
1
|
50
|
|
|
|
25
|
if ($opts->verbose) { |
55
|
0
|
|
|
|
|
0
|
$from = $from->benchmark; |
56
|
|
|
|
|
|
|
} |
57
|
1
|
50
|
|
|
|
7
|
|
58
|
1
|
|
|
|
|
7
|
my $tx = sub { |
59
|
|
|
|
|
|
|
if ($opts->delete) { |
60
|
|
|
|
|
|
|
$into->delete_all; |
61
|
|
|
|
|
|
|
$into->commit; |
62
|
1
|
50
|
|
1
|
|
3
|
} |
63
|
0
|
|
|
|
|
0
|
|
64
|
0
|
|
|
|
|
0
|
my $n = $into->add_many($from); |
65
|
|
|
|
|
|
|
$into->commit; |
66
|
|
|
|
|
|
|
if ($opts->verbose) { |
67
|
1
|
|
|
|
|
6
|
say STDERR $n == 1 ? "copied 1 item" : "copied $n items"; |
68
|
1
|
|
|
|
|
19
|
say STDERR "done"; |
69
|
1
|
50
|
|
|
|
3
|
} |
70
|
1
|
50
|
|
|
|
17
|
}; |
71
|
1
|
|
|
|
|
26
|
|
72
|
|
|
|
|
|
|
if ($opts->transaction) { |
73
|
1
|
|
|
|
|
8
|
$self->usage_error("Bag isn't transactional") |
74
|
|
|
|
|
|
|
if !$into->store->does('Catmandu::Transactional'); |
75
|
1
|
50
|
|
|
|
4
|
$into->store->transaction($tx); |
76
|
0
|
0
|
|
|
|
0
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
|
|
|
|
0
|
$tx->(); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
1
|
|
|
|
|
7
|
|
82
|
|
|
|
|
|
|
1; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=pod |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 NAME |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Catmandu::Cmd::copy - copy items from one store to another |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 EXAMPLES |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
catmandu copy <STORE> <OPTIONS> to <STORE> <OPTIONS> |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
catmandu copy MongoDB --database_name items --bag book to \ |
96
|
|
|
|
|
|
|
ElasticSearch --index_name items --bag book |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
catmandu help store MongoDB |
99
|
|
|
|
|
|
|
catmandu help store ElasticSearch |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=cut |