| 1 | package Catmandu::Cmd::export; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 14 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 14 | our $VERSION = '1.2025'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 14 | ▶ | use parent 'Catmandu::Cmd'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 14 | ▶ | use Catmandu; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 14 | ▶ | use Catmandu::ArrayIterator; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | sub command_opt_spec { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command_opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 2 | ["verbose|v", ""], | |||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | ["fix=s@", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | ["var=s%", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | ["preprocess|pp", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | ["start=i", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | ["limit=i", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ["total=i", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | ["cql-query|q=s", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ["query=s", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | ["sru-sortkeys=s", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | ["sort=s", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ["id=s@", ""], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ["id-file=s", "A line-delimited file containing the id's to export."], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | sub command { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=17 SCAR=38.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 2 | my ($self, $opts, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 2 | my ($from_args, $from_opts, $into_args, $into_opts) | |||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | = $self->_parse_options($args); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | my $from_bag = delete $from_opts->{bag}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | my $into = Catmandu->exporter($into_args->[0], $into_opts); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | if ($opts->id_file) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 1 | my $bag = $from; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | $from = Catmandu->importer('Text', file => $opts->id_file) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | ->map(sub {$bag->get($_[0]->{text})}); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | elsif (my $ids = $opts->id) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | my $bag = $from; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | $from = Catmandu::ArrayIterator->new([map {$bag->get($_)} @$ids]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | ▶ | elsif ($opts->query // $opts->cql_query // $opts->sort | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%3/9
(($opts->query // $opts->cql_query) // $opts->sort) // $opts->sru_sortkeys
($opts->query // $opts->cql_query) // $opts->sort
$opts->query // $opts->cql_query
MC/DC0%0/4
(($opts->query // $opts->cql_query) // $opts->sort) // $opts->sru_sortkeys
$opts->query
$opts->cql_query
$opts->sort
$opts->sru_sortkeys
Truth table20%1/5
A // B // C // D
A= $opts->queryB= $opts->cql_queryC= $opts->sortD= $opts->sru_sortkeys
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | // $opts->sru_sortkeys) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | $self->usage_error("Bag isn't searchable") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | if !$from->does('Catmandu::Searchable'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $self->usage_error("Bag isn't CQL searchable") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$opts->cql_query // $opts->sru_sortkeys and not $from->does("Catmandu::CQLSearchable")
$opts->cql_query // $opts->sru_sortkeys
MC/DC0%0/3
$opts->cql_query // $opts->sru_sortkeys and not $from->does("Catmandu::CQLSearchable")
$opts->cql_query
$opts->sru_sortkeys
not $from->does("Catmandu::CQLSearchable")
Truth table0%0/5
A // B and not(C)
A= $opts->cql_queryB= $opts->sru_sortkeysC= not $from->does("Catmandu::CQLSearchable")
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | if ($opts->cql_query // $opts->sru_sortkeys) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | && !$from->does('Catmandu::CQLSearchable'); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | $from = $from->searcher( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | cql_query => $opts->cql_query, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | query => $opts->query, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | sru_sortkeys => $opts->sru_sortkeys, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | sort => $opts->sort, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | start => $opts->start, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | total => $opts->total, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | limit => $opts->limit, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | $from = $from->slice($opts->start, $opts->total); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 2 | ▶ | if ($opts->fix) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | $from = $self->_build_fixer($opts)->fix($from); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 2 | $from = $from->benchmark; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | my $n = $into->add_many($from); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 2 | $into->commit; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 2 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 2 | ▶ | say STDERR $n == 1 ? "exported 1 item" : "exported $n items"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | say STDERR "done"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 14 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||