
;#	eval_perl_expression - provide a perl based CLI
;#
;#	this gives you lots of functionality.  You can enter perl statements,
;#	make aliases to run unix commands, recall previous commands, edit
;#	them, push menus, and more.  It's a good start, now I just have to
;#	completely rewrite it!  Note that &get_input() actually does a lot
;#	of the work.  BUG: if you push a CLI, and then push a menu of any
;#	sort, and then push another CLI, your history gets clobbered.

$cmds{'eval_perl_expression'} = '&eval_perl_expression';
if (! defined($production)) {
    $keep_looping = 1;
} else {
    $keep_looping = 0;
}

sub eval_perl_expression {
    push(@menu_stack, "&eval_perl_expression");
    print TTYOUT "\n";
    @command_history = @perl_history;
    $perl_exp = "?"; # put something there to get into the loop
    while ($perl_exp !~ /^$/ || $keep_looping) {
	($perl_exp =~ /^$/) && break;
	print TTYOUT "\n";
	&get_input("perl $dir_prompt>> ");
	$perl_exp = $command_history[$#command_history];
	@alias_args = split(' ', $perl_exp);
	
	;# ok, this has room for vast improvement.  Aliases are
	;# defined in your ~/.SoftListrc
	if ($aliases{$alias_args[$[]}) {
	    eval $aliases{$alias_args[$[]};
	    
	    ;# this funny line here seems to make menus and the
	    ;# CLI work ok if they are interspersed...however..
	    ;# if you use an alias to call a menu, and then push
	    ;# another CLI, your history can be clobbered.  This
	    ;# isn't a biggie to deal with right now, but it's
	    ;# there.
	    
	    $perl_exp = "?";
	} else {
	    if ($perl_exp !~ /^$/) {
		print TTYOUT "\n";
		if ($perl_exp =~ /^!/) {
		    system(substr ($perl_exp, 1));
		} else {
		    eval $perl_exp;
		    print TTYOUT $@;
		}
	    }
	}
    }
    @perl_history = @command_history;
    &pop_level;
    1;
}
1;
