Catmandu/Cmd/import.pm

filter: Statementstmt 85.3% 35 / 41 Branchbran 43.7% 7 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 8 / 8 Podpod 100% 3 / 3 totaltotal 73.9% 54 / 73 CC 10 SCAR 17.2
CC
10
Cov
72%
command
10.0
__ANON__
4.7
BEGIN
1.0
CRAP 5.6
« Catmandu/Interactive.pm ↑ Summary Catmandu/Fix/Bind/hashmap.pm »
1 package Catmandu::Cmd::import;
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 namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 ▶sub command_opt_spec {
Subroutine command_opt_spec: called CC=1 SCAR=0.0
Pod documented
12 (
13 1 ["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 1 ▶sub validate_args {
Subroutine validate_args: called CC=1 SCAR=0.0
Pod documented
25 1 my ($self, $opt, $args) = @_;
26 1 return;
27 }
28  
29 1 ▶sub command {
Subroutine command: called CC=7 SCAR=23.1
Pod documented
30 1 my ($self, $opts, $args) = @_;
31  
32 1 my ($from_args, $from_opts, $into_args, $into_opts)
33 = $self->_parse_options($args);
34  
35 1 my $from = Catmandu->importer($from_args->[0], $from_opts);
36 1 my $into_bag = delete $into_opts->{bag};
37 1 my $into = Catmandu->store($into_args->[0], $into_opts)->bag($into_bag);
38  
39 1 ▶ if ($opts->start // $opts->total) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->start // $opts->total) 0 1 1
Condition33%1/3
$opts->start // $opts->total
l!l&&r!l&&!r
001
MC/DC0%0/2
$opts->start // $opts->total
$opts->start $opts->total
Truth table33%1/3
A // B
A= $opts->startB= $opts->total
ABresult
1X1
011
000
40 0 $from = $from->slice($opts->start, $opts->total);
41 }
42 1 ▶ if ($opts->fix) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->fix) 0 1 1
43 0 $from = $self->_build_fixer($opts)->fix($from);
44 }
45 1 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 1 0 1
46 1 $from = $from->benchmark;
47 }
48  
49 1 ▶ my $tx = sub {
Subroutine __ANON__: called CC=4 SCAR=15.5
50 1 ▶ if ($opts->delete) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->delete) 0 1 1
51 0 $into->delete_all;
52 0 $into->commit;
53 }
54  
55 1 my $n = $into->add_many($from);
56 1 $into->commit;
57 1 ▶ if ($opts->verbose) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->verbose) 1 0 1
58 1 ▶ say STDERR $n == 1 ? "imported 1 item" : "imported $n items";
Branch: 1 branch
BranchTrueFalseTotal
$n == 1 ? : 0 1 1
59 1 say STDERR "done";
60 }
61 1 };
62  
63 1 ▶ if ($opts->transaction) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->transaction) { } 0 1 1
64 0 ▶ $self->usage_error("Bag isn't transactional")
Branch: 1 branch
BranchTrueFalseTotal
unless $into->store->does("Catmandu::Transactional") 0 0 0
65 if !$into->store->does('Catmandu::Transactional');
66 0 $into->store->transaction($tx);
67 }
68 else {
69 1 $tx->();
70 }
71 }
72  
73 14 1;
74  
75 __END__
« Catmandu/Interactive.pm ↑ Summary Catmandu/Fix/Bind/hashmap.pm »