Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Type::Tiny and anyOf, oneOf

by tobyink (Canon)
on Feb 02, 2021 at 23:46 UTC ( #11127840=note: print w/replies, xml ) Need Help??

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 (Abbot) 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.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11127840]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (3)
As of 2021-10-17 19:06 GMT
Find Nodes?
    Voting Booth?
    My first memorable Perl project was:

    Results (72 votes). Check out past polls.