line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Smart::Interface; |
2
|
|
|
|
|
|
|
|
3
|
4
|
|
|
4
|
|
19668
|
use strict; |
|
4
|
|
|
|
|
8
|
|
|
4
|
|
|
|
|
120
|
|
4
|
4
|
|
|
4
|
|
25
|
use warnings; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
128
|
|
5
|
4
|
|
|
4
|
|
1094
|
use Test::Smart::Question; |
|
4
|
|
|
|
|
7
|
|
|
4
|
|
|
|
|
861
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 NAME |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Test::Smart::Interface - the superclass of all L Interfaces |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 DESCRIPTION |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Test::Smart::Interface provides a base class for classes providing an Interface |
14
|
|
|
|
|
|
|
to the testing system, simulating a computer actually answering the Human |
15
|
|
|
|
|
|
|
Intelligent question. Any implementing class should override all of the |
16
|
|
|
|
|
|
|
provided placeholders or else tests will be skipped. |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
=head1 SYNOPSIS |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
package Test::Smart::Interface::Implementation; |
21
|
|
|
|
|
|
|
use base qw(Test::Smart::Interface); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub load { |
24
|
|
|
|
|
|
|
# Do any loading |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Methods: |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub submit { |
30
|
|
|
|
|
|
|
# Submit a question |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub has_answer { |
34
|
|
|
|
|
|
|
# See if theres an answer |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub answer { |
38
|
|
|
|
|
|
|
# Go get it |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
If you have problems, return undef on error and set the error using your |
42
|
|
|
|
|
|
|
inherited err method: |
43
|
|
|
|
|
|
|
SUPER->err("The moon is in the wrong phase"); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 DETAILS |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Test::Smart::Interface is just that, an interface specification. Please fully |
48
|
|
|
|
|
|
|
implement any subclass, otherwise tests will just skip. Except for maybe the |
49
|
|
|
|
|
|
|
constructor, if you don't need to do anything there. |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 load() |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This is your constructor, you may specify any other parameters you like or need |
54
|
|
|
|
|
|
|
to set your interface up, just document them well. |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub load { |
59
|
1
|
|
|
1
|
1
|
12
|
my $class = shift; |
60
|
1
|
|
|
|
|
5
|
return bless({},$class); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 submit($question,$name) |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Questions are submitted to the Interface through this method, which recieves |
66
|
|
|
|
|
|
|
a plain text question and a test name. Do whatever magic is necessary to |
67
|
|
|
|
|
|
|
send your question here and return an instance of Test::Smart::Question with |
68
|
|
|
|
|
|
|
the appropriate and any extra fields you may need populated. Or return undef |
69
|
|
|
|
|
|
|
and set err if you run into problems. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Consult the documentation of L for details on populating |
72
|
|
|
|
|
|
|
it. The provided submit creates one with the skip flag set, you probably don't |
73
|
|
|
|
|
|
|
want this. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=cut |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub submit { |
78
|
1
|
|
|
1
|
1
|
653
|
my ($self,$question,$name) = @_; |
79
|
1
|
|
|
|
|
10
|
return Test::Smart::Question->new(question => $question, name => $name, id => "skip", skip => "No Interface Loaded"); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 answer($question_obj) |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
This method is used to retrieve an answer and populate it into the $QuestionObj |
85
|
|
|
|
|
|
|
provided. Consult L's documentation on how to do that. |
86
|
|
|
|
|
|
|
It should return true on success and undef on failure. You are allowed to set |
87
|
|
|
|
|
|
|
the skip flag here, its what the default does. |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub answer { |
92
|
1
|
|
|
1
|
1
|
3
|
my($self,$Qobj) = @_; |
93
|
1
|
50
|
|
|
|
6
|
return undef unless $Qobj->isa('Test::Smart::Question'); |
94
|
|
|
|
|
|
|
|
95
|
1
|
|
|
|
|
4
|
$Qobj->skip("No Interface Loaded"); |
96
|
1
|
|
|
|
|
3
|
return 1; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 has_answer($Qobj) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
This method should return true when there is an answer available for the passed |
102
|
|
|
|
|
|
|
question, but should not modify the object. This is because it is often easier |
103
|
|
|
|
|
|
|
or cheaper to see if the answer is there than to actually go get it. The |
104
|
|
|
|
|
|
|
default just returns true, you probably shouldn't use it. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub has_answer { |
109
|
1
|
|
|
1
|
1
|
5
|
return 1; |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 err([$message]) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
If there was an error in calling any of the above methods set an error string |
115
|
|
|
|
|
|
|
with this method. Calling err with no arguments returns the current error (if |
116
|
|
|
|
|
|
|
any). |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub err { |
121
|
12
|
|
|
12
|
1
|
340
|
my($self,$err) = @_; |
122
|
12
|
100
|
|
|
|
41
|
$self->{err} = $err if $err; |
123
|
12
|
|
|
|
|
142
|
return $self->{err}; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head1 SEE ALSO |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L, L |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 AUTHOR |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
Edgar A. Bering, Etrizor@gmail.comE |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
Copyright (C) 2007 by Edgar A. Bering |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
139
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
140
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |