EB::Shell::Base 1.01.02 review

Download
by rbytes.net on

EB::Shell::Base is a generic class to build line-oriented command interpreters. SYNOPSIS package My::Shell; use base qw(

License: Perl Artistic License
File size: 0K
Developer: Darren Chamberlain
0 stars award from rbytes.net

EB::Shell::Base is a generic class to build line-oriented command interpreters.

SYNOPSIS

package My::Shell;

use base qw(EB::Shell::Base);

sub do_greeting {
return "Hello!"
}

EB::Shell::Base is a slightly modified version of Shell::Base. It is modifed for the EekBoek program http://www.squirrel.nl/eekboek and NOT intended for general use. Please use Shell::Base instead.

Shell::Base is a base class designed for building command line programs. It defines a number of useful defaults, simplifies adding commands and help, and integrates well with Term::ReadLine.

After writing several REP (Read-Eval-Print) loops in Perl, I found myself wishing for something a little more convenient than starting with:

while(1) {
my $line = ;
last unless defined $line;

chomp $line;
if ($line =~ /^...

Features

Shell::Base provides simple access to many of the things I always write into my REP's, as well as support for many thing that I always intend to, but never find time for:
readline support

Shell::Base provides simple access to the readline library via Term::ReadLine, including built-in tab-completion and easy integration with the history file features.

If a subclass does want or need Term::ReadLine support, then it can be replaced in subclasses by overriding a few methods. See "Using Shell::Base Without readline", below.

Trivial to add commands

Adding commands to your shell is as simple as creating methods: the command foo is dispatched to do_foo. In addition, there are hooks for unknown commands and for when the user just hits , both of which a subclass can override.

Integrated help system

Shell::Base makes it simple to integrate online help within alongside your command methods. Help for a command foo can be retrieved with help foo, with the addition of one method. In addition, a general help command lists all possible help commands; this list is generated at run time, so there's no possibility of forgetting to add help methods to the list of available topics.

Pager integration

Output can be sent through the user's default pager (as defined by $ENV{'PAGER'}, with a reasonable default) or dumped directly to STDOUT.

Customizable output stream(s)

Printing is handled through a print() method, which can be overridden in a subclass to send output anywhere.

Pre- and post-processing methods

Input received from readline() can be processed before it is parsed, and output from command methods can be post-processed before it is sent to print().

Automatic support for RC files

A simple RC-file parser is built in, which handles name = value type configuration files. This parser handles comments, whitespace, multiline definitions, boolean and (name, value) option types, and multiple files (e.g., /etc/foorc, $HOME/.foorc).

Shell::Base was originally based, conceptually, on Python's cmd.Cmd class, though it has expanded far beyond what Cmd offers.

Requirements:
Perl

EB::Shell::Base 1.01.02 search tags