NAME
Physics::Balls::Error - a flagged refusal, returned and never thrown
VERSION
Version 0.01
SYNOPSIS
my $out = Physics::Balls->strike($world, %shot);
if ($out->error) {
print $out->code, ': ', $out->message, "\n";
print "too hard\n" if $out->bad_power;
}
DESCRIPTION
Every refusal is one of these, so a caller tests error and reads code rather than parsing a string. The codes are no_ball, bad_direction, bad_power, bad_spin, bad_layout, overlap and engine, each also a true attribute on the object.
METHODS
of
my $err = Physics::Balls::Error->of('bad_power', 'got 1200');
code
The code.
message
The sentence for the code, with the detail after a colon when there is one.
detail
What was wrong, when the refusal can say.
error
Always true.
FLAGS
Each code is also a method that is true on an error of that code and false otherwise, so a caller can test $err->bad_power without comparing strings.
no_ball
The shot names a ball that is not in the layout.
bad_direction
dx and dy must be integers within plus or minus 1,000,000 and not both zero.
bad_power
power must be an integer from 0 to 1000.
bad_spin
sx and sy must be integers from -500 to 500.
bad_layout
A layout is a list of [id, x, y] integers with distinct ids.
overlap
Two balls in the layout are more than a tenth of a millimetre inside each other.
engine
The engine gave up; the detail says why.