NAME

Punk::Model::Computed::Error - a visitor's input a computed backend will not take, naming its field

SYNOPSIS

my $runs = eval { $c->model('TimeRun')->search({ rule => $expr }) };
if (ref $@ && $@->isa('Punk::Model::Computed::Error')) {
    return $c->json({ error => $@ }, 400);
}

Punk::Model::Computed::Error->throw(zone => "no time zone is called 'Mars/Olympus'");

DESCRIPTION

What a Punk::Model::Computed backend dies with when a visitor's input will not do: a field (the filter field at fault) and a message (a sentence for the visitor). It stringifies to the message, and TO_JSON gives both, so it can be returned as a JSON body as it is.

A program's misuse of a backend (a field the model does not declare, an operator or an option the backend does not take) croaks with a plain string instead: that is the program's fault, not the visitor's.

A subclass of this class is an error of this kind too: from and "wrap" in Punk::Model::Computed pass one through unchanged.

METHODS

new

my $e = Punk::Model::Computed::Error->new($field, $message);

throw

Punk::Model::Computed::Error->throw($field, $message);

Dies with a new error of the class it is called on.

from

my $e = Punk::Model::Computed::Error->from($field, $@);

The error a die becomes: the die itself when it is one of these already, else a new one for $field with the die's text as "said" gives it.

said

my $text = Punk::Model::Computed::Error->said($@);

A die's text as a visitor should read it: without the at FILE line N. it ends with (and perl's , <FH> line N after that), and without a leading Class->method:, the way a module's croak names itself. So Time::Keeper->new: no such month at lib/Time/Keeper.pm line 40. is no such month. An object is its string.

field

message

TO_JSON

{ field => ..., message => ... }.

SEE ALSO

Punk::Model::Computed, Punk::Validate.