208
|
17 |
6 |
0 |
$self->{'cache_commands'} //= do {
my %commands;
foreach my $pkg ($self->packages) {
next if defined $name_method and not $pkg->can($name_method);
my $name = defined $name_method ? $pkg->$name_method : $pkg =~ s/\Q$self->{'base'}\E:://ru;
next unless my $code = $pkg->can($self->{'methods'}{'code'});
my $desc = ($pkg->can($self->{'methods'}{'desc'}) || (next))->($pkg);
my $args;
if (my $argsmeth = $pkg->can($self->{'methods'}{'args'})) {
$args = [map({"Commandable::Command::_Argument"->new(%$_);} $pkg->$argsmeth)];
};
my $opts;
if (my $optsmeth = $pkg->can($self->{'methods'}{'opts'})) {
$opts = {map({my $o = "Commandable::Command::_Option"->new(%$_);
map {$_, $o;} $o->names;} $pkg->$optsmeth)};
};
$commands{$name} = "Commandable::Command"->new("name", $name, "description", $desc, "arguments", $args, "options", $opts, "package", $pkg, "code", $code);
};
$self->add_builtin_commands(\%commands);
\%commands
} |