AI::ExpertSystem::Advanced::Viewer::Terminal - Viewer for terminal


AI-ExpertSystem-Advanced documentation Contained in the AI-ExpertSystem-Advanced distribution.

Index


Code Index:

NAME

Top

AI::ExpertSystem::Advanced::Viewer::Terminal - Viewer for terminal

DESCRIPTION

Top

Extends from AI::ExpertSystem::Advanced::Viewer::Base and its main purpose is to interact with a (console) terminal.

Attribtes

Top

readline

A Term::ReadLine instance.

Methods

Top

debug($msg)

Basically just prints the given $msg but prepends the "DEBUG" string to it.

print($msg)

Simply prints the given $msg.

print_error($msg)

Will prepend the "ERROR:" word to the given message and then will call print().

ask($message, @options)

Will be used to ask the user for some information. It will receive a string, the question to ask and an array of all the possible options.

explain($yaml_summary)

Explains what happened.

AUTHOR

Top

Pablo Fischer (pablo@pablo.com.mx).

COPYRIGHT

Top


AI-ExpertSystem-Advanced documentation Contained in the AI-ExpertSystem-Advanced distribution.
#
# AI::ExpertSystem::Advanced::Viewer::Terminal
#
# Author(s): Pablo Fischer (pfischer@cpan.org)
# Created: 12/13/2009 15:44:23 PST 15:44:23
package AI::ExpertSystem::Advanced::Viewer::Terminal;

use Moose;
use Term::UI;
use Term::ReadLine;

extends 'AI::ExpertSystem::Advanced::Viewer::Base';

our $VERSION = '0.02';

has 'readline' => (
        is => 'ro',
        isa => 'Term::ReadLine');

sub debug {
    my ($self, $msg) = @_;
    print "DEBUG: $msg\n";
}

sub print {
    my ($self, $msg) = @_;
    print "$msg\n";
}

sub print_error {
    my ($self, $msg) = @_;
    $self->print("ERROR: $msg");
}

sub ask {
    my ($self, $msg, $options) = @_;

    my %valid_choices = (
        'Y' => '+',
        'N' => '-',
        'U' => '~');

    my $reply = $self->{'readline'}->get_reply(
            prompt => $msg . ' ',
            choices => [qw|Y N U|]);
    return $valid_choices{$reply};
}

sub explain {
    my ($self, $summary) = @_;

    print $summary;
}


# Called when the object is created
sub BUILD {
    my ($self) = @_;

    $self->{'readline'} = Term::ReadLine->new('questions');
}

1;