NAME

Physics::Balls::Error - a flagged refusal, returned and never thrown

VERSION

Version 0.06

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, bad_kind, bad_adjust, bad_roll, 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] or [id, x, y, kind] integers with distinct ids.

bad_kind

A row's kind is not an integer index into the kinds the world declares. A world with no kinds accepts kind 0 only.

bad_adjust

The adjust fields are not integers in range: adjust_at any integer, adjust_axis 0 or 1, adjust_dir 1 or -1, adjust_mu and adjust_curve 0 to 100000.

bad_roll

The release roll is not a direction within plus or minus 1,000,000, not both zero, with a spin from 0 to 1000.

overlap

Two balls in the layout are more than a tenth of a millimetre inside each other, at the touching distance of their kinds.

engine

The engine gave up; the detail says why.