in reply to Type::Tiny and anyOf, oneOf

Not exactly sure what you want to accomplish but "any of" sounds like a union:

use Types::Standard qw( ArrayRef HashRef ScalarRef ); my ( @thing1, %thing2, $thing3 ); my $union = ArrayRef | HashRef; $union->check( \@thing1 ); # true $union->check( \%thing1 ); # true $union->check( \$thing1 ); # false ( ArrayRef | HashRef | ScalarRef )->check( \$thing1 ); # true

Replies are listed 'Best First'.
Re^2: Type::Tiny and anyOf, oneOf
by 1nickt (Canon) on Feb 03, 2021 at 00:04 UTC

    Thanks Toby. It probably can't be accomplished with a type. With a JSON Schema you can say about an object (Dict) that it must contain one of a list of (named) keys each with their own type. You could require either a phone number or an email address, for example. So something like:

    my $check = compile(Dict[ foo => Str, oneOf => [ baz => Int, qux => Str, ], ]);


    The way forward always starts with a minimal test.