| 1 | package Catmandu::Cmd::import; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 13 | ▶ | use Catmandu::Sane; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 13 | our $VERSION = '1.0201_02'; | |||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 13 | ▶ | use parent 'Catmandu::Cmd'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Catmandu; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 13 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub command_opt_spec { | ||||||||||||||||||||||||||||
| 12 | ( | ||||||||||||||||||||||||||||
| 13 | 1 | ▶ | ["verbose|v", ""], | ||||||||||||||||||||||||||
|
Subroutine
command_opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 14 | ["fix=s@", ""], | ||||||||||||||||||||||||||||
| 15 | ["var=s%", ""], | ||||||||||||||||||||||||||||
| 16 | ["preprocess|pp", ""], | ||||||||||||||||||||||||||||
| 17 | ["start=i", ""], | ||||||||||||||||||||||||||||
| 18 | ["total=i", ""], | ||||||||||||||||||||||||||||
| 19 | ["delete", "delete existing objects first"], | ||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | sub command { | ||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my ($self, $opts, $args) = @_; | ||||||||||||||||||||||||||
|
Subroutine
command: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 0 | my ($from_args, $from_opts, $into_args, $into_opts) | |||||||||||||||||||||||||||
| 27 | = $self->_parse_options($args); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 0 | my $from = Catmandu->importer($from_args->[0], $from_opts); | |||||||||||||||||||||||||||
| 30 | 0 | my $into_bag = delete $into_opts->{bag}; | |||||||||||||||||||||||||||
| 31 | 0 | my $into = Catmandu->store($into_args->[0], $into_opts)->bag($into_bag); | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | if ($opts->start // $opts->total) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opts->start // $opts->total
MC/DC0%0/2
$opts->start // $opts->total
$opts->start
$opts->total
Truth table0%0/3
A // B
A= $opts->startB= $opts->total
| |||||||||||||||||||||||||||||
| 34 | 0 | $from = $from->slice($opts->start, $opts->total); | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | if ($opts->fix) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | $from = $self->_build_fixer($opts)->fix($from); | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 0 | $from = $from->benchmark; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | if ($opts->delete) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | 0 | $into->delete_all; | |||||||||||||||||||||||||||
| 45 | 0 | $into->commit; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 0 | my $n = $into->add_many($from); | |||||||||||||||||||||||||||
| 49 | 0 | $into->commit; | |||||||||||||||||||||||||||
| 50 | 0 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | ▶ | say STDERR $n == 1 ? "imported 1 object" : "imported $n objects"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | say STDERR "done"; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 13 | 1; | |||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | __END__ | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | =pod | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | =head1 NAME | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | Catmandu::Cmd::import - import objects into a store | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | =head1 EXAMPLES | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | catmandu import <IMPORTER> <OPTIONS> to <STORE> <OPTIONS> | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | catmandu import YAML to MongoDB --database-name items --bag book < books.yml | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | catmandu help importer YAML | ||||||||||||||||||||||||||||
| 73 | catmandu help importer MongoDB | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | =cut | ||||||||||||||||||||||||||||