blib/lib/Catmandu/Cmd/config.pm

filter: Statementstmt 84.6% 33 / 39 Branchbran 64.2% 9 / 14 Conditioncond 42.8% 6 / 14 MC/DCmcdc 12.5% 1 / 8 Subroutinesub 100% 6 / 6 Podpod 100% 1 / 1 totaltotal 68.2% 56 / 82 CC 13 SCAR 28.0
CC
13
Cov
72%
command
22.3
BEGIN
1.0
BEGIN
1.0
CRAP 16.4
« blib/lib/Catmandu/Searchable.pm ↑ Summary blib/lib/Catmandu/Fix/import.pm »
1 package Catmandu::Cmd::config;
2  
3 13 ▶use Catmandu::Sane;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 13 our $VERSION = '1.0201_02';
6  
7 13 ▶use parent 'Catmandu::Cmd';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use Catmandu::Util qw(data_at);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Catmandu;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 13 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub command {
13 2 ▶ my ($self, $opts, $args) = @_;
Subroutine command: called CC=13 SCAR=31.0
Pod documented
14 2 my $path;
15 2 my $into_args = [];
16 2 my $into_opts = {};
17 2 my $into;
18  
19 2 ▶ if (@$args == 1 || (@$args > 1 && $args->[1] eq 'to')) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args == 1 or @$args > 1 and $args->[1] eq "to") 1 1 2
Condition66%4/6
@$args == 1 or @$args > 1 and $args->[1] eq "to"
l!l&&r!l&&!r
011
@$args > 1 and $args->[1] eq "to"
!ll&&!rl&&r
011
MC/DC33%1/3
@$args == 1 or @$args > 1 and $args->[1] eq "to"
@$args == 1 @$args > 1 $args->[1] eq "to"
Truth table50%2/4
A or B and C
A= @$args == 1B= @$args > 1C= $args->[1] eq "to"
ABCresult
1XX1
0111
00X0
0100
20 1 $path = shift @$args;
21 }
22  
23 2 ▶ if (@$args && $args->[0] eq 'to') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args and $args->[0] eq "to") 2 0 2
Condition33%1/3
@$args and $args->[0] eq "to"
!ll&&!rl&&r
002
MC/DC0%0/2
@$args and $args->[0] eq "to"
@$args $args->[0] eq "to"
Truth table33%1/3
A and B
A= @$argsB= $args->[0] eq "to"
ABresult
0X0
100
111
24 2 ▶ for (my $i = 1; $i < @$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$args) 2 2 4
25 2 my $arg = $args->[$i];
26 2 ▶ if ($arg =~ s/^-+//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ s/^-+//) { } 0 2 2
27 0 $arg =~ s/-/_/g;
28 0 ▶ if ($arg eq 'fix') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq 'fix') { } 0 0 0
29 0 ▶ push @{$into_opts->{$arg} ||= []}, $args->[++$i];
Condition0%0/2
$into_opts->{$arg} ||= []
l!l
00
MC/DC0%0/1
$into_opts->{$arg} ||= []
$into_opts->{$arg}
Truth table0%0/2
A
A= $into_opts->{$arg}
Aresult
11
00
30 }
31 else {
32 0 $into_opts->{$arg} = $args->[++$i];
33 }
34 }
35 else {
36 2 push @$into_args, $arg;
37 }
38 }
39 }
40  
41 2 ▶ if (@$into_args || %$into_opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$into_args or %$into_opts) { } 2 0 2
Condition33%1/3
@$into_args or %$into_opts
l!l&&r!l&&!r
200
MC/DC0%0/2
@$into_args or %$into_opts
@$into_args %$into_opts
Truth table33%1/3
A or B
A= @$into_argsB= %$into_opts
ABresult
1X1
011
000
42 2 $into = Catmandu->exporter($into_args->[0], $into_opts);
43 }
44 else {
45 0 $into = Catmandu->exporter('JSON', pretty => 1, array => 0);
46 }
47  
48 2 ▶ $into->add(
Branch: 1 branch
BranchTrueFalseTotal
defined $path ? : 1 1 2
49 defined $path ? data_at($path, Catmandu->config) : Catmandu->config);
50 2 $into->commit;
51 }
52  
53 13 1;
54  
55 __END__
56  
57 =pod
58  
59 =head1 NAME
60  
61 Catmandu::Cmd::config - export the Catmandu config
62  
63 =head1 EXAMPLES
64  
65 # export config to JSON
66 catmandu config
67 # or any other Catmandu::Exporter
68 catmandu config to YAML --fix 'delete_field(password)'
69 # export only part of the config file
70 catmandu config my.prefix to CSV
71  
72 =cut
« blib/lib/Catmandu/Searchable.pm ↑ Summary blib/lib/Catmandu/Fix/import.pm »