NAME
Test::Proto::Where - provide case switching using Test::Proto
VERSION
0.001
SYNOPSIS
print test_subject {foo=>'bar'} =>
where [], sub{ 'Empty array' },
where pHash, sub{ 'A hash' },
otherwise sub { 'Something else' };
Uses Test::Proto and its upgrading feature to implement a dispatch.
Note: This module is presently EXPERIMENTAL: it is a working proof of concept.
SYNTAX
test_subject
Takes as its first argument a prototype, which must not be a list of bare array/hash. It then takes one or more where/otherwise statements, as described below. If it does not get the arguments it requires, it will die
.
If you are taking the first argument from a function or method call, you should use scalar to force scalar context, like this:
test_subject scalar($obj->method) =>
where ...
Note also that because test_subject takes where and otherwise as arugments, if you are enclosing the first argument in brackets you must enclose all the arguments in brackets, other wise perl will be confused and think you are only passing the first argument.
where
where
is followed by a test, then an instruction. If the test passes, the instruction is carried out and no other 'where' or 'otherwise' statements are executed.
otherwise
otherwise
is followed an instruction. If no preceding where tests have passed, this instruction will be executed.