Skip Menu |

This queue is for tickets about the Type-Tiny CPAN distribution.

Report information
The Basics
Id: 121841
Status: rejected
Priority: 0/
Queue: Type-Tiny

People
Owner: perl [...] toby.ink
Requestors: perl [...] toby.ink
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Support `any_of`, `all_of`, `one_of`, and `none_of` in options hash to `compile_named`
Inspired by Params::Validate::Dependencies.
Attached is a pretty complete implementation.
Subject: anyof-allof-oneof.pl
use v5.16; use B; sub aoaooono { my ($hash, $style, $quote_keys) = @_; my $process_element = sub { my $element = shift; ref $element eq 'HASH' ? aoaooono($element, $style, $quote_keys) : sprintf( $style, $quote_keys && $element !~ /\A[a-z_][a-z0-9_]*\z/i ? B::cstring($element) : $element, ); }; my $process_elements = sub { my ($arrayref, $join) = @_; return $arrayref->[0]->$process_element if @$arrayref == 1; sprintf '(%s)', join " $join " => map $_->$process_element, @$arrayref; }; if ($hash->{any_of}) { $hash->{any_of}->$process_elements('or'); } elsif ($hash->{all_of}) { $hash->{all_of}->$process_elements('and'); } elsif ($hash->{one_of}) { $hash->{one_of}->$process_elements('xor'); } elsif ($hash->{none_of}) { '!' . $hash->{none_of}->$process_elements('or'); } } say aoaooono({ any_of => [ 'foo', { all_of => ['bar', 'baz', { none_of => ['instant-death'] }] }, { one_of => [qw/ quux quuux quuuux /] }, ], },'exists $_{%s}', !!1);
On further thought, let's keep Type::Params' options more limited and avoid overcomplicating things. This sort of thing is easy to achieve by making the parameters optional and checking the necessary combinations in the body of the sub.