| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||
| 2 | package MOP4Import::Util::Inspector; | ||||||||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use constant DEBUG => $ENV{DEBUG_MOP4IMPORT}; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||
| 9 | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | print STDERR "Using (file '" . __FILE__ . "')\n" if DEBUG and DEBUG >= 2 | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 11 | } | ||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||
| 13 | 7 | use MOP4Import::Base::CLI_JSON -as_base | |||||||||||||||||||||||||||||||||||||||
| 14 | , [fields => | ||||||||||||||||||||||||||||||||||||||||
| 15 | [lib => | ||||||||||||||||||||||||||||||||||||||||
| 16 | doc => "library directory list. SCALAR, ARRAY or ':' separated STRING", | ||||||||||||||||||||||||||||||||||||||||
| 17 | zsh_completer => ": :_directories", | ||||||||||||||||||||||||||||||||||||||||
| 18 | ] | ||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | ]; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||
| 21 | 7 | ▶ | use MOP4Import::NamedCodeAttributes (); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | use MOP4Import::Util qw/terse_dump fields_hash fields_symbol | |||||||||||||||||||||||||||||||||||||||
| 24 | maybe_fields_hash | ||||||||||||||||||||||||||||||||||||||||
| 25 | 7 | ▶ | take_hash_opts_maybe/; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 26 | 7 | ▶ | use MOP4Import::Util::FindMethods; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | ▶ | use List::Util (); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||
| 30 | sub describe_commands_of { | ||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | (my MY $self, my $classOrObj) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
describe_commands_of: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | my $class = ref $classOrObj || $self->require_module($classOrObj); | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $classOrObj || $self->require_module($classOrObj)
MC/DC0%0/2
ref $classOrObj || $self->require_module($classOrObj)
ref $classOrObj
$self->require_module($classOrObj)
Truth table33%1/3
A || B
A= ref $classOrObjB= $self->require_module($classOrObj)
| |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | map {$self->format_command_of($class, $_)} $self->list_commands_of($class); | |||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||
| 37 | sub describe_options_of { | ||||||||||||||||||||||||||||||||||||||||
| 38 | 6 | ▶ | (my MY $self, my $classOrObj) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
describe_options_of: called CC=4 SCAR=14.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 39 | 6 | ▶ | my $class = ref $classOrObj || $self->require_module($classOrObj); | ||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $classOrObj || $self->require_module($classOrObj)
MC/DC0%0/2
ref $classOrObj || $self->require_module($classOrObj)
ref $classOrObj
$self->require_module($classOrObj)
Truth table33%1/3
A || B
A= ref $classOrObjB= $self->require_module($classOrObj)
| |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||
| 41 | 6 | my @msg; | |||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||
| 43 | 6 | my @options = $self->group_options_of($class); | |||||||||||||||||||||||||||||||||||||||
| 44 | 6 | my $maxlen = $self->max_option_length($class); | |||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | foreach my $group (@options) { | |||||||||||||||||||||||||||||||||||||||
| 47 | 7 | my ($pkg, @fields) = @$group; | |||||||||||||||||||||||||||||||||||||||
| 48 | 7 | push @msg, <<END; | |||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||
| 50 | Options from $pkg: | ||||||||||||||||||||||||||||||||||||||||
| 51 | END | ||||||||||||||||||||||||||||||||||||||||
| 52 | 7 | foreach my FieldSpec $fs (@fields) { | |||||||||||||||||||||||||||||||||||||||
| 53 | 31 | push @msg, $self->format_option($fs, $maxlen); | |||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | @msg; | |||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||
| 59 | sub list_commands_of { | ||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | ▶ | my ($self, $pack) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_commands_of: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 61 | 7 | $self->require_module($pack); | |||||||||||||||||||||||||||||||||||||||
| 62 | 7 | ▶ | FindMethods($pack, sub {s/^cmd_//}); | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||
| 65 | sub format_command_of { | ||||||||||||||||||||||||||||||||||||||||
| 66 | 9 | ▶ | my ($self, $class, $name) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_command_of: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 67 | 9 | ▶ | " ".join(" " | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->info_command_doc_of($class, $name) // ""
MC/DC100%1/1
$self->info_command_doc_of($class, $name) // ""
$self->info_command_doc_of($class, $name)
Truth table100%2/2
A
A= $self->info_command_doc_of($class, $name)
| |||||||||||||||||||||||||||||||||||||||||
| 68 | , $name | ||||||||||||||||||||||||||||||||||||||||
| 69 | , $self->info_command_doc_of($class, $name) // '')."\n"; | ||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||
| 72 | sub list_options_of { | ||||||||||||||||||||||||||||||||||||||||
| 73 | 13 | ▶ | my ($self, $pack) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_options_of: called CC=4 SCAR=19.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 74 | 13 | $self->require_module($pack); | |||||||||||||||||||||||||||||||||||||||
| 75 | 13 | my $symbol = fields_symbol($pack); | |||||||||||||||||||||||||||||||||||||||
| 76 | 13 | ▶ | if (my $array = *{$symbol}{ARRAY}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 77 | 13 | List::Util::uniq(@$array, $self->list_options_onconfigure_of($pack)) | |||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | elsif (my $hash = *{$symbol}{HASH}) { | |||||||||||||||||||||||||||||||||||||||
| 80 | 0 | sort keys %$hash; | |||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||
| 82 | elsif ($pack->can("meta")) { | ||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $pack->meta->get_attribute_list | |||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||
| 85 | else { | ||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | (); | |||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||
| 90 | sub list_options_onconfigure_of { | ||||||||||||||||||||||||||||||||||||||||
| 91 | 13 | ▶ | my ($self, $pack) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_options_onconfigure_of: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 92 | 13 | $self->require_module($pack); | |||||||||||||||||||||||||||||||||||||||
| 93 | 13 | my $isa = mro::get_linear_isa($pack); | |||||||||||||||||||||||||||||||||||||||
| 94 | 13 | my %dup; | |||||||||||||||||||||||||||||||||||||||
| 95 | map { | ||||||||||||||||||||||||||||||||||||||||
| 96 | 13 | my $symtab = MOP4Import::Util::symtab($_); | |||||||||||||||||||||||||||||||||||||||
| 97 | map { | ||||||||||||||||||||||||||||||||||||||||
| 98 | 64 | ▶ | if (/^onconfigure_(\w+)$/ and not $dup{$1}++) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
/^onconfigure_(\w+)$/ and not $dup{$1}++
MC/DC100%2/2
/^onconfigure_(\w+)$/ and not $dup{$1}++
/^onconfigure_(\w+)$/
not $dup{$1}++
Truth table100%3/3
A and not(B)
A= /^onconfigure_(\w+)$/B= not $dup{$1}++
| |||||||||||||||||||||||||||||||||||||||||
| 99 | 20 | $1 | |||||||||||||||||||||||||||||||||||||||
| 100 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 101 | () | ||||||||||||||||||||||||||||||||||||||||
| 102 | 3375 | } | |||||||||||||||||||||||||||||||||||||||
| 103 | } sort keys %$symtab; | ||||||||||||||||||||||||||||||||||||||||
| 104 | } @$isa; | ||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||
| 107 | sub group_options_of { | ||||||||||||||||||||||||||||||||||||||||
| 108 | 6 | ▶ | my ($self, $pack, @opt_names) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
group_options_of: called CC=8 SCAR=21.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | $self->require_module($pack); | |||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | my $meta = $pack->can("meta") ? $pack->meta : undef; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | ▶ | @opt_names = $self->list_options_of($pack) unless @opt_names; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | my %package; | |||||||||||||||||||||||||||||||||||||||
| 113 | my @unknown; | ||||||||||||||||||||||||||||||||||||||||
| 114 | 6 | foreach my $name (@opt_names) { | |||||||||||||||||||||||||||||||||||||||
| 115 | 31 | ▶ | next unless $name =~ /^[a-z]/; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 116 | # FieldSpec もどきをここで作る | ||||||||||||||||||||||||||||||||||||||||
| 117 | 31 | ▶ | my FieldSpec $spec = $self->get_field_spec_of($pack, $name) or do { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | push @unknown, $name; | |||||||||||||||||||||||||||||||||||||||
| 119 | next | ||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | }; | |||||||||||||||||||||||||||||||||||||||
| 121 | 31 | push @{$package{$spec->{package}}}, $spec; | |||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||
| 124 | 6 | my $isa = mro::get_linear_isa($pack); | |||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||
| 126 | my @grouped = map { | ||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | ▶ | $package{$_} ? [$_, @{$package{$_}}] : (); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 128 | } @$isa; | ||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||
| 130 | 6 | ▶ | ((@unknown ? ['', @unknown] : ()), @grouped); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||
| 133 | sub get_field_spec_of { | ||||||||||||||||||||||||||||||||||||||||
| 134 | 31 | ▶ | (my MY $self, my ($pack, $name)) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_field_spec_of: called CC=6 SCAR=27.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 135 | 31 | $self->require_module($pack); | |||||||||||||||||||||||||||||||||||||||
| 136 | 31 | ▶ | if (my $fields = maybe_fields_hash($pack)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 137 | 31 | my $spec = $fields->{$name}; | |||||||||||||||||||||||||||||||||||||||
| 138 | 31 | ▶ | return $spec if ref $spec; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 139 | 3 | $self->get_field_spec_for_onconfigure($pack, $name) | |||||||||||||||||||||||||||||||||||||||
| 140 | } elsif (my $sub = $pack->can("meta")) { | ||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $attMeta = $sub->($pack)->get_attribute($name); | |||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my FieldSpec $spec = +{}; | |||||||||||||||||||||||||||||||||||||||
| 143 | 0 | $spec->{package} = $pack; | |||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $spec->{name} = $name; | |||||||||||||||||||||||||||||||||||||||
| 145 | 0 | ▶ | if (my $doc = $attMeta->{documentation}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | $spec->{doc} = $doc; | |||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||
| 148 | elsif ($doc = $attMeta->{isa}) { | ||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | $spec->{doc} = "isa $doc"; | |||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $spec; | |||||||||||||||||||||||||||||||||||||||
| 152 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | undef; | |||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||
| 157 | sub get_field_spec_for_onconfigure { | ||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | ▶ | (my MY $self, my ($pack, $name)) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_field_spec_for_onconfigure: called CC=3 SCAR=12.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | ▶ | my $code = $pack->can("onconfigure_$name") | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 160 | or return; | ||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||
| 162 | 3 | ▶ | if (my $atts = MOP4Import::NamedCodeAttributes->m4i_CODE_ATTR_dict($code)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 163 | 3 | $self->create_field_spec_from_code_attribute($pack, $name, $atts); | |||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||
| 165 | else { | ||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | +{package => $pack, name => $name}; | |||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||
| 170 | sub create_field_spec_from_code_attribute { | ||||||||||||||||||||||||||||||||||||||||
| 171 | 3 | ▶ | (my MY $self, my ($pack, $name, $atts)) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_field_spec_from_code_attribute: called CC=3 SCAR=11.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 172 | 3 | my FieldSpec $spec = +{}; | |||||||||||||||||||||||||||||||||||||||
| 173 | 3 | $spec->{package} = $pack; | |||||||||||||||||||||||||||||||||||||||
| 174 | 3 | $spec->{name} = $name; | |||||||||||||||||||||||||||||||||||||||
| 175 | 3 | ▶ | if ($atts->{Doc}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $spec->{doc} = $atts->{Doc}; | |||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||
| 178 | 3 | ▶ | if ($atts->{ZshCompleter}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $spec->{zsh_completer} = $atts->{ZshCompleter}; | |||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||
| 181 | 3 | $spec; | |||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||
| 184 | sub max_option_length { | ||||||||||||||||||||||||||||||||||||||||
| 185 | 6 | ▶ | my ($self, $pack) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
max_option_length: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | my $fields = fields_hash($pack); | |||||||||||||||||||||||||||||||||||||||
| 187 | 6 | my @name = grep {/^[a-z]/} $self->list_options_of($pack); | |||||||||||||||||||||||||||||||||||||||
| 188 | 6 | List::Util::max(map {length} @name); | |||||||||||||||||||||||||||||||||||||||
| 189 | } | ||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||
| 191 | sub format_option { | ||||||||||||||||||||||||||||||||||||||||
| 192 | 31 | ▶ | (my MY $self, my FieldSpec $fs, my $maxlen) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_option: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 193 | 31 | ▶ | my $len = ($maxlen // 16); | ||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$maxlen // 16
MC/DC0%0/1
$maxlen // 16
$maxlen
Truth table50%1/2
A
A= $maxlen
| |||||||||||||||||||||||||||||||||||||||||
| 194 | 31 | ▶ | sprintf " --%-${len}s %s\n", $fs->{name}, $fs->{doc} // ""; | ||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$fs->{"doc"} // ""
MC/DC100%1/1
$fs->{"doc"} // ""
$fs->{"doc"}
Truth table100%2/2
A
A= $fs->{"doc"}
| |||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||
| 197 | sub is_getter_of { | ||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | ▶ | my ($self, $pack, $subName) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_getter_of: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | my $fields = fields_hash($pack); | |||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | exists $fields->{$subName} && $pack->can($subName); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||
| 203 | sub info_command_doc_of { | ||||||||||||||||||||||||||||||||||||||||
| 204 | 10 | ▶ | my ($self, $class, $name) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
info_command_doc_of: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 205 | 10 | $self->info_method_doc_of($class, "cmd_$name"); | |||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||
| 208 | sub info_method_doc_of { | ||||||||||||||||||||||||||||||||||||||||
| 209 | 10 | ▶ | my ($self, $class, $name, $allow_missing) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
info_method_doc_of: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||
| 211 | 10 | ▶ | my $atts = $self->info_code_attributes_of($class, $name, $allow_missing) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 212 | or return undef; | ||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||
| 214 | 10 | $atts->{Doc}; | |||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||
| 217 | sub info_code_attribute { | ||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my ($self, $attName, $code) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
info_code_attribute: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | my $atts = MOP4Import::NamedCodeAttributes->m4i_CODE_ATTR_dict($code) | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 220 | or return undef; | ||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | $atts->{$attName}; | |||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||
| 224 | sub info_code_attributes_of { | ||||||||||||||||||||||||||||||||||||||||
| 225 | 20 | ▶ | my ($self, $class, $name, $allow_missing) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
info_code_attributes_of: called CC=9 SCAR=35.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 226 | 20 | ▶ | unless (defined $class and defined $name) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $class and defined $name
MC/DC0%0/2
defined $class and defined $name
defined $class
defined $name
Truth table33%1/3
A and B
A= defined $classB= defined $name
| |||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | Carp::croak "Usage: \$self->info_code_attributes_of(\$class, \$name, ?\$allow_missing\?)" | |||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||
| 229 | 20 | $self->require_module($class); | |||||||||||||||||||||||||||||||||||||||
| 230 | 20 | ▶ | if ($class->can('meta')) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | my $meta = $class->meta->get_method($name) or do { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | return if $allow_missing; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | Carp::croak "No such method: $name"; | |||||||||||||||||||||||||||||||||||||||
| 234 | }; | ||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | $meta->can('attributes') | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 236 | or return; | ||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $atts = $meta->attributes; | |||||||||||||||||||||||||||||||||||||||
| 238 | 0 | MOP4Import::NamedCodeAttributes->m4i_parse_attributes(@$atts); | |||||||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 240 | 20 | ▶ | my $sub = $class->can($name) or do { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | ▶ | return if $allow_missing; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | Carp::croak "No such method: $name"; | |||||||||||||||||||||||||||||||||||||||
| 243 | }; | ||||||||||||||||||||||||||||||||||||||||
| 244 | 20 | MOP4Import::NamedCodeAttributes->m4i_CODE_ATTR_dict($sub); | |||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||||||||||||||
| 248 | sub info_methods :method { | ||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | (my MY $self, my ($methodPattern, %opts)) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
info_methods: not called CC=18 SCAR=58.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $groupByClass = delete $opts{group}; | |||||||||||||||||||||||||||||||||||||||
| 252 | 0 | my $detail = delete $opts{detail}; | |||||||||||||||||||||||||||||||||||||||
| 253 | 0 | my $all = delete $opts{all}; | |||||||||||||||||||||||||||||||||||||||
| 254 | 0 | my $inc = delete $opts{inc}; | |||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $pack = do { | |||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if (my $name = delete $opts{pack}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $self->require_module($name, MOP4Import::Util::lexpand($inc)); | |||||||||||||||||||||||||||||||||||||||
| 258 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | ref $self; | |||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||
| 261 | }; | ||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | unless (keys %opts == 0) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | Carp::croak "Unknown options: ".join(", ", sort keys %opts); | |||||||||||||||||||||||||||||||||||||||
| 265 | } | ||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my $re = do { | |||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if (not defined $methodPattern or $methodPattern eq '') { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
Condition0%0/3
not defined $methodPattern or $methodPattern eq ""
MC/DC0%0/2
not defined $methodPattern or $methodPattern eq ""
not defined $methodPattern
$methodPattern eq ""
Truth table0%0/3
not(A) or B
A= not defined $methodPatternB= $methodPattern eq ""
| |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | qr{^[a-z]\w+\z} | |||||||||||||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||||||||||||||
| 271 | elsif (ref $methodPattern eq 'Regexp') { | ||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | $methodPattern | |||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||
| 274 | elsif ($methodPattern =~ m{^/(.*)/\z}) { | ||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | qr{$1} | |||||||||||||||||||||||||||||||||||||||
| 276 | } elsif ($methodPattern =~ /\*/) { | ||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | require Text::Glob; | |||||||||||||||||||||||||||||||||||||||
| 278 | 0 | Text::Glob::glob_to_regex($methodPattern); | |||||||||||||||||||||||||||||||||||||||
| 279 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | qr{^$methodPattern}; | |||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||
| 282 | }; | ||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | my $isa = mro::get_linear_isa($pack); | |||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||
| 286 | my @all = map { | ||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | my $symtab = MOP4Import::Util::symtab($_); | |||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | my @names = grep {not /\W/ and $_ =~ $re} keys %$symtab; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 289 | my @found = grep { | ||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $entry = $symtab->{$_}; | |||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if (ref \$entry eq 'GLOB' and my $code = *{$entry}{CODE}) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref \$entry eq "GLOB" and my $code = *{$entry;}{"CODE"}
MC/DC0%0/1
ref \$entry eq "GLOB" and my $code = *{$entry;}{"CODE"}
ref \$entry eq "GLOB"
Truth table0%0/2
A
A= ref \$entry eq "GLOB"
| |||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | ▶ | $all || MOP4Import::Util::has_method_attr($code); | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||
| 294 | } @names; | ||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | ▶ | if (not @found) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||
| 296 | () | ||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | } elsif ($detail) { | |||||||||||||||||||||||||||||||||||||||
| 298 | +{class => $_, methods => [map { | ||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | my $doc = $self->info_method_doc($_); | |||||||||||||||||||||||||||||||||||||||
| 300 | 0 | ▶ | [$_, $doc ? $doc : ()]; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 301 | } sort @found]} | ||||||||||||||||||||||||||||||||||||||||
| 302 | } elsif ($groupByClass) { | ||||||||||||||||||||||||||||||||||||||||
| 303 | 0 | [$_, sort @found] | |||||||||||||||||||||||||||||||||||||||
| 304 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | @found; | |||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||
| 307 | } @$isa; | ||||||||||||||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if (not $detail and not $groupByClass) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$detail || $groupByClass
MC/DC0%0/2
$detail || $groupByClass
$detail
$groupByClass
Truth table0%0/3
A || B
A= $detailB= $groupByClass
| |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my %dup; | |||||||||||||||||||||||||||||||||||||||
| 311 | 0 | sort grep {not $dup{$_}++}@all; | |||||||||||||||||||||||||||||||||||||||
| 312 | } else { | ||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | @all; | |||||||||||||||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||
| 317 | sub require_module { | ||||||||||||||||||||||||||||||||||||||||
| 318 | 91 | ▶ | (my MY $self, my ($moduleName, @inc)) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
require_module: called CC=6 SCAR=18.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 319 | |||||||||||||||||||||||||||||||||||||||||
| 320 | 91 | my $fn = Module::Runtime::module_notional_filename($moduleName); | |||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||
| 322 | # Use symtab test to avoid require_module() against already loaded modules. | ||||||||||||||||||||||||||||||||||||||||
| 323 | # In modulino, cmd_help may be called during module loading. | ||||||||||||||||||||||||||||||||||||||||
| 324 | # At that time, $INC{$moduleFileName} is not yet initialized. | ||||||||||||||||||||||||||||||||||||||||
| 325 | # This leads to double-require. | ||||||||||||||||||||||||||||||||||||||||
| 326 | 91 | ▶ | if (MOP4Import::Util::maybe_symtab($moduleName)) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 327 | 89 | ▶ | return wantarray ? ($moduleName => $INC{$fn}) : $moduleName; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||
| 329 | |||||||||||||||||||||||||||||||||||||||||
| 330 | 2 | @inc = map {split /:/} MOP4Import::Util::lexpand($self->{lib}) | |||||||||||||||||||||||||||||||||||||||
| 331 | 2 | ▶ | if not @inc and ref $self; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not @inc and ref $self
MC/DC0%0/2
not @inc and ref $self
not @inc
ref $self
Truth table33%1/3
not(A) and B
A= not @incB= ref $self
| |||||||||||||||||||||||||||||||||||||||||
| 332 | { | ||||||||||||||||||||||||||||||||||||||||
| 333 | 2 | require Module::Runtime; | |||||||||||||||||||||||||||||||||||||||
| 334 | 2 | local @INC = (@inc, @INC); | |||||||||||||||||||||||||||||||||||||||
| 335 | 2 | Module::Runtime::require_module($moduleName); | |||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||
| 337 | 2 | ▶ | wantarray ? ($moduleName => $INC{$fn}) : $moduleName; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||
| 340 | sub list_validator_in_module { | ||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | (my MY $self, my ($typeName, $moduleName, @rest)) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_validator_in_module: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | my $pack = $self->require_module($moduleName, @rest); | |||||||||||||||||||||||||||||||||||||||
| 343 | 0 | my $sub = $pack->can($typeName); | |||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | my $realType = $sub ? $sub->() : $typeName; | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | MOP4Import::Util::list_validator($realType); | |||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||||||||||||
| 348 | sub list_module_path { | ||||||||||||||||||||||||||||||||||||||||
| 349 | 0 | ▶ | (my MY $self, my @modName) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_module_path: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | my %modules; | |||||||||||||||||||||||||||||||||||||||
| 351 | 0 | foreach my $modName (@modName) { | |||||||||||||||||||||||||||||||||||||||
| 352 | 0 | (undef, my $path) = $self->require_module($modName); | |||||||||||||||||||||||||||||||||||||||
| 353 | 0 | $modules{$modName} = $path; | |||||||||||||||||||||||||||||||||||||||
| 354 | } | ||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | \%modules | |||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||
| 358 | sub list_module_version { | ||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | (my MY $self, my @modName) = @_; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
list_module_version: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | my %modules; | |||||||||||||||||||||||||||||||||||||||
| 361 | 0 | foreach my $modName (@modName) { | |||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $self->require_module($modName); | |||||||||||||||||||||||||||||||||||||||
| 363 | 0 | $modules{$modName} = $modName->VERSION; | |||||||||||||||||||||||||||||||||||||||
| 364 | } | ||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | \%modules | |||||||||||||||||||||||||||||||||||||||
| 366 | } | ||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||
| 368 | 7 | ▶ | unless (caller) { | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||
| 369 | # To avoid redefinition wornings: | ||||||||||||||||||||||||||||||||||||||||
| 370 | # cli_run -> cli_help -> cli_inspector -> require MOP4Import::Util::Inspector; | ||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | require File::Spec; | |||||||||||||||||||||||||||||||||||||||
| 372 | 0 | $INC{"MOP4Import/Util/Inspector.pm"} = File::Spec->rel2abs(__FILE__); | |||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||
| 374 | 0 | MY->cli_run(\@ARGV); | |||||||||||||||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||
| 377 | 7 | 1; | |||||||||||||||||||||||||||||||||||||||