| AI-ExpertSystem-Advanced documentation | Contained in the AI-ExpertSystem-Advanced distribution. |
AI::ExpertSystem::Advanced::Viewer::Terminal - Viewer for terminal
Extends from AI::ExpertSystem::Advanced::Viewer::Base and its main purpose is to interact with a (console) terminal.
A Term::ReadLine instance.
Basically just prints the given $msg but prepends the "DEBUG" string to it.
Simply prints the given $msg.
Will prepend the "ERROR:" word to the given message and then will call
print().
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.
Explains what happened.
Pablo Fischer (pablo@pablo.com.mx).
Copyright (C) 2010 by Pablo Fischer.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| 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;