Subject: | Types::Standard: is it possible to check for an empty ArrayRef/HashRef? |
Date: | Tue, 22 Oct 2013 14:22:19 +0200 |
To: | bug-Type-Tiny [...] rt.cpan.org |
From: | BPJ <bpj [...] melroch.se> |
Is it possible to check for an empty ArrayRef or
HashRef with Types::Standard? The problem is I want
to make a constraint which accepts either an empty ref
or a ref with some specific (type of) contents. It seems now I can
only
accept either a ref with some specific content (Tuple/Map),
a ref with some specific type of content (ArrayRef/HashRef with
params)
or a ref with any content (ArrayRef/HashRef without params).
To be sure I can do something like
my $empty_hash = declare 'EmptyHashRef',
as HashRef, where { 0 == keys %$_ };
my $foo = union [ $empty_hash, Map[ Str, Str ] ];
but I see myself doing this all the time, so it would be nice if
EmptyArrayRef and EmptyHashRef or something with the same effect
were bundled in.
/bpj