blib/lib/Catmandu/Cmd/info.pm

filter: Statementstmt 90.7% 59 / 65 Branchbran 78.5% 22 / 28 Conditioncond 50.0% 4 / 8 MC/DCmcdc 40.0% 2 / 5 Subroutinesub 100% 9 / 9 Podpod 66.6% 2 / 3 totaltotal 83.0% 98 / 118 CC 19 SCAR 27.7
CC
19
Cov
84%
command
22.4
BEGIN
1.0
BEGIN
1.0
CRAP 16.0
« blib/lib/Catmandu/Fix/import.pm ↑ Summary blib/lib/Catmandu/Util.pm »
1 package Catmandu::Cmd::info;
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;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 13 ▶use Catmandu::Util qw(pod_section);
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_opt_spec {
13 (
14 7 ▶ ["all", "show all module on this server"],
Subroutine command_opt_spec: called CC=1 SCAR=0.0
Pod documented
15 ["exporters", "show all Catmandu exporters"],
16 ["importers", "show all Catmandu importers"],
17 ["fixes", "show all Catmandu fixes"],
18 ["stores", "show all Catmandu stores"],
19 ["validators", "show all Catmandu validators"],
20 ["namespace=s", "search by namespace"],
21 ["max_depth=i", "maximum depth to search for modules"],
22 [
23 "inc=s@",
24 'override included directories (defaults to @INC)',
25 {default => [@INC]}
26 ],
27 ["verbose|v", ""]
28 );
29 }
30  
31 sub add_about {
32 720 ▶ my $item = shift;
Subroutine add_about: called CC=1 SCAR=0.0
Pod undocumented
33 720 my $name = pod_section($item->{file}, 'NAME');
34 720 $name =~ s/[^-]+(\s*-?\s*)?//;
35 720 $name =~ s/\n/ /mg;
36 720 chomp $name;
37 720 $item->{about} = $name;
38 720 $item;
39 }
40  
41 sub command {
42 7 ▶ my ($self, $opts, $args) = @_;
Subroutine command: called CC=19 SCAR=31.1
Pod documented
43 7 my $verbose = $opts->verbose;
44  
45 7 ▶ if (defined $opts->{namespace}) {
Branch: 7 branches
BranchTrueFalseTotal
if (defined $opts->{'namespace'}) { } 0 7 7
elsif ($opts->{'all'}) { } 0 7 7
elsif ($opts->{'exporters'}) { } 1 6 7
elsif ($opts->{'importers'}) { } 1 5 6
elsif ($opts->{'fixes'}) { } 2 3 5
elsif ($opts->{'stores'}) { } 1 2 3
elsif ($opts->{'validators'}) { } 1 1 2
46 }
47 elsif ($opts->{all}) {
48 0 delete $opts->{all};
49 }
50 elsif ($opts->{exporters}) {
51 1 delete $opts->{exporters};
52 1 $opts->{namespace} = 'Catmandu::Exporter';
53 }
54 elsif ($opts->{importers}) {
55 1 delete $opts->{importers};
56 1 $opts->{namespace} = 'Catmandu::Importer';
57 }
58 elsif ($opts->{fixes}) {
59 2 delete $opts->{fixes};
60 2 $opts->{namespace} = 'Catmandu::Fix';
61 }
62 elsif ($opts->{stores}) {
63 1 delete $opts->{stores};
64 1 $opts->{namespace} = 'Catmandu::Store';
65 }
66 elsif ($opts->{validators}) {
67 1 delete $opts->{stores};
68 1 $opts->{namespace} = 'Catmandu::Validator';
69 }
70 else {
71 1 $opts->{namespace} = [qw(Catmandu)];
72 }
73  
74 7 ▶ my $from_opts = {fix => [sub {add_about(@_)}]};
Subroutine __ANON__: called CC=1 SCAR=0.0
75  
76 7 for my $key (qw(inc namespace max_depth)) {
77 21 ▶ $from_opts->{$key} = $opts->$key if defined $opts->$key;
Branch: 1 branch
BranchTrueFalseTotal
if defined $opts->$key 14 7 21
78 }
79  
80 7 my $from = Catmandu->importer('Modules', $from_opts);
81  
82 7 my $into_args = [];
83 7 my $into_opts = {};
84 7 my $into;
85  
86 7 ▶ if (@$args && $args->[0] eq 'to') {
Branch: 1 branch
BranchTrueFalseTotal
if (@$args and $args->[0] eq "to") 1 6 7
Condition66%2/3
@$args and $args->[0] eq "to"
!ll&&!rl&&r
601
MC/DC50%1/2
@$args and $args->[0] eq "to"
@$args $args->[0] eq "to"
Truth table66%2/3
A and B
A= @$argsB= $args->[0] eq "to"
ABresult
0X0
100
111
87  
88 # TODO: don't duplicate argument parsing
89 1 ▶ for (my $i = 1; $i < @$args; $i++) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i < @$args) 1 1 2
90 1 my $arg = $args->[$i];
91 1 ▶ if ($arg =~ s/^-+//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ s/^-+//) { } 0 1 1
92 0 $arg =~ s/-/_/g;
93 0 ▶ if ($arg eq 'fix') {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg eq 'fix') { } 0 0 0
94 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
95 }
96 else {
97 0 $into_opts->{$arg} = $args->[++$i];
98 }
99 }
100 else {
101 1 push @$into_args, $arg;
102 }
103 }
104 }
105  
106 7 ▶ if (@$into_args || %$into_opts) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$into_args or %$into_opts) { } 1 6 7
Condition66%2/3
@$into_args or %$into_opts
l!l&&r!l&&!r
106
MC/DC50%1/2
@$into_args or %$into_opts
@$into_args %$into_opts
Truth table66%2/3
A or B
A= @$into_argsB= %$into_opts
ABresult
1X1
011
000
107 1 $into = Catmandu->exporter($into_args->[0], $into_opts);
108 1 $into->add_many($from);
109 1 $into->commit;
110 }
111 else {
112 6 my $cols = [qw(name version about)];
113 6 ▶ push @$cols, 'file' if $opts->verbose;
Branch: 1 branch
BranchTrueFalseTotal
if $opts->verbose 0 6 6
114 6 $from->format(cols => $cols);
115 }
116 }
117  
118 13 1;
119  
120 __END__
121  
122 =pod
123  
124 =head1 NAME
125  
126 Catmandu::Cmd::info - list installed Catmandu modules
127  
128 =head1 DESCRIPTION
129  
130 This L<Catmandu::Cmd> uses L<Catmandu::Importer::Modules> to list all modules.
131 By default modules are listed in tabular form, like L<Catmandu::Exporter::Table>.
132  
133 =head1 EXAMPLES
134  
135 catmandu info --exporters
136 catmandu info --importers
137 catmandu info --fixes
138 catmandu info --stores
139 catmandu info --validators
140 catmandu info --namespace=Catmandu
141 catmandu info --all
142  
143 # export list of exporter modules to JSON
144 catmandu info --exporters to JSON
145  
146 =cut
« blib/lib/Catmandu/Fix/import.pm ↑ Summary blib/lib/Catmandu/Util.pm »