+ - support isa and coerce together for Moose
- guard _accessor_maker_for calls in Moo::Role in case Moo isn't loaded
- reset handlemoose state on mutation in case somebody reified the
metaclass too early
$spec{is} = 'ro' if $spec{is} eq 'lazy' or $spec{is} eq 'rwp';
delete $spec{asserter};
if (my $isa = $spec{isa}) {
- $spec{isa} = do {
+ my $tc = $spec{isa} = do {
if (my $mapped = $TYPE_MAP{$isa}) {
$mapped->();
} else {
);
}
};
- die "Aaaargh" if $spec{coerce};
+ if (my $coerce = $spec{coerce}) {
+ $tc->coercion(Moose::Meta::TypeCoercion->new)
+ ->_compiled_type_coercion($coerce);
+ $spec{coerce} = 1;
+ }
} elsif (my $coerce = $spec{coerce}) {
my $attr = perlstring($name);
my $tc = Moose::Meta::TypeConstraint->new(
'my $r = $_[42]{'.$attr.'}; $_[42]{'.$attr.'} = 1; $r'
},
);
- $tc->coercion(Moose::Meta::TypeCoercion->new)
- ->_compiled_type_coercion($coerce);
- $spec{isa} = $tc;
- $spec{coerce} = 1;
+ $tc->coercion(Moose::Meta::TypeCoercion->new)
+ ->_compiled_type_coercion($coerce);
+ $spec{isa} = $tc;
+ $spec{coerce} = 1;
}
push @attrs, $meta->add_attribute($name => %spec);
}
has output_to => (
isa => quote_sub(q{
- use Scalar::Util qw/ blessed /;
- die $_[0] . "Does not have a ->consume method" unless blessed($_[0]) && $_[0]->can('consume'); }),
+ use Scalar::Util ();
+ die $_[0] . "Does not have a ->consume method" unless Scalar::Util::blessed($_[0]) && $_[0]->can('consume'); }),
is => 'ro',
required => 1,
coerce => quote_sub(q{
- my %stuff = %{$_[0]};
- my $class = delete($stuff{class});
- $class->new(%stuff);
+ use Scalar::Util ();
+ if (Scalar::Util::blessed($_[0]) && $_[0]->can('consume')) {
+ $_[0];
+ } else {
+ my %stuff = %{$_[0]};
+ my $class = delete($stuff{class});
+ $class->new(%stuff);
+ }
}),
);
}