p5-type-tiny
p5-type-tiny copied to clipboard
Optional accepts multiple parameters, only uses the first, but refers to all of them in error messages
More of a footgun then anything else, but if one mistakenly passes two parameters to Optional, the resultant error message contains both, which can confuse the end user:
perl -MTypes::Standard=-all -e 'Optional([Str,CodeRef])->assert_valid(sub{})'
Reference sub { "DUMMY" } did not pass type constraint "Optional[Str,CodeRef]" at -e line 1
Reference sub { "DUMMY" } did not pass type constraint "Optional[Str,CodeRef]"
$_ exists
"Optional[Str,CodeRef]" constrains $_ with "Str" if it exists
"Str" is a subtype of "Value"
Reference sub { "DUMMY" } did not pass type constraint "Value"
"Value" is defined as: (defined($_) and not ref($_))