App-Tool-Base

 view release on metacpan or  search on metacpan

lib/App/Tool/Base.pm  view on Meta::CPAN



sub _join_arg_help_list {
    my ($req_args, $opt_args) = @_;
    return  join ( q{ },
        ( map {"<$_>"} @{ $req_args || [] } ),
        ( map {"[<$_>]"} @{ $opt_args || [] } ),
    );
}


sub _get_option_key {
    my ($getopt_key) = @_;
    my ($key) = $getopt_key =~ /^([\w\-]+)/xms;
    return $key;
}


sub _format_table {
    my ($table, $format) = @_;
    
    my @maxlens;
    for my $row (@$table) {
        for my $i (0 .. $#$row) {
            next if $maxlens[$i] && length $row->[$i] <= $maxlens[$i];
            $maxlens[$i] = length $row->[$i];
        }
    }

    $format //= join q{ }, ("%-s") x scalar @maxlens;
    $format =~ s/(%-?)/$1 . shift @maxlens/gexms;

    return join qq{\n}, map {sprintf $format, @$_} @$table;
}


=head2 LIST

Show list of supported actions.

=cut

sub list_actions
    :Action(LIST)
    :Hidden
    :Description('Show list of available actions')
    :Option(full, 'show hidden actions also')
{
    my %opt = @_;

    my $actions = _get_action_names($opt{full});
    say join qq{\n}, @$actions;
    return;
}



sub import
{
    my $class = shift;
    my $inheritor = caller(0);
    my ($run) = @_;

    {
        no strict 'refs';
        push @{"$inheritor\::ISA"}, $class;
        *{"$inheritor\::$run"} = \&run  if $run;
    };

    return;
}


1;



( run in 0.991 second using v1.01-cache-2.11-cpan-437f7b0c052 )