| 1 | package Catmandu::Cmd::convert; | ||||||||||||||||||||||||||||||||
| 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::Util qw(array_includes); | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 14 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 15 | ▶ | sub command_opt_spec { | ||||||||||||||||||||||||||||||
|
Subroutine
command_opt_spec: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||
| 13 | ( | ||||||||||||||||||||||||||||||||
| 14 | 15 | ["verbose|v", ""], | |||||||||||||||||||||||||||||||
| 15 | ["fix=s@", ""], | ||||||||||||||||||||||||||||||||
| 16 | ["var=s%", ""], | ||||||||||||||||||||||||||||||||
| 17 | ["preprocess|pp", ""], | ||||||||||||||||||||||||||||||||
| 18 | ["start=i", ""], | ||||||||||||||||||||||||||||||||
| 19 | ["total=i", ""], | ||||||||||||||||||||||||||||||||
| 20 | ["id=s@", ""], | ||||||||||||||||||||||||||||||||
| 21 | [ | ||||||||||||||||||||||||||||||||
| 22 | "id-file=s", | ||||||||||||||||||||||||||||||||
| 23 | "A line-delimited file containing the id's to include in the conversion. Other records will be ignored." | ||||||||||||||||||||||||||||||||
| 24 | ], | ||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||
| 28 | 15 | ▶ | sub command { | ||||||||||||||||||||||||||||||
|
Subroutine
command: called CC=11 SCAR=24.3
Pod
documented
| |||||||||||||||||||||||||||||||||
| 29 | 15 | my ($self, $opts, $args) = @_; | |||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||
| 31 | 15 | my ($from_args, $from_opts, $into_args, $into_opts) | |||||||||||||||||||||||||||||||
| 32 | = $self->_parse_options($args); | ||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||
| 34 | 15 | my $from = Catmandu->importer($from_args->[0], $from_opts); | |||||||||||||||||||||||||||||||
| 35 | 14 | my $into = Catmandu->exporter($into_args->[0], $into_opts); | |||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||
| 37 | 12 | ▶ | if ($opts->id // $opts->id_file) { | ||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%2/3
$opts->id // $opts->id_file
MC/DC50%1/2
$opts->id // $opts->id_file
$opts->id
$opts->id_file
Truth table66%2/3
A // B
A= $opts->idB= $opts->id_file
| |||||||||||||||||||||||||||||||||
| 38 | 1 | my $id_map = {}; | |||||||||||||||||||||||||||||||
| 39 | 1 | ▶ | if (my $ids = $opts->id) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 40 | 0 | $id_map->{$_} = 1 for @$ids; | |||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||
| 43 | Catmandu->importer('Text', file => $opts->id_file)->each( | ||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | sub { | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 45 | 3 | $id_map->{$_[0]->{text}} = 1; | |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||
| 47 | 1 | ); | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | $from = $from->select( | ||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub {defined $_[0]->{_id} && exists $id_map->{$_[0]->{_id}}}); | ||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||
| 52 | ▶ | elsif ($opts->start // $opts->total) { | |||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts->start // $opts->total
MC/DC50%1/2
$opts->start // $opts->total
$opts->start
$opts->total
Truth table66%2/3
A // B
A= $opts->startB= $opts->total
| |||||||||||||||||||||||||||||||||
| 53 | 1 | $from = $from->slice($opts->start, $opts->total); | |||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||
| 56 | 12 | ▶ | if ($opts->fix) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 57 | 5 | $from = $self->_build_fixer($opts)->fix($from); | |||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 9 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 61 | 2 | $from = $from->benchmark; | |||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 9 | my $n = $into->add_many($from); | |||||||||||||||||||||||||||||||
| 65 | 7 | $into->commit; | |||||||||||||||||||||||||||||||
| 66 | 7 | ▶ | if ($opts->verbose) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 67 | 2 | ▶ | say STDERR $n == 1 ? "converted 1 item" : "converted $n items"; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 68 | 2 | say STDERR "done"; | |||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 14 | 1; | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | __END__ | ||||||||||||||||||||||||||||||||