9 use Moose::Util::TypeConstraints;
15 inline_as { "defined $_[1] && ! ref $_[1] && $_[1] !~ /Q/" };
17 subtype 'NotInlinable',
22 my $inlinable = find_type_constraint('Inlinable');
23 my $not_inlinable = find_type_constraint('NotInlinable');
27 $inlinable->has_inlined_type_constraint,
28 'Inlinable returns true for has_inlined_type_constraint'
32 $inlinable->_inline_check('$foo'),
33 'defined $foo && ! ref $foo && $foo !~ /Q/',
34 'got expected inline code for Inlinable constraint'
38 !$not_inlinable->has_inlined_type_constraint,
39 'NotInlinable returns false for has_inlined_type_constraint'
43 exception { $not_inlinable->_inline_check('$foo') },
44 qr/Cannot inline a type constraint check for NotInlinable/,
45 'threw an exception when asking for inlinable code from type which cannot be inlined'
50 my $aofi = Moose::Util::TypeConstraints::find_or_create_type_constraint(
51 'ArrayRef[Inlinable]');
54 $aofi->has_inlined_type_constraint,
55 'ArrayRef[Inlinable] returns true for has_inlined_type_constraint'
59 $aofi->_inline_check('$foo'),
60 '&List::MoreUtils::all( sub { defined $_ && ! ref $_ && $_ !~ /Q/ }, @{$foo} )',
61 'got expected inline code for ArrayRef[Inlinable] constraint'
64 my $aofni = Moose::Util::TypeConstraints::find_or_create_type_constraint(
65 'ArrayRef[NotInlinable]');
68 !$aofni->has_inlined_type_constraint,
69 'ArrayRef[NotInlinable] returns false for has_inlined_type_constraint'
73 subtype 'ArrayOfInlinable',
74 as 'ArrayRef[Inlinable]';
76 subtype 'ArrayOfNotInlinable',
77 as 'ArrayRef[NotInlinable]';
80 local $TODO = 'A subtype of a Parameterized type should not be a Parameterizable type';
82 my $aofi = Moose::Util::TypeConstraints::find_or_create_type_constraint(
83 'ArrayRef[Inlinable]');
86 $aofi->has_inlined_type_constraint,
87 'ArrayOfInlinable returns true for has_inlined_type_constraint'
92 my $hoaofi = Moose::Util::TypeConstraints::find_or_create_type_constraint(
93 'HashRef[ArrayRef[Inlinable]]');
96 $hoaofi->has_inlined_type_constraint,
97 'HashRef[ArrayRef[Inlinable]] returns true for has_inlined_type_constraint'
101 $hoaofi->_inline_check('$foo'),
102 '&List::MoreUtils::all( sub { &List::MoreUtils::all( sub { defined $_ && ! ref $_ && $_ !~ /Q/ }, @{$_} ) }, values %{$foo} )',
103 'got expected inline code for HashRef[ArrayRef[Inlinable]] constraint'
106 my $hoaofni = Moose::Util::TypeConstraints::find_or_create_type_constraint(
107 'HashRef[ArrayRef[NotInlinable]]');
110 !$hoaofni->has_inlined_type_constraint,
111 'HashRef[ArrayRef[NotInlinable]] returns false for has_inlined_type_constraint'
116 my $iunion = Moose::Util::TypeConstraints::find_or_create_type_constraint(
117 'Inlinable | Object');
120 $iunion->has_inlined_type_constraint,
121 'Inlinable | Object returns true for has_inlined_type_constraint'
125 $iunion->_inline_check('$foo'),
126 '(defined $foo && ! ref $foo && $foo !~ /Q/) || (Scalar::Util::blessed( $foo ))',
127 'got expected inline code for Inlinable | Object constraint'
130 my $niunion = Moose::Util::TypeConstraints::find_or_create_type_constraint(
131 'NotInlinable | Object');
134 !$niunion->has_inlined_type_constraint,
135 'NotInlinable | Object returns false for has_inlined_type_constraint'
140 my $iunion = Moose::Util::TypeConstraints::find_or_create_type_constraint(
141 'Object | Inlinable');
144 $iunion->has_inlined_type_constraint,
145 'Object | Inlinable returns true for has_inlined_type_constraint'
149 $iunion->_inline_check('$foo'),
150 '(Scalar::Util::blessed( $foo )) || (defined $foo && ! ref $foo && $foo !~ /Q/)',
151 'got expected inline code for Object | Inlinable constraint'
154 my $niunion = Moose::Util::TypeConstraints::find_or_create_type_constraint(
155 'Object | NotInlinable');
158 !$niunion->has_inlined_type_constraint,
159 'Object | NotInlinable returns false for has_inlined_type_constraint'
164 my $iunion = Moose::Util::TypeConstraints::find_or_create_type_constraint(
165 'Object | Inlinable | CodeRef');
168 $iunion->has_inlined_type_constraint,
169 'Object | Inlinable | CodeRef returns true for has_inlined_type_constraint'
173 $iunion->_inline_check('$foo'),
174 q{(Scalar::Util::blessed( $foo )) || (defined $foo && ! ref $foo && $foo !~ /Q/) || (ref $foo eq 'CODE')},
175 'got expected inline code for Object | Inlinable | CodeRef constraint'
178 my $niunion = Moose::Util::TypeConstraints::find_or_create_type_constraint(
179 'Object | NotInlinable | CodeRef');
182 !$niunion->has_inlined_type_constraint,
183 'Object | NotInlinable | CodeRef returns false for has_inlined_type_constraint'