line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
14
|
|
|
14
|
|
132412
|
|
|
14
|
|
|
|
|
45
|
|
|
14
|
|
|
|
|
88
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2018'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use parent 'Catmandu::Cmd'; |
7
|
14
|
|
|
14
|
|
92
|
use Catmandu; |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
72
|
|
8
|
14
|
|
|
14
|
|
879
|
use namespace::clean; |
|
14
|
|
|
|
|
41
|
|
|
14
|
|
|
|
|
78
|
|
9
|
14
|
|
|
14
|
|
2737
|
|
|
14
|
|
|
|
|
40
|
|
|
14
|
|
|
|
|
73
|
|
10
|
|
|
|
|
|
|
( |
11
|
|
|
|
|
|
|
["verbose|v", ""], |
12
|
|
|
|
|
|
|
["fix=s@", ""], |
13
|
1
|
|
|
1
|
1
|
28
|
["var=s%", ""], |
14
|
|
|
|
|
|
|
["preprocess|pp", ""], |
15
|
|
|
|
|
|
|
["start=i", ""], |
16
|
|
|
|
|
|
|
["total=i", ""], |
17
|
|
|
|
|
|
|
["delete", "delete existing items first"], |
18
|
|
|
|
|
|
|
["transaction|tx", "wrap in a transaction"], |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my ($self, $opts, $args) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my ($from_args, $from_opts, $into_args, $into_opts) |
25
|
1
|
|
|
1
|
1
|
3
|
= $self->_parse_options($args); |
26
|
|
|
|
|
|
|
|
27
|
1
|
|
|
|
|
5
|
my $from = Catmandu->importer($from_args->[0], $from_opts); |
28
|
|
|
|
|
|
|
my $into_bag = delete $into_opts->{bag}; |
29
|
|
|
|
|
|
|
my $into = Catmandu->store($into_args->[0], $into_opts)->bag($into_bag); |
30
|
1
|
|
|
|
|
21
|
|
31
|
1
|
|
|
|
|
12
|
if ($opts->start // $opts->total) { |
32
|
1
|
|
|
|
|
9
|
$from = $from->slice($opts->start, $opts->total); |
33
|
|
|
|
|
|
|
} |
34
|
1
|
50
|
33
|
|
|
17
|
if ($opts->fix) { |
35
|
0
|
|
|
|
|
0
|
$from = $self->_build_fixer($opts)->fix($from); |
36
|
|
|
|
|
|
|
} |
37
|
1
|
50
|
|
|
|
16
|
if ($opts->verbose) { |
38
|
0
|
|
|
|
|
0
|
$from = $from->benchmark; |
39
|
|
|
|
|
|
|
} |
40
|
1
|
50
|
|
|
|
8
|
|
41
|
1
|
|
|
|
|
9
|
my $tx = sub { |
42
|
|
|
|
|
|
|
if ($opts->delete) { |
43
|
|
|
|
|
|
|
$into->delete_all; |
44
|
|
|
|
|
|
|
$into->commit; |
45
|
1
|
50
|
|
1
|
|
5
|
} |
46
|
0
|
|
|
|
|
0
|
|
47
|
0
|
|
|
|
|
0
|
my $n = $into->add_many($from); |
48
|
|
|
|
|
|
|
$into->commit; |
49
|
|
|
|
|
|
|
if ($opts->verbose) { |
50
|
1
|
|
|
|
|
8
|
say STDERR $n == 1 ? "imported 1 item" : "imported $n items"; |
51
|
1
|
|
|
|
|
24
|
say STDERR "done"; |
52
|
1
|
50
|
|
|
|
5
|
} |
53
|
1
|
50
|
|
|
|
84
|
}; |
54
|
1
|
|
|
|
|
76
|
|
55
|
|
|
|
|
|
|
if ($opts->transaction) { |
56
|
1
|
|
|
|
|
6
|
$self->usage_error("Bag isn't transactional") |
57
|
|
|
|
|
|
|
if !$into->store->does('Catmandu::Transactional'); |
58
|
1
|
50
|
|
|
|
6
|
$into->store->transaction($tx); |
59
|
0
|
0
|
|
|
|
0
|
} |
60
|
|
|
|
|
|
|
else { |
61
|
0
|
|
|
|
|
0
|
$tx->(); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
1
|
|
|
|
|
5
|
|
65
|
|
|
|
|
|
|
1; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=pod |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head1 NAME |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
Catmandu::Cmd::import - import items into a store |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 EXAMPLES |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
catmandu import <IMPORTER> <OPTIONS> to <STORE> <OPTIONS> |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
catmandu import YAML to MongoDB --database-name items --bag book < books.yml |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
catmandu help importer YAML |
81
|
|
|
|
|
|
|
catmandu help importer MongoDB |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=cut |