line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
14
|
|
|
14
|
|
110860
|
|
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
87
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use parent 'Catmandu::Cmd'; |
7
|
14
|
|
|
14
|
|
88
|
use Catmandu; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
75
|
|
8
|
14
|
|
|
14
|
|
925
|
use namespace::clean; |
|
14
|
|
|
|
|
23
|
|
|
14
|
|
|
|
|
93
|
|
9
|
14
|
|
|
14
|
|
2712
|
|
|
14
|
|
|
|
|
36
|
|
|
14
|
|
|
|
|
81
|
|
10
|
|
|
|
|
|
|
( |
11
|
|
|
|
|
|
|
["verbose|v", ""], |
12
|
|
|
|
|
|
|
["fix=s@", ""], |
13
|
1
|
|
|
1
|
1
|
53
|
["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
|
3
|
= $self->_parse_options($args); |
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
|
|
6
|
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
|
|
|
|
|
2
|
my $into = Catmandu->store($into_args->[0], $into_opts)->bag($into_bag); |
36
|
1
|
|
|
|
|
23
|
|
37
|
1
|
|
|
|
|
3
|
if ($opts->query // $opts->cql_query) { |
38
|
1
|
|
|
|
|
6
|
$self->usage_error("Bag isn't searchable") |
39
|
|
|
|
|
|
|
unless $from->can('searcher'); |
40
|
1
|
50
|
33
|
|
|
13
|
$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
|
|
|
|
20
|
if ($opts->verbose) { |
55
|
0
|
|
|
|
|
0
|
$from = $from->benchmark; |
56
|
|
|
|
|
|
|
} |
57
|
1
|
50
|
|
|
|
6
|
|
58
|
1
|
|
|
|
|
8
|
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
|
|
|
|
|
17
|
say STDERR "done"; |
69
|
1
|
50
|
|
|
|
4
|
} |
70
|
1
|
50
|
|
|
|
14
|
}; |
71
|
1
|
|
|
|
|
23
|
|
72
|
|
|
|
|
|
|
if ($opts->transaction) { |
73
|
1
|
|
|
|
|
6
|
$self->usage_error("Bag isn't transactional") |
74
|
|
|
|
|
|
|
if !$into->store->does('Catmandu::Transactional'); |
75
|
1
|
50
|
|
|
|
5
|
$into->store->transaction($tx); |
76
|
0
|
0
|
|
|
|
0
|
} |
77
|
|
|
|
|
|
|
else { |
78
|
0
|
|
|
|
|
0
|
$tx->(); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
1
|
|
|
|
|
6
|
|
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 |