http://www.perlmonks.org?node_id=840710

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm developing a linux based hardware device and plan to provide a Cisco IOS-like command line interface. I've considered rolling my own, but would rather not re-invent the wheel. Can anyone recommend a good Perl based framework for developing such a "shell"?

Replies are listed 'Best First'.
Re: A framework for a shell in perl?
by jettero (Monsignor) on May 19, 2010 at 14:18 UTC
    Wheel::ReadLine is tip top. You have command events and everything just works. POE can be a little frightening at first, but you'll get the hang of it.

    -Paul

Re: A framework for a shell in perl?
by elwarren (Priest) on May 19, 2010 at 15:43 UTC
Re: A framework for a shell in perl?
by skx (Parson) on May 19, 2010 at 16:43 UTC

    The last time I needed such a think I used readline and did it manually because reading and parsing isn't difficult.

    However that was before I knew about Term::Shell, which looks like it would suit your needs.

    Steve
    --
Re: A framework for a shell in perl?
by Khen1950fx (Canon) on May 20, 2010 at 10:01 UTC
    Here's an example to get you started. There are three commands: system, version, and exit. Note that subs for the commands start with "sub run_system", etc. Prefix run to the command. I don't have any Cisco devices, so I can't help you there.
    #!/usr/bin/perl use strict; use warnings; my $obj = cios->new(); $obj->cmdloop; package cios; use base qw(Term::Shell); use CPAN; sub prompt_str { my $cwd = 'cwd'; $cwd =~ s[^\Q$ENV{HOME}\E][~]; "cios> " } sub run_system { print "\nYour System:\n", "Perl $]\n", "$^O\n", "$0\n\n"; } sub run_version { my $mod = 'Term::Shell'; for $mod(CPAN::Shell->expand("Module", $mod)) { print "The current version is: ", $mod->cpan_version, "\n", "The installed version is: ", $mod->inst_version, "\n", $mod->inst_file, "\n"; } }
Re: A framework for a shell in perl?
by metaperl (Curate) on May 19, 2010 at 17:40 UTC