line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
14
|
|
|
14
|
|
147176
|
|
|
14
|
|
|
|
|
31
|
|
|
14
|
|
|
|
|
93
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use parent 'Catmandu::Cmd'; |
7
|
14
|
|
|
14
|
|
93
|
use Catmandu; |
|
14
|
|
|
|
|
53
|
|
|
14
|
|
|
|
|
81
|
|
8
|
14
|
|
|
14
|
|
1004
|
use Catmandu::Util qw(array_includes); |
|
14
|
|
|
|
|
26
|
|
|
14
|
|
|
|
|
77
|
|
9
|
14
|
|
|
14
|
|
2658
|
use namespace::clean; |
|
14
|
|
|
|
|
40
|
|
|
14
|
|
|
|
|
659
|
|
10
|
14
|
|
|
14
|
|
83
|
|
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
78
|
|
11
|
|
|
|
|
|
|
( |
12
|
|
|
|
|
|
|
["verbose|v", ""], |
13
|
|
|
|
|
|
|
["fix=s@", ""], |
14
|
15
|
|
|
15
|
1
|
169
|
["var=s%", ""], |
15
|
|
|
|
|
|
|
["preprocess|pp", ""], |
16
|
|
|
|
|
|
|
["start=i", ""], |
17
|
|
|
|
|
|
|
["total=i", ""], |
18
|
|
|
|
|
|
|
["id=s@", ""], |
19
|
|
|
|
|
|
|
[ |
20
|
|
|
|
|
|
|
"id-file=s", |
21
|
|
|
|
|
|
|
"A line-delimited file containing the id's to include in the conversion. Other records will be ignored." |
22
|
|
|
|
|
|
|
], |
23
|
|
|
|
|
|
|
); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
my ($self, $opts, $args) = @_; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my ($from_args, $from_opts, $into_args, $into_opts) |
29
|
15
|
|
|
15
|
1
|
34
|
= $self->_parse_options($args); |
30
|
|
|
|
|
|
|
|
31
|
15
|
|
|
|
|
68
|
my $from = Catmandu->importer($from_args->[0], $from_opts); |
32
|
|
|
|
|
|
|
my $into = Catmandu->exporter($into_args->[0], $into_opts); |
33
|
|
|
|
|
|
|
|
34
|
15
|
|
|
|
|
78
|
if ($opts->id // $opts->id_file) { |
35
|
14
|
|
|
|
|
186
|
my $id_map = {}; |
36
|
|
|
|
|
|
|
if (my $ids = $opts->id) { |
37
|
12
|
100
|
66
|
|
|
119
|
$id_map->{$_} = 1 for @$ids; |
|
|
100
|
66
|
|
|
|
|
38
|
1
|
|
|
|
|
11
|
} |
39
|
1
|
50
|
|
|
|
4
|
else { |
40
|
0
|
|
|
|
|
0
|
Catmandu->importer('Text', file => $opts->id_file)->each( |
41
|
|
|
|
|
|
|
sub { |
42
|
|
|
|
|
|
|
$id_map->{$_[0]->{text}} = 1; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
); |
45
|
3
|
|
|
3
|
|
11
|
} |
46
|
|
|
|
|
|
|
$from = $from->select( |
47
|
1
|
|
|
|
|
7
|
sub {defined $_[0]->{_id} && exists $id_map->{$_[0]->{_id}}}); |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ($opts->start // $opts->total) { |
50
|
1
|
50
|
|
4
|
|
44
|
$from = $from->slice($opts->start, $opts->total); |
|
4
|
|
|
|
|
31
|
|
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
1
|
|
|
|
|
21
|
if ($opts->fix) { |
54
|
|
|
|
|
|
|
$from = $self->_build_fixer($opts)->fix($from); |
55
|
|
|
|
|
|
|
} |
56
|
12
|
100
|
|
|
|
219
|
|
57
|
5
|
|
|
|
|
71
|
if ($opts->verbose) { |
58
|
|
|
|
|
|
|
$from = $from->benchmark; |
59
|
|
|
|
|
|
|
} |
60
|
9
|
100
|
|
|
|
89
|
|
61
|
2
|
|
|
|
|
22
|
my $n = $into->add_many($from); |
62
|
|
|
|
|
|
|
$into->commit; |
63
|
|
|
|
|
|
|
if ($opts->verbose) { |
64
|
9
|
|
|
|
|
84
|
say STDERR $n == 1 ? "converted 1 item" : "converted $n items"; |
65
|
7
|
|
|
|
|
134
|
say STDERR "done"; |
66
|
7
|
100
|
|
|
|
37
|
} |
67
|
2
|
50
|
|
|
|
136
|
} |
68
|
2
|
|
|
|
|
55
|
|
69
|
|
|
|
|
|
|
1; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=pod |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Catmandu::Cmd::convert - convert items |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 EXAMPLES |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
catmandu convert <IMPORTER> <OPTIONS> to <EXPORTER> <OPTIONS> |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
cat books.json | catmandu convert JSON to CSV --fields id,title |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
catmandu help importer JSON |
85
|
|
|
|
|
|
|
catmandu help exporter YAML |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=cut |