Simple/Goal.pm

filter: Statementstmt 100% 32 / 32 Branchbran 100% 18 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 6 / 6 Podpod 100% 4 / 4 totaltotal 100% 60 / 60 CC 11 SCAR 12.5
CC
11
Cov
100%
answer
5.0
new
4.0
is_goal
3.0
CRAP 3.5
« Simple/Rule.pm ↑ Summary Simple/Knowledge.pm »
1 package AI::ExpertSystem::Simple::Goal;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 our $VERSION = '1.0';
7  
8 6 ▶sub new {
Subroutine new: called CC=4 SCAR=13.9
Pod documented
9 6 my ($class, $name, $message) = @_;
10  
11 # Check the input
12  
13 6 ▶ die "Goal->new() takes 2 arguments" if scalar(@_) != 3;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ != 3 3 3 6
14 3 ▶ die "Goal->new() argument 1 (NAME) is undefined" if ! defined($name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 2 3
15 2 ▶ die "Goal->new() argument 2 (MESSAGE) is undefined" if ! defined($message);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $message 1 1 2
16  
17 # All OK, create the object
18  
19 1 my $self = {};
20  
21 1 $self->{_name} = $name;
22 1 $self->{_message} = $message;
23  
24 1 return bless $self, $class;
25 }
26  
27 5 ▶sub is_goal {
Subroutine is_goal: called CC=3 SCAR=11.0
Pod documented
28 5 my ($self, $name) = @_;
29  
30 # Check the input
31  
32 5 ▶ die "Goal->is_goal() takes 1 argument" if scalar(@_) != 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ != 2 2 3 5
33 3 ▶ die "Goal->is_goal() argument 1 (NAME) is undefined" if ! defined($name);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 1 2 3
34  
35 # All OK, do the stuff
36  
37 2 return $self->{_name} eq $name;
38 }
39  
40 2 ▶sub name {
Subroutine name: called CC=2 SCAR=6.9
Pod documented
41 2 my ($self) = @_;
42  
43 # Check the input
44  
45 2 ▶ die "Goal->name() takes no arguments" if scalar(@_) != 1;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ != 1 1 1 2
46  
47 # All OK, do the stuff
48  
49 1 return $self->{_name};
50 }
51  
52 4 ▶sub answer {
Subroutine answer: called CC=5 SCAR=16.1
Pod documented
53 4 my ($self, $value) = @_;
54  
55 # Check the input
56  
57 4 ▶ die "Goal->answer() takes 1 argument" if scalar(@_) != 2;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ != 2 2 2 4
58 2 ▶ die "Goal->answer() argument 1 (VALUE) is undefined" if ! defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 1 1 2
59  
60 # All OK, do the stuff
61  
62 1 my @text = ();
63  
64 1 foreach my $word (split('\s', $self->{_message})) {
65 4 ▶ if($word eq $self->{_name}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($word eq $self->{'_name'}) { } 1 3 4
66 1 push(@text, $value);
67 } else {
68 3 push(@text, $word);
69 }
70 }
71  
72 1 return join(' ', @text);
73 }
74  
75 1 1;
76  
77 =head1 NAME
78  
79 AI::ExpertSystem::Simple::Goal - Utility class for a simple expert system
80  
81 =head1 VERSION
82  
83 This document refers to verion 1.00 of AI::ExpertSystem::Simple::Goal, released April 25, 2003
84  
85 =head1 SYNOPSIS
86  
87 This class handles the goal in the expert system and returns the answer when the goal is matched.
88  
89 =head1 DESCRIPTION
90  
91 =head2 Overview
92  
93 This is a utility class for AI::ExpertSystem::Simple
94  
95 =head2 Constructors and initialisation
96  
97 =over 4
98  
99 =item new( NAME, MESSAGE )
100  
101 The constructor takes two arguments. The first, NAME, is the name of the attribute that when set will
102 trigger the end of the consoltation. The second argument, MESSAGE, is the text that will be interpolated
103 as the answer for the consoltation.
104  
105 =back
106  
107 =head2 Public methods
108  
109 =over 4
110  
111 =item is_goal( NAME )
112  
113 This method compares the given NAME with that of the attribute name given when the object was constructed and
114 returns true if they are the same or false if not.
115  
116 =item name( )
117  
118 This method return the value of the NAME argument that was set when the object was constructed.
119  
120 =item answer( VALUE )
121  
122 This method take VALUE to be the value of the goal attribute and will use it to interpolate and return the MESSAGE that was given
123 when the object was constructed.
124  
125 =back
126  
127 =head2 Private methods
128  
129 None
130  
131 =head1 ENVIRONMENT
132  
133 None
134  
135 =head1 DIAGNOSTICS
136  
137 =over 4
138  
139 =item Goal->new() takes 2 arguments
140  
141 When the constructor is initialised it requires two arguments. This message is given if more or less arguments were supplied.
142  
143 =item Goal->new() argument 1 (NAME) is undefined
144  
145 The correct number of arguments were supplied to the constructor, however the first argument, NAME, was undefined.
146  
147 =item Goal->new() argument 2 (MESSAGE) is undefined
148  
149 The correct number of arguments were supplied to the constructor, however the second argument, MESSAGE, was undefined.
150  
151 =item Goal->is_goal() takes 1 argument
152  
153 When the method is called it requires one argument. This message is given if more or less arguments were supplied.
154  
155 =item Goal->is_goal() argument 1 (NAME) is undefined
156  
157 The correct number of arguments were supplied with the method call, however the first argument, NAME, was undefined.
158  
159 =item Goal->name() takes no arguments
160  
161 When the method is called it takes no arguments. This message is given if some were supplied.
162  
163 =item Goal->answer() takes 1 argument
164  
165 When the method is called it requires one argument. This message is given if more or less arguments were supplied.
166  
167 =item Goal->answer() argument 1 (VALUE) is undefined
168  
169 The correct number of arguments were supplied with the method call, however the first argument, VALUE, was undefined.
170  
171 =back
172  
173 =head1 BUGS
174  
175 None to date
176  
177 =head1 FILES
178  
179 See Goal.t in the test directory
180  
181 =head1 SEE ALSO
182  
183 AI::ExpertSystem::Simple - The base class for the expert system shell
184  
185 AI::ExpertSystem::Simple::Knowledge - A utility class
186  
187 AI::ExpertSystem::Simple::Rules - A utility class
188  
189 =head1 AUTHORS
190  
191 Peter Hickman (peterhi@ntlworld.com)
192  
193 =head1 COPYRIGHT
194  
195 Copyright (c) 2003, Peter Hickman. All rights reserved.
196  
197 This module is free software. It may be used, redistributed and/or
198 modified under the same terms as Perl itself.
« Simple/Rule.pm ↑ Summary Simple/Knowledge.pm »