line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
14
|
|
|
14
|
|
158288
|
|
|
14
|
|
|
|
|
74
|
|
|
14
|
|
|
|
|
85
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use parent 'Catmandu::Cmd'; |
7
|
14
|
|
|
14
|
|
94
|
use Catmandu; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
86
|
|
8
|
14
|
|
|
14
|
|
910
|
use Catmandu::ArrayIterator; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
66
|
|
9
|
14
|
|
|
14
|
|
7657
|
use namespace::clean; |
|
14
|
|
|
|
|
38
|
|
|
14
|
|
|
|
|
448
|
|
10
|
14
|
|
|
14
|
|
85
|
|
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
58
|
|
11
|
|
|
|
|
|
|
( |
12
|
|
|
|
|
|
|
["verbose|v", ""], |
13
|
|
|
|
|
|
|
["fix=s@", ""], |
14
|
2
|
|
|
2
|
1
|
33
|
["var=s%", ""], |
15
|
|
|
|
|
|
|
["preprocess|pp", ""], |
16
|
|
|
|
|
|
|
["start=i", ""], |
17
|
|
|
|
|
|
|
["limit=i", ""], |
18
|
|
|
|
|
|
|
["total=i", ""], |
19
|
|
|
|
|
|
|
["cql-query|q=s", ""], |
20
|
|
|
|
|
|
|
["query=s", ""], |
21
|
|
|
|
|
|
|
["sru-sortkeys=s", ""], |
22
|
|
|
|
|
|
|
["sort=s", ""], |
23
|
|
|
|
|
|
|
["id=s@", ""], |
24
|
|
|
|
|
|
|
["id-file=s", "A line-delimited file containing the id's to export."], |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my ($self, $opts, $args) = @_; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
my ($from_args, $from_opts, $into_args, $into_opts) |
31
|
2
|
|
|
2
|
1
|
5
|
= $self->_parse_options($args); |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
11
|
my $from_bag = delete $from_opts->{bag}; |
34
|
|
|
|
|
|
|
my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag); |
35
|
|
|
|
|
|
|
my $into = Catmandu->exporter($into_args->[0], $into_opts); |
36
|
2
|
|
|
|
|
15
|
|
37
|
2
|
|
|
|
|
13
|
if ($opts->id_file) { |
38
|
2
|
|
|
|
|
13
|
my $bag = $from; |
39
|
|
|
|
|
|
|
$from = Catmandu->importer('Text', file => $opts->id_file) |
40
|
2
|
100
|
33
|
|
|
22
|
->map(sub {$bag->get($_[0]->{text})}); |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
41
|
1
|
|
|
|
|
6
|
} |
42
|
|
|
|
|
|
|
elsif (my $ids = $opts->id) { |
43
|
1
|
|
|
3
|
|
8
|
my $bag = $from; |
|
3
|
|
|
|
|
65
|
|
44
|
|
|
|
|
|
|
$from = Catmandu::ArrayIterator->new([map {$bag->get($_)} @$ids]); |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
0
|
elsif ($opts->query // $opts->cql_query // $opts->sort |
47
|
0
|
|
|
|
|
0
|
// $opts->sru_sortkeys) |
|
0
|
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
{ |
49
|
|
|
|
|
|
|
$self->usage_error("Bag isn't searchable") |
50
|
|
|
|
|
|
|
if !$from->does('Catmandu::Searchable'); |
51
|
|
|
|
|
|
|
$self->usage_error("Bag isn't CQL searchable") |
52
|
0
|
0
|
|
|
|
0
|
if ($opts->cql_query // $opts->sru_sortkeys) |
53
|
|
|
|
|
|
|
&& !$from->does('Catmandu::CQLSearchable'); |
54
|
0
|
0
|
0
|
|
|
0
|
$from = $from->searcher( |
|
|
|
0
|
|
|
|
|
55
|
|
|
|
|
|
|
cql_query => $opts->cql_query, |
56
|
|
|
|
|
|
|
query => $opts->query, |
57
|
0
|
|
|
|
|
0
|
sru_sortkeys => $opts->sru_sortkeys, |
58
|
|
|
|
|
|
|
sort => $opts->sort, |
59
|
|
|
|
|
|
|
start => $opts->start, |
60
|
|
|
|
|
|
|
total => $opts->total, |
61
|
|
|
|
|
|
|
limit => $opts->limit, |
62
|
|
|
|
|
|
|
); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
elsif ($opts->start // $opts->total) { |
65
|
|
|
|
|
|
|
$from = $from->slice($opts->start, $opts->total); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
1
|
|
|
|
|
55
|
if ($opts->fix) { |
69
|
|
|
|
|
|
|
$from = $self->_build_fixer($opts)->fix($from); |
70
|
|
|
|
|
|
|
} |
71
|
2
|
100
|
|
|
|
13
|
|
72
|
1
|
|
|
|
|
12
|
if ($opts->verbose) { |
73
|
|
|
|
|
|
|
$from = $from->benchmark; |
74
|
|
|
|
|
|
|
} |
75
|
2
|
50
|
|
|
|
50
|
|
76
|
2
|
|
|
|
|
17
|
my $n = $into->add_many($from); |
77
|
|
|
|
|
|
|
$into->commit; |
78
|
|
|
|
|
|
|
if ($opts->verbose) { |
79
|
2
|
|
|
|
|
14
|
say STDERR $n == 1 ? "exported 1 item" : "exported $n items"; |
80
|
2
|
|
|
|
|
39
|
say STDERR "done"; |
81
|
2
|
50
|
|
|
|
6
|
} |
82
|
2
|
100
|
|
|
|
164
|
} |
83
|
2
|
|
|
|
|
36
|
|
84
|
|
|
|
|
|
|
1; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=pod |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 NAME |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Catmandu::Cmd::export - export items from a store |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 EXAMPLES |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
catmandu export <STORE> <OPTIONS> to <EXPORTER> <OPTIONS> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
catmandu export MongoDB --database-name items --bag book to YAML |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
catmandu export ElasticSearch --bag book --sru-sortkeys 'title,,1' --cql-query '(title = "test")' |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
catmandu help store MongoDB |
102
|
|
|
|
|
|
|
catmandu help exporter YAML |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=cut |