"Cannot add additional type coercions to Union types '$self'");
}
- my $coercions = ($self->{coercion_map} ||= []);
- my %has = map{ $_->[0] => undef } @{$coercions};
+ my $coercion_map = ($self->{coercion_map} ||= []);
+ my %has = map{ $_->[0]->name => undef } @{$coercion_map};
for(my $i = 0; $i < @_; $i++){
my $from = $_[ $i];
or $self->throw_error(
"Could not find the type constraint ($from) to coerce from");
- push @{$coercions}, [ $type => $action ];
+ push @{$coercion_map}, [ $type => $action ];
}
$self->_compile_type_coercion();
sub _compile_type_coercion {
my($self) = @_;
- my @coercions = @{$self->{coercion_map}};
+ my @coercions;
+
+ foreach my $pair(@{$self->{coercion_map}}) {
+ push @coercions, [ $pair->[0]->_compiled_type_constraint, $pair->[1] ];
+ }
$self->{_compiled_type_coercion} = sub {
my($thing) = @_;
foreach my $pair (@coercions) {
#my ($constraint, $converter) = @$pair;
- if ($pair->[0]->check($thing)) {
+ if ($pair->[0]->($thing)) {
local $_ = $thing;
return $pair->[1]->($thing);
}
return 1;
}
-sub _as_string { $_[0]->name } # overload ""
-sub _identity; # overload 0+
+# overloading stuff
+
+sub _as_string { $_[0]->name } # overload ""
+sub _identity; # overload 0+
sub _unite { # overload infix:<|>
my($lhs, $rhs) = @_;
=head1 VERSION
-This document describes Mouse version 0.81
+This document describes Mouse version 0.86
=head1 DESCRIPTION