'Data::Constraint'
->add_constraint(
'FortyTwo'
,
'run'
=>
sub
{
defined
$_
[1] and not
ref
$_
[1] and
$_
[1] eq 42 },
'description'
=>
'True if the value reveals the answer to life, the universe, and everything'
,
);
my
$type
= to_TypeTiny(
'Data::Constraint'
->get_by_name(
'FortyTwo'
) );
should_pass( 42,
$type
);
should_fail(
"42.0"
,
$type
);
should_fail( [ 42 ],
$type
);
should_fail(
undef
,
$type
);
my
$e
= exception {
$type
->(43) };
like
$e
,
qr/Value "43" did not pass type constraint "FortyTwo"/
,
'error message'
;
done_testing;