AI-ExpertSystem-Simple
view release on metacpan or search on metacpan
lib/AI/ExpertSystem/Simple/Goal.pm view on Meta::CPAN
package AI::ExpertSystem::Simple::Goal;
use strict;
use warnings;
our $VERSION = '1.0';
sub new {
my ($class, $name, $message) = @_;
# Check the input
die "Goal->new() takes 2 arguments" if scalar(@_) != 3;
die "Goal->new() argument 1 (NAME) is undefined" if ! defined($name);
die "Goal->new() argument 2 (MESSAGE) is undefined" if ! defined($message);
# All OK, create the object
my $self = {};
$self->{_name} = $name;
$self->{_message} = $message;
return bless $self, $class;
}
sub is_goal {
my ($self, $name) = @_;
# Check the input
die "Goal->is_goal() takes 1 argument" if scalar(@_) != 2;
die "Goal->is_goal() argument 1 (NAME) is undefined" if ! defined($name);
# All OK, do the stuff
return $self->{_name} eq $name;
}
sub name {
my ($self) = @_;
# Check the input
die "Goal->name() takes no arguments" if scalar(@_) != 1;
# All OK, do the stuff
return $self->{_name};
}
sub answer {
my ($self, $value) = @_;
# Check the input
die "Goal->answer() takes 1 argument" if scalar(@_) != 2;
die "Goal->answer() argument 1 (VALUE) is undefined" if ! defined($value);
# All OK, do the stuff
my @text = ();
foreach my $word (split('\s', $self->{_message})) {
if($word eq $self->{_name}) {
push(@text, $value);
} else {
push(@text, $word);
}
}
return join(' ', @text);
}
1;
=head1 NAME
AI::ExpertSystem::Simple::Goal - Utility class for a simple expert system
=head1 VERSION
This document refers to verion 1.00 of AI::ExpertSystem::Simple::Goal, released April 25, 2003
( run in 0.877 second using v1.01-cache-2.11-cpan-39bf76dae61 )