| 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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
@$args and $args->[0] eq "to"
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"
| |||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||
| 88 | # TODO: don't duplicate argument parsing | ||||||||||||||||||||||||||||||||||
| 89 | 1 | ▶ | for (my $i = 1; $i < @$args; $i++) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 90 | 1 | my $arg = $args->[$i]; | |||||||||||||||||||||||||||||||||
| 91 | 1 | ▶ | if ($arg =~ s/^-+//) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 92 | 0 | $arg =~ s/-/_/g; | |||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | if ($arg eq 'fix') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | push @{$into_opts->{$arg} ||= []}, $args->[++$i]; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$into_opts->{$arg} ||= []
MC/DC0%0/1
$into_opts->{$arg} ||= []
$into_opts->{$arg}
Truth table0%0/2
A
A= $into_opts->{$arg}
| |||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
@$into_args or %$into_opts
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
| |||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||