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