Prophet
view release on metacpan or search on metacpan
lib/Prophet/CLI/Command/Shell.pm view on Meta::CPAN
#!/usr/bin/env perl
package Prophet::CLI::Command::Shell;
{
$Prophet::CLI::Command::Shell::VERSION = '0.751';
}
use Any::Moose;
extends 'Prophet::CLI::Command';
use File::Spec;
use Prophet::Util;
use Text::ParseWords qw(shellwords);
use Scalar::Util qw(weaken);
has name => (
is => 'ro',
isa => 'Str',
default => sub { Prophet::Util->updir($0) }
);
has term => (
is => 'ro',
isa => 'Term::ReadLine::Stub',
lazy => 1,
handles => [qw/readline addhistory/],
default => sub {
my $self = shift;
my $weakself = $self;
weaken($weakself);
require Term::ReadLine;
my $term = Term::ReadLine->new("Prophet shell");
$term->Attribs->{completion_function} = sub {
$weakself->_complete(@_);
};
return $term;
},
);
our $HIST = $ENV{PROPHET_HISTFILE}
|| ( ( $ENV{HOME} || ( getpwuid($<) )[7] ) . "/.prophetreplhist" );
our $LEN = $ENV{PROPHET_HISTLEN} || 500;
sub usage_msg {
my $self = shift;
my $cmd = $self->cli->get_script_name;
return <<"END_USAGE";
usage: ${cmd}\[shell]
END_USAGE
}
sub prompt {
my $self = shift;
return $self->name . '> ';
}
sub preamble {
return join "\n",
"Prophet $Prophet::VERSION",
'Type "help", "about", or "copying" for more information.',
;
}
sub read {
my $self = shift;
Prophet::CLI->end_pager; # in case a previous command died
$self->readline( $self->prompt );
}
sub eval {
my $self = shift;
my $line = shift;
eval {
local $SIG{__DIE__} = 'DEFAULT';
my @args = shellwords($line);
$self->cli->run_one_command(@args);
};
warn $@ if $@;
}
sub _run {
my $self = shift;
Prophet::CLI->end_pager;
local $| = 1;
print $self->preamble . "\n";
# we don't want to run the pager for the shell
$self->cli->interactive_shell(1);
while ( defined( my $cmd = $self->read ) ) {
next if $cmd =~ /^\s*$/;
last
if $cmd =~ /^\s*q(?:uit)?\s*$/i
|| $cmd =~ /^\s*exit\s*$/i;
$self->eval($cmd);
( run in 1.729 second using v1.01-cache-2.11-cpan-df04353d9ac )