File Coverage

blib/lib/Test/AskAnExpert/Interface.pm
Criterion Covered Total %
statement 21 21 100.0
branch 3 4 75.0
condition n/a
subroutine 8 8 100.0
pod 5 5 100.0
total 37 38 97.3


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