The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Test::Smart::Question - Data wrapper for Test::Smart questions

DESCRIPTION

This object provides basic semantics and data encapsulation for Test::Smart questions, feel free to subclass it as you need when writing Interfaces.

SYNOPSIS

  use Test::Smart::Question;

  $Qobj = Test::Smart::Question->new(question => "I can has cheesburger?",
                                     name     => "Cheesburger",
                                     id       => "Uniq123");

  $Qobj->skip("The person being asked doesn't know how to answer");
  $Qobj->test;

  $Qobj->answer('yes','commentary or diagnostics');
  ($answer,$comment) = $Qobj->answer;
  $answer = $Qobj->answer;

DETAILS

new(question => $question_text,id => $uniq_id, [name => $test_name,skip => $reason,other_key => $other_value])

The constructor takes its params as a hash, requiring question and id and optionally taking name and skip. If skip is set it is equivalent to calling $Qobj->skip("Reason") with all of the semantic implications (you can no longer provide an answer unless you explicitly call $Qobj->test).

Test::Smart::Question also stores any other keys given to it in the blessed hashref for the convinence of any Interface implementer who doesn't need a full subclass. These should probably be treated as private unless documented otherwise in the Interface's documentation.

question

This is a read only accessor for the question string provided at object construction. If you try to set question it simply ignores the pass.

id

Like question but for the constructor set ID.

name([$new_name])

Mutator for the stored test name. This value is used when answering the question for TAP output in the same way as the second parameter to ok

skip([$reason])

Sets the internal skip value. Once set it cannot be undefed unless you use $Qobj->test to indicate you do indeed want to test with this Question. While a skip reason is set the object will silently reject answers submitted to it.

test

Indicate to the object that you're going to test it, which means it should accept an answer and clear skip.

answer([$answer, $comment])

Mutator for the object's stored answer. When setting it the first parameter must match /yes|no/i and should reflect the answer provided by the person. If diagnostics or commentary is required it is provided in the $comment param, though this is optional.

If there is currently a reason for skipping set (either through skip or in the constructor) then answer will simply return undef and do nothing. You also cannot retrieve the answer if skip gets set.

SUBCLASSING

If you want to make a custom interface for Test::Smart look at Test::Smart::Interface. If you do find the need to write something so fancy that you must also subclass this, make sure your subclass is a perfect drop-in replacement or else you'll break Test::Smart itsself.

SEE ALSO

Test::Smart, Test::Smart::Interface

AUTHOR

Edgar A. Bering, <trizor@gmail.com>

COPYRIGHT AND LICENSE

Copyright (C) 2007 by Edgar A. Bering

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.