App-CmdDispatch

 view release on metacpan or  search on metacpan

lib/App/CmdDispatch.pm  view on Meta::CPAN

    return;
}

sub alias_list { return $_[0]->{table}->alias_list(); }

sub shell
{
    my ( $self ) = @_;

    $self->_print( "Enter a command or 'quit' to exit:\n" );
    while ( my $line = $self->_prompt( '> ' ) )
    {
        chomp $line;
        next unless $line =~ /\S/;
        last if $line eq 'quit';
        $self->run( split /\s+/, $line );
    }
    return;
}

sub _print
{
    my $self = shift;
    return $self->{io}->print( @_ );
}

sub _prompt
{
    my $self = shift;
    return $self->{io}->prompt( @_ );
}

sub _initialize_config
{
    my ( $self, $config_file ) = @_;
    my $conf = Config::Tiny->read( $config_file );
    %{ $self->{config} } = (
        ( $conf->{_} ? %{ delete $conf->{_} } : () ),    # first extract the top level
        %{$conf},                # Keep any multi-levels that are not aliases
        %{ $self->{config} },    # Override with supplied parameters

lib/App/CmdDispatch.pm  view on Meta::CPAN

    }

    $self->{io} = $io;
    return;
}

sub _is_valid_io_object
{
    my ( $io ) = @_;
    return unless ref $io;
    return 2 == grep { $io->can( $_ ) } qw/print prompt/;
}

sub _setup_commands
{
    my ( $self, $commands ) = @_;
    $commands = { %{$commands} };

    return $commands unless $self->{config}->{default_commands};

    foreach my $def ( split / /, $self->{config}->{default_commands} )

lib/App/CmdDispatch.pm  view on Meta::CPAN

=item shell

Prove a shell interface that loops asking for subcommands. Each command
is executed and contol returns to the loop.

=back

=item io

An object supplying input and output services for the CmdDispatcher. This
object must provide both a C<print> method and a C<prompt> method. See
L<App::CmdDispatch::IO> for more information on the interface.

=item help:*

The options beginning with the string 'help:' are described in the docs for
L<App::CmdDispatch::Help>.

=back

=head2 run( $cmd, @args )

lib/App/CmdDispatch/IO.pm  view on Meta::CPAN

    my $self = shift;
    return CORE::print @_;
}

sub readline
{
    my ($self) = @_;
    return $self->{term}->readline( '' );
}

sub prompt
{
    my ($self, @in) = @_;
    return $self->{term}->readline( @in );
}

{
    package App::CmdDispatch::MinimalIO;

    sub new
    {

lib/App/CmdDispatch/IO.pm  view on Meta::CPAN

        my $self = shift;
        return CORE::print @_;
    }

    sub readline
    {
        my ($self) = @_;
        return CORE::readline;
    }

    sub prompt
    {
        my ($self, @in) = @_;
        $self->print( @in );
        return $self->readline();
    }
}
1;
__END__

=head1 NAME

lib/App/CmdDispatch/IO.pm  view on Meta::CPAN

This document describes C<App::CmdDispatch::IO> version 0.44

=head1 SYNOPSIS

    use App::CmdDispatch::IO;

    my $io = App::CmdDispatch::IO->new;

    $io->print( "Message to the user\n" );

    my $name = $io->prompt( "What is your name: " );
  
=head1 DESCRIPTION

This class encapsulates the I/O interface needed by the L<App::CmdDispatch>
module. A user can replace this object to provide a different mechanism for
interacting with the user.

This default version of the class defines the interface and interacts with
the user through the standard in and out streams.

lib/App/CmdDispatch/IO.pm  view on Meta::CPAN

Create a new object of type C<App::CmdDispatch::IO>.

=head2 print( @strings )

Display the list of supplied strings to the user.

=head2 readline

Return a single line from the user.

=head2 prompt( @strings )

Display the list of supplied strings and then return a single line from the
user.

=head1 CONFIGURATION AND ENVIRONMENT

C<App::CmdDispatch::IO> requires no configuration files or environment variables.

=head1 DEPENDENCIES

t/00.load.t  view on Meta::CPAN

use Test::More tests => 4;

BEGIN
{
    use_ok( 'App::CmdDispatch' );
}

note( "Testing App::CmdDispatch $App::CmdDispatch::VERSION" );

can_ok( 'App::CmdDispatch',     qw/new get_config run help hint command_hint shell/ );
can_ok( 'App::CmdDispatch::IO', qw/new print readline prompt/ );
can_ok( 'App::CmdDispatch::Table',
    qw/new run has_aliases get_alias get_command alias_list command_list/ );

t/lib/Test/IO.pm  view on Meta::CPAN

    $self->{output} .= join( '', @_ );
    return 1;
}

sub readline
{
    my ($self) = @_;
    return shift @{$self->{input}};
}

sub prompt
{
    my $self = shift;
    $self->print( @_ );
    return $self->readline();
}

sub output
{
    my ($self) = @_;
    return $self->{output};



( run in 0.564 second using v1.01-cache-2.11-cpan-6aa56a78535 )