The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

App::PerlShell - Perl Shell

SYNOPSIS

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

DESCRIPTION

App::PerlShell creates an interactive Perl shell. From it, Perl commands can be executed. There are some additional commands helpful in any interactive shell.

Why Yet Another Perl Shell?

I needed an interactive Perl Shell for some Perl applications I was writing and found several options on CPAN:

  • Perl::Shell

  • perlconsole

  • Devel::REPL

All of which are excellent modules, but none had everything I wanted without a ton of external dependencies. I didn't want that trade off; I wanted functions without dependencies.

I also wanted to emulate a shell - not necessarily a REPL (Read-Evaluate-Parse-Loop). In the way sh, Bash, csh and others *nix or cmd.exe on Windows are a shell - I wanted a Perl Shell. For example, many of the above modules will evaluate an expression:

 5+1
 6

If I enter "5+1" in cmd.exe or Bash, I don't get 6, I get an error. In a Perl program, if I have a line "5+1;", I get an error in execution. If I really want "6", I need to "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 'ls', 'cd' and 'pwd' for example.

CAVEATS

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

METHODS

new() - create a new Shell object

  my $shell = App::PerlShell->new([OPTIONS]);

Create a new App::PerlShell object with OPTIONS as optional parameters. Valid options are:

  Option     Description                             Default
  ------     -----------                             -------
  -execute   Valid Perl code ending statements with  (none)
             semicolon (;).
  -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

run() - run the shell

  $shell->run();

Run the shell. Provides interactive environment for entering commands.

COMMANDS

In the interactive shell, all valid Perl commands can be entered. This includes constructs like 'for () {}' and 'if () {} ... else {}' as well as any subs from 'use'ed modules. The following are also provided.

cd [('directory')]

Change directory to optional 'directory'. No argument changes to 'homedir'. Optional return value is current directory (directory before change).

clear
cls

Clear screen.

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.

debug

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

dir [('OPTIONS')]
ls [('OPTIONS')]

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

dumper $var

Displays $var with Data::Dumper.

exit

Exit shell.

help

Display shell help.

modules [('SEARCH')]

Displays used modules. With 'SEARCH', displays matching used modules. Optional return value is hash with module names as keys and file locations as values.

pwd

Print working directory. Optional return value is result.

session ('file')

Open session file. Only logs Perl commands. Appends to already existing file. Use session (':close') to end.

variables

List user defined variables currently active in current package in shell.

EXPORT

cd, cls, clear, dir, help, ls, modules, pwd, session, variables

EXAMPLES

This distribution comes with a script (installed to the default "bin" install directory) that not only demonstrates example uses but also provides functional execution.

SEE ALSO

App::PerlShell::Config, App::PerlShell::ModRefresh, App::PerlShell::LexPersist

LICENSE

This software is released under the same terms as Perl itself. If you don't know what that means visit http://perl.com/.

AUTHOR

Copyright (c) 2015 Michael Vincent

http://www.VinsWorld.com

All rights reserved