App::PerlShell - Perl Shell
use App::PerlShell; my $shell = App::PerlShell->new(); $shell->run;
App::PerlShell creates an interactive Perl shell. From it, Perl commands can be executed. There are some additional commands helpful in any interactive 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.
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.
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
$shell->run();
Run the shell. Provides interactive environment for entering 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.
Change directory to optional 'directory'. No argument changes to 'homedir'. Optional return value is current directory (directory before change).
Clear screen.
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.
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.
debug
Directory listing. 'OPTIONS' are system directory listing command options. Optional return value is array of output.
Displays $var with Data::Dumper.
Exit shell.
Display shell help.
Displays used modules. With 'SEARCH', displays matching used modules. Optional return value is hash with module names as keys and file locations as values.
Print working directory. Optional return value is result.
Open session file. Only logs Perl commands. Appends to already existing file. Use session (':close') to end.
session (':close')
List user defined variables currently active in current package in shell.
cd, cls, clear, dir, help, ls, modules, pwd, session, variables
This distribution comes with a script (installed to the default "bin" install directory) that not only demonstrates example uses but also provides functional execution.
App::PerlShell::Config, App::PerlShell::ModRefresh, App::PerlShell::LexPersist
This software is released under the same terms as Perl itself. If you don't know what that means visit http://perl.com/.
Copyright (c) 2015 Michael Vincent
http://www.VinsWorld.com
All rights reserved
To install App::PerlShell, copy and paste the appropriate command in to your terminal.
cpanm
cpanm App::PerlShell
CPAN shell
perl -MCPAN -e shell install App::PerlShell
For more information on module installation, please visit the detailed CPAN module installation guide.