App-Spec
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/Spec/Role/Command.pm view on Meta::CPAN
use strict;
use warnings;
package App::Spec::Role::Command;
our $VERSION = '0.013'; # VERSION
use YAML::PP;
use List::Util qw/ any /;
use App::Spec::Option;
use Ref::Util qw/ is_arrayref /;
use Moo::Role;
has name => ( is => 'rw' );
has markup => ( is => 'rw', default => 'pod' );
has class => ( is => 'rw' );
has op => ( is => 'ro' );
has plugins => ( is => 'ro' );
has plugins_by_type => ( is => 'ro', default => sub { +{} } );
has options => ( is => 'rw', default => sub { +[] } );
has parameters => ( is => 'rw', default => sub { +[] } );
has subcommands => ( is => 'rw', default => sub { +{} } );
has description => ( is => 'rw' );
sub default_plugins {
qw/ Meta Help /
}
sub has_subcommands {
my ($self) = @_;
return $self->subcommands ? 1 : 0;
}
sub build {
my ($class, %spec) = @_;
$spec{options} ||= [];
$spec{parameters} ||= [];
for (@{ $spec{options} }, @{ $spec{parameters} }) {
$_ = { spec => $_ } unless ref $_;
}
$_ = App::Spec::Option->build(%$_) for @{ $spec{options} || [] };
$_ = App::Spec::Parameter->build(%$_) for @{ $spec{parameters} || [] };
my $commands;
for my $name (keys %{ $spec{subcommands} || {} }) {
my $cmd = $spec{subcommands}->{ $name };
$commands->{ $name } = App::Spec::Subcommand->build(
name => $name,
%$cmd,
);
}
$spec{subcommands} = $commands;
if ( defined (my $op = $spec{op}) ) {
die "Invalid op '$op'" unless $op =~ m/^\w+\z/;
}
if ( defined (my $class = $spec{class}) ) {
die "Invalid class '$class'" unless $class =~ m/^ \w+ (?: ::\w+)* \z/x;
}
my $self = $class->new(%spec);
}
sub read {
my ($class, $file) = @_;
unless (defined $file) {
die "No filename given";
}
my $spec = $class->load_data($file);
view all matches for this distributionview release on metacpan - search on metacpan
( run in 1.912 second using v1.00-cache-2.02-grep-82fe00e-cpan-72ae3ad1e6da )