line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
14
|
|
|
14
|
|
140981
|
|
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
72
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use parent 'Catmandu::Cmd'; |
7
|
14
|
|
|
14
|
|
94
|
use Catmandu; |
|
14
|
|
|
|
|
29
|
|
|
14
|
|
|
|
|
66
|
|
8
|
14
|
|
|
14
|
|
847
|
use Catmandu::ArrayIterator; |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
66
|
|
9
|
14
|
|
|
14
|
|
7414
|
use namespace::clean; |
|
14
|
|
|
|
|
36
|
|
|
14
|
|
|
|
|
385
|
|
10
|
14
|
|
|
14
|
|
79
|
|
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
47
|
|
11
|
|
|
|
|
|
|
( |
12
|
|
|
|
|
|
|
["verbose|v", ""], |
13
|
|
|
|
|
|
|
["fix=s@", ""], |
14
|
2
|
|
|
2
|
1
|
29
|
["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
|
6
|
= $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
|
|
|
|
|
5
|
|
37
|
2
|
|
|
|
|
11
|
if ($opts->id_file) { |
38
|
2
|
|
|
|
|
23
|
my $bag = $from; |
39
|
|
|
|
|
|
|
$from = Catmandu->importer('Text', file => $opts->id_file) |
40
|
2
|
100
|
33
|
|
|
10
|
->map(sub {$bag->get($_[0]->{text})}); |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
41
|
1
|
|
|
|
|
5
|
} |
42
|
|
|
|
|
|
|
elsif (my $ids = $opts->id) { |
43
|
1
|
|
|
3
|
|
4
|
my $bag = $from; |
|
3
|
|
|
|
|
56
|
|
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
|
|
|
|
|
41
|
if ($opts->fix) { |
69
|
|
|
|
|
|
|
$from = $self->_build_fixer($opts)->fix($from); |
70
|
|
|
|
|
|
|
} |
71
|
2
|
100
|
|
|
|
9
|
|
72
|
1
|
|
|
|
|
12
|
if ($opts->verbose) { |
73
|
|
|
|
|
|
|
$from = $from->benchmark; |
74
|
|
|
|
|
|
|
} |
75
|
2
|
50
|
|
|
|
37
|
|
76
|
2
|
|
|
|
|
15
|
my $n = $into->add_many($from); |
77
|
|
|
|
|
|
|
$into->commit; |
78
|
|
|
|
|
|
|
if ($opts->verbose) { |
79
|
2
|
|
|
|
|
12
|
say STDERR $n == 1 ? "exported 1 item" : "exported $n items"; |
80
|
2
|
|
|
|
|
41
|
say STDERR "done"; |
81
|
2
|
50
|
|
|
|
7
|
} |
82
|
2
|
100
|
|
|
|
141
|
} |
83
|
2
|
|
|
|
|
39
|
|
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 |