line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use Catmandu::Sane; |
3
|
14
|
|
|
14
|
|
134187
|
|
|
14
|
|
|
|
|
43
|
|
|
14
|
|
|
|
|
95
|
|
4
|
|
|
|
|
|
|
our $VERSION = '1.2019'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
use parent 'Catmandu::Cmd'; |
7
|
14
|
|
|
14
|
|
94
|
use Catmandu; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
80
|
|
8
|
14
|
|
|
14
|
|
973
|
use namespace::clean; |
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
77
|
|
9
|
14
|
|
|
14
|
|
3056
|
|
|
14
|
|
|
|
|
28
|
|
|
14
|
|
|
|
|
83
|
|
10
|
|
|
|
|
|
|
( |
11
|
|
|
|
|
|
|
["verbose|v", ""], |
12
|
|
|
|
|
|
|
["fix=s@", ""], |
13
|
1
|
|
|
1
|
1
|
18
|
["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
|
|
|
|
|
8
|
|
31
|
1
|
|
|
|
|
11
|
if ($opts->start // $opts->total) { |
32
|
1
|
|
|
|
|
9
|
$from = $from->slice($opts->start, $opts->total); |
33
|
|
|
|
|
|
|
} |
34
|
1
|
50
|
33
|
|
|
20
|
if ($opts->fix) { |
35
|
0
|
|
|
|
|
0
|
$from = $self->_build_fixer($opts)->fix($from); |
36
|
|
|
|
|
|
|
} |
37
|
1
|
50
|
|
|
|
14
|
if ($opts->verbose) { |
38
|
0
|
|
|
|
|
0
|
$from = $from->benchmark; |
39
|
|
|
|
|
|
|
} |
40
|
1
|
50
|
|
|
|
8
|
|
41
|
1
|
|
|
|
|
8
|
my $tx = sub { |
42
|
|
|
|
|
|
|
if ($opts->delete) { |
43
|
|
|
|
|
|
|
$into->delete_all; |
44
|
|
|
|
|
|
|
$into->commit; |
45
|
1
|
50
|
|
1
|
|
3
|
} |
46
|
0
|
|
|
|
|
0
|
|
47
|
0
|
|
|
|
|
0
|
my $n = $into->add_many($from); |
48
|
|
|
|
|
|
|
$into->commit; |
49
|
|
|
|
|
|
|
if ($opts->verbose) { |
50
|
1
|
|
|
|
|
5
|
say STDERR $n == 1 ? "imported 1 item" : "imported $n items"; |
51
|
1
|
|
|
|
|
31
|
say STDERR "done"; |
52
|
1
|
50
|
|
|
|
3
|
} |
53
|
1
|
50
|
|
|
|
73
|
}; |
54
|
1
|
|
|
|
|
78
|
|
55
|
|
|
|
|
|
|
if ($opts->transaction) { |
56
|
1
|
|
|
|
|
14
|
$self->usage_error("Bag isn't transactional") |
57
|
|
|
|
|
|
|
if !$into->store->does('Catmandu::Transactional'); |
58
|
1
|
50
|
|
|
|
4
|
$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 |