use
5.008001;
BEGIN {
$Type::Coercion::Union::AUTHORITY
=
'cpan:TOBYINK'
;
$Type::Coercion::Union::VERSION
=
'2.008000'
;
}
$Type::Coercion::Union::VERSION
=~
tr
/_//d;
sub
_croak ($;@) {
require
Error::TypeTiny;
goto
\
&Error::TypeTiny::croak
}
our
@ISA
=
'Type::Coercion'
;
sub
_preserve_type_constraint {
my
$self
=
shift
;
$self
->{_union_of} =
$self
->{type_constraint}->type_constraints
if
$self
->{type_constraint};
}
sub
_maybe_restore_type_constraint {
my
$self
=
shift
;
if
(
my
$union
=
$self
->{_union_of} ) {
return
Type::Tiny::Union->new(
type_constraints
=>
$union
);
}
return
;
}
sub
type_coercion_map {
my
$self
=
shift
;
Types::TypeTiny::assert_TypeTiny(
my
$type
=
$self
->type_constraint );
$type
->isa(
'Type::Tiny::Union'
)
or _croak
"Type::Coercion::Union must be used in conjunction with Type::Tiny::Union"
;
my
@c
;
for
my
$tc
(
@$type
) {
next
unless
$tc
->has_coercion;
push
@c
, @{
$tc
->coercion->type_coercion_map };
}
return
\
@c
;
}
sub
add_type_coercions {
my
$self
=
shift
;
_croak
"Adding coercions to Type::Coercion::Union not currently supported"
if
@_
;
}
sub
_build_moose_coercion {
my
$self
=
shift
;
my
%options
= ();
$options
{type_constraint} =
$self
->type_constraint
if
$self
->has_type_constraint;
my
$r
=
"Moose::Meta::TypeCoercion::Union"
->new(
%options
);
return
$r
;
}
sub
can_be_inlined {
my
$self
=
shift
;
Types::TypeTiny::assert_TypeTiny(
my
$type
=
$self
->type_constraint );
for
my
$tc
(
@$type
) {
next
unless
$tc
->has_coercion;
return
!!0
unless
$tc
->coercion->can_be_inlined;
}
!!1;
}
1;