App-PerlShell

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

1.08  Tue Apr  7 10:05:00 2021
    - .plshrc file in $HOME
    - Semicolon not required with environment variable PERLSHELL_SEMIOFF=1

1.07  Thu Mar 26 10:05:00 2020
    - `perldoc` command added and `ls` updated for multiple options
    - Better COMMAND definition in hash for EXPORT and `help`

1.06  Tue Mar 10 23:05:00 2020
    - Unbalanced ({[]}) can now execute with single semicolon ";" at 
      "More?" prompt

1.05  Thu Jun  6 14:05:00 2019
    - App::PerlShell::Plugin::File

1.04  Thu May  3 14:05:00 2018
    - AddOn => Plugin
    - Fixed some POD mistakes and updated examples
    - bin/plsh.pl SKIPVARS updated

1.03  Thu Apr 26 14:05:00 2018

bin/plsh.pl  view on Meta::CPAN


GetOptions(

    # '' => \$opt{interact},    # lonesome dash is interactive test from STDIN
    'e|execute=s@' => \$opt{execute},
    'E|exit!'      => \$opt{exit},
    'feature=s'    => \$opt{feature},
    'Include=s@'   => \$opt{include},
    'lexical!'     => \$opt{lexical},
    'P|package=s'  => \$opt{package},
    'p|prompt=s'   => \$opt{prompt},
    'session=s'    => \$opt{session},
    'V|verbose!'   => \$opt{verbose},
    # 'words!'       => \$opt{words},
    'help!'        => \$opt{help},
    'man!'         => \$opt{man},
    'versions!'    => \$opt{versions}
) or pod2usage( -verbose => 0 );

pod2usage( -verbose => 1 ) if defined $opt{help};
pod2usage( -verbose => 2 ) if defined $opt{man};

bin/plsh.pl  view on Meta::CPAN

if ( defined $opt{execute} ) {
    for ( @{$opt{execute}} ) {
        $params{execute} .= $_;
        if ( $params{execute} !~ /;$/ ) {
            $params{execute} .= ';';
        }
        $params{execute} .= "\n";
    }
}

if ( defined $opt{prompt} ) {
    $params{prompt} = $opt{prompt};
    $params{execute} .= "\$ENV{PERLSHELL_PROMPT}='$opt{prompt}';\n";
}

# Must be here again to add to end of execute to override .plshrc setting
# of package with the command line -P if specified
if ( defined $opt{package} ) {
    $params{execute} .= "\$ENV{PERLSHELL_PACKAGE}='$opt{package}';\n";
}

if ( defined $opt{feature} ) {
    $opt{feature} =~ s/^[v]//;

bin/plsh.pl  view on Meta::CPAN

 -I dir               Specify directory to prepend @INC.  Multiple
 --Include            -I allowed.

 -l                   Require "my" for all variables.
 --lexical            Requires Lexical::Persistence, fails if not found.

 -P package           Package to use as namespace.  Will:
 --package              use `package';
                      before any -e arguments.

 -p prompt            Prompt for the shell.
 --prompt

 -s file              Session command log file.
 --session

 -V                   Output verbose initialization information.
 --verose

=cut

 -w                   Treat each element of args as a separate

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

}

sub new {
    my $self = shift;
    my $class = ref($self) || $self;

    # Default parameters
    my %params = (
        homedir => ( $^O eq "MSWin32" ) ? $ENV{USERPROFILE} : $ENV{HOME},
        package => __PACKAGE__,
        prompt  => 'Perl> '
    );

    my $lex = 0;
    my $verbose = 0;
    if ( @_ == 1 ) {
        croak("Insufficient number of args - @_");
    } else {
        my %cfg = @_;
        for ( keys(%cfg) ) {
            if (/^-?homedir$/i) {

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

                    $params{homedir} = $cfg{$_};
                } else {
                    croak("Cannot find directory `$cfg{$_}'");
                }
            } elsif (/^-?execute$/i) {
                $params{execute} = $cfg{$_};
            } elsif (/^-?lex(?:ical)?$/i) {
                $lex = 1;
            } elsif (/^-?package$/i) {
                $params{package} = $cfg{$_};
            } elsif (/^-?prompt$/i) {
                $params{prompt} = $cfg{$_};
            } elsif (/^-?feature$/i) {
                $params{feature} = $cfg{$_};
            } elsif (/^-?session$/i) {
                # assign, will test open in run()
                $params{session} = $cfg{$_};
            } elsif (/^-?skipvars$/i) {
                if ( ref $cfg{$_} eq 'ARRAY' ) {
                    $params{skipvars} = $cfg{$_};
                } else {
                    croak("Not array reference `$cfg{$_}'");

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

                "-lexical specified, `Lexical::Persistence' required but not found"
            );
        }
    }

    # Setup Environment Variables
    $ENV{PERLSHELL_FEATURE} = $params{feature};
    $ENV{PERLSHELL_HOME}    = $params{homedir};
    $ENV{PERLSHELL_PACKAGE} = $params{package};
    $ENV{PERLSHELL_PERLDOC} = 'perldoc';
    $ENV{PERLSHELL_PROMPT}  = $params{prompt};
    $ENV{PERLSHELL_SEMIOFF} = 0;
    if ( defined $params{skipvars} ) {
        $ENV{PERLSHELL_SKIPVARS} = join ';', @{$params{skipvars}};
    }

    if ( $verbose ) {
        print "$params{execute}\n";
    }

    # clean up object
    delete $params{feature};
    delete $params{homedir};
    delete $params{package};
    delete $params{prompt};
    delete $params{skipvars};
    return bless \%params, $class;
}

