App-Rad-Plugin-ReadLine
view release on metacpan - search on metacpan
view release on metacpan or search on metacpan
lib/App/Rad/Plugin/ReadLine.pm view on Meta::CPAN
$c->debug("not registering shell as a command since \$name was passed as undef");
}
else {
$name = _shell_command() if not defined $name;
$help = _shell_help() if not defined $help;
$c->debug("registering shell as '$name' => '$help'");
$c->register( $name => \&shell, $help );
}
}
# this is printed when your shell first starts, it will optionally run a command,
# then optionally run a sub
# again, you can do both, but that's likely to be unhelpful
sub _welcome {
my $c = shift;
# $c->critters();
$c->stash->{shelllvl} ++;
do {
local $c->{'cmd'} = $GreetWithCommand;
$c->execute();
} if defined $GreetWithCommand;
$c->$GreetWithSub() if defined $GreetWithSub;
}
sub shell {
my $c = shift;
# $c->critters();
$c->stash->{shelllvl} ++;
{no warnings qw[ redefine ];
*App::Rad::Help::usage = sub {
"Your app as a shell. Type commands with arguments"
};}
# sub-shells
local $GreetWithCommand = $GreetWithCommand ;
local $GreetWithSub = $GreetWithSub ;
local $DefaultCommand = $DefaultCommand ;
local $ShellPrompt = $ShellPrompt ;
local $still_going = $still_going ;
$c->shell_options(@_) if @_;
$c->register( 'exit', sub {
$App::Rad::Plugin::ReadLine::still_going = 0;
}, "exit the $0 shell" );
$c->unregister_command('shell');# Xhibit forbidden
my $welcome = \&_welcome;
$c->$welcome();
while($still_going) {
(my $cmd, local @ARGV) = split ' ',
_terminal->get_reply(
prompt => _shell_prompt(),
default => $DefaultCommand,
);
if (defined $cmd and $cmd ne '') {
@{$c->argv} = @ARGV;
$c->{'cmd'} = $cmd;
$c->debug('received command: ' . $c->{'cmd'});
$c->debug('received parameters: ' . join (' ', @{$c->argv} ));
}
$c->_tinygetopt();
# run the specified command
# setup/pre_process are run for us...
$c->execute();
# teardown is run after this (again, magically)
}
}
"Say my name"
__END__
=pod
=head1 NAME
App::Rad::Plugin::ReadLine - App::Rad::Plugin::ReadLine a Term::UI ->shell for Rad Apps
=head1 VERSION
version 0.002
=head1 SYNOPSIS
To run your app as a shell, you can either...
=head2 call C<< ->shell >> from an action ...
start shell mode straight away from a sub-command
#see ./example/01-myapp
#! /usr/bin/perl
#...
use App::Rad qw[ ReadLine ];
App::Rad->run();
sub turtles :Help('do it in the shell'){
my $c = shift;
$c->shell({
GreetWithCommand => '', # use what App::Rad decides is the default
ShellPrompt => 'c/,,\\' # ascii turtle for the prompt
});
}
#end of listing
#running ./example/01-myapp demo turtles exit
Usage: ./example/01-myapp command [arguments]
view all matches for this distributionview release on metacpan - search on metacpan
( run in 0.772 second using v1.00-cache-2.02-grep-82fe00e-cpan-9e6bc14194b )