| 1 | package Catmandu::Cmd::import; | ||||||||||||||||||||||||||||
| 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 namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | sub command_opt_spec { | ||||||||||||||||||||||||||
|
Subroutine
command_opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 12 | ( | ||||||||||||||||||||||||||||
| 13 | 1 | ["verbose|v", ""], | |||||||||||||||||||||||||||
| 14 | ["fix=s@", ""], | ||||||||||||||||||||||||||||
| 15 | ["var=s%", ""], | ||||||||||||||||||||||||||||
| 16 | ["preprocess|pp", ""], | ||||||||||||||||||||||||||||
| 17 | ["start=i", ""], | ||||||||||||||||||||||||||||
| 18 | ["total=i", ""], | ||||||||||||||||||||||||||||
| 19 | ["delete", "delete existing items first"], | ||||||||||||||||||||||||||||
| 20 | ["transaction|tx", "wrap in a transaction"], | ||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 1 | ▶ | sub validate_args { | ||||||||||||||||||||||||||
|
Subroutine
validate_args: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 1 | my ($self, $opt, $args) = @_; | |||||||||||||||||||||||||||
| 26 | 1 | return; | |||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | sub command { | ||||||||||||||||||||||||||
|
Subroutine
command: called CC=7 SCAR=23.1
Pod
documented
| |||||||||||||||||||||||||||||
| 30 | 1 | my ($self, $opts, $args) = @_; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 1 | my ($from_args, $from_opts, $into_args, $into_opts) | |||||||||||||||||||||||||||
| 33 | = $self->_parse_options($args); | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 1 | my $from = Catmandu->importer($from_args->[0], $from_opts); | |||||||||||||||||||||||||||
| 36 | 1 | my $into_bag = delete $into_opts->{bag}; | |||||||||||||||||||||||||||
| 37 | 1 | my $into = Catmandu->store($into_args->[0], $into_opts)->bag($into_bag); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if ($opts->start // $opts->total) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
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
| |||||||||||||||||||||||||||||
| 40 | 0 | $from = $from->slice($opts->start, $opts->total); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | 1 | ▶ | if ($opts->fix) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | 0 | $from = $self->_build_fixer($opts)->fix($from); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 1 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 1 | $from = $from->benchmark; | |||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 1 | ▶ | my $tx = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=15.5
| |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | if ($opts->delete) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | 0 | $into->delete_all; | |||||||||||||||||||||||||||
| 52 | 0 | $into->commit; | |||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | my $n = $into->add_many($from); | |||||||||||||||||||||||||||
| 56 | 1 | $into->commit; | |||||||||||||||||||||||||||
| 57 | 1 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | ▶ | say STDERR $n == 1 ? "imported 1 item" : "imported $n items"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 59 | 1 | say STDERR "done"; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 1 | }; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | if ($opts->transaction) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | $self->usage_error("Bag isn't transactional") | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | if !$into->store->does('Catmandu::Transactional'); | ||||||||||||||||||||||||||||
| 66 | 0 | $into->store->transaction($tx); | |||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||
| 69 | 1 | $tx->(); | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 14 | 1; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | __END__ | ||||||||||||||||||||||||||||