sub run {
    my $App_PerlShell_Shell = shift;

    # handle session if requested
    if ( defined $App_PerlShell_Shell->{session} ) {
        if ( not defined session( $App_PerlShell_Shell->{session} ) ) {

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

    if ( exists $App_PerlShell_Shell->{shellLexEnv} ) {
        $App_PerlShell_Shell->{shell}
          = $App_PerlShell_Shell->{shellLexEnv}->get_package();
    } else {
        $App_PerlShell_Shell->{shell} = $ENV{PERLSHELL_PACKAGE};
    }
    $App_PerlShell_Shell->{shell}
      = Term::ReadLine->new( $App_PerlShell_Shell->{shell} );
    $App_PerlShell_Shell->{shell}->ornaments(0);

    #'use strict' is not used to allow "$p=" instead of "my $p=" at the prompt
    no strict 'vars';

    # will always exeucte without readline first time through (do ... while)
    while (1) {

        # do ... while loop won't support next and last
        # First check then clear {execute} to autopopulate
        # $App_PerlShell_Shell->{shellCmdLine}
        # otherwise, just do the readline.

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

Shell.  For example, many of the above modules will evaluate an expression:

 5+1
 6

If I enter C<5+1> in C<cmd.exe> or C<bash>, I don't get C<6>, I get an error.  
In a Perl program, if I have a line C<5+1;>, I get an error in execution.  If I 
really want C<6>, I need to C<print 5+1;>.  And so it should be in the Perl 
Shell.

This is much closer to a command prompt / terminal than a REPL.  As such, 
some basic shell commands are provided, like C<ls>, C<cd> and C<pwd> for 
example.

=head1 CAVEATS

For command recall using the up/down arrows in *nix, you will need 
B<Term::ReadLine::Gnu> installed.  This module will function fine without 
it as B<Term::ReadLine> is a core module; however, command recall using 
the up/down arrows will not work.

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

  ------     -----------                             -------
  -execute   Valid Perl code ending statements with  (none)
             semicolon (;).
  -feature   Perl feature set to use e.g., ":5.10"   :default
  -homedir   Specify home directory.                 $ENV{HOME} or
             Used for `cd' with no argument.         $ENV{USERPROFILE}
  -lexical   Require "my" for variables.             (off)
             Requires Lexical::Persistence
  -package   Package to impersonate.  Execute all    App::PerlShell
             commands as if in this package.
  -prompt    Shell prompt.                           Perl>
  -session   Session file to log commands.           (none)
  -skipvars  Variables to ignore in `variables'      $VERSION, @ISA,
             command.                                @EXPORT

=head2 run() - run the shell

  $shell->run();

Run the shell.  Provides interactive environment for entering commands.

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

Clear screen.

=item B<commands> [('SEARCH')]

Displays available commands.  Commands are essentially 'sub's defined 
in the current package.  With 'SEARCH', displays matching commands.  
Optional return value is array with commands.

=item B<debug>

Print command so far (don't execute) at multiline input 'More?' prompt.  Must 
be used as C<debug> only, no semicolon starting at first position in input.

=item B<dir> [('OPTIONS')]

=item B<ls> [('OPTIONS')]

Directory listing.  'OPTIONS' are system directory listing command options.  
Optional return value is array of output.

=item B<dumper> $var

lib/App/PerlShell/ModRefresh.pm  view on Meta::CPAN

=head1 SYNOPSIS

 use App::PerlShell;
 my $shell = App::PerlShell->new();
 $shell->run;

=head1 DESCRIPTION

B<App::PerlShell::ModRefresh> provides an extension to 
B<App::PerlShell> to automatically refresh used modules if they 
change on disk between commands issued at the shell prompt.  It uses 
B<Module::Refresh> to accomplish this.  If B<Module::Refresh> is not 
installed, this feature is not available.

=head1 METHODS

Several methods and accessors are provided and some override the 
B<Module::Refresh> ones.  These are called as-needed from the 
B<App::PerlShell> C<run> method.

=over 4



( run in 0.640 second using v1.01-cache-2.11-cpan-0b5f733616e )