use Moose::Meta::TypeCoercion::Union;
+use List::MoreUtils qw(all);
use List::Util qw(first);
use base 'Moose::Meta::TypeConstraint';
};
}
+sub has_inlined_type_constraint {
+ my $self = shift;
+
+ return all { $_->has_inlined_type_constraint }
+ @{ $self->type_constraints };
+}
+
+sub _inline_check {
+ my $self = shift;
+ my $val = shift;
+
+ return
+ join ' || ', map { '(' . $_->_inline_check($val) . ')' }
+ @{ $self->type_constraints };
+};
sub equals {
my ( $self, $type_or_name ) = @_;
( bless {}, 'DuckLike' ),
],
reject => [
- 'Thing',
$ZERO,
$ONE,
$INT,
'Enumerated', {
accept => \@allowed,
reject => [
- 'Thing',
$ZERO,
$ONE,
$INT,
}
{
+ my $union = Moose::Meta::TypeConstraint::Union->new(
+ type_constraints => [
+ find_type_constraint('Int'),
+ find_type_constraint('Object'),
+ ],
+ );
+
+ test_constraint(
+ $union, {
+ accept => [
+ $ZERO,
+ $ONE,
+ $INT,
+ $NEG_INT,
+ $FH_OBJECT,
+ $REGEX,
+ $REGEX_OBJ,
+ $OBJECT,
+ ],
+ reject => [
+ $NUM,
+ $NEG_NUM,
+ $EMPTY_STRING,
+ $STRING,
+ $NUM_IN_STRING,
+ $SCALAR_REF,
+ $SCALAR_REF_REF,
+ $ARRAY_REF,
+ $HASH_REF,
+ $CODE_REF,
+ $GLOB,
+ $GLOB_REF,
+ $FH,
+ $UNDEF,
+ ],
+ }
+ );
+}
+
+{
package DoesRole;
use Moose;