Skip to content

Commit

Permalink
Remove a couple spots where we check for MMTC or Specio classes in fa…
Browse files Browse the repository at this point in the history
…vor duck type checks
  • Loading branch information
autarch committed May 15, 2016
1 parent ff224eb commit f18f44c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
22 changes: 7 additions & 15 deletions lib/Moose/Meta/Attribute.pm
Expand Up @@ -324,21 +324,12 @@ sub _process_isa_option {

# allow for anon-subtypes here ...
#
# Checking for Specio explicitly is completely revolting. At some point
# this needs to be refactored so that Moose core defines a standard type
# API that all types must implement. Unfortunately, the current core API
# is _not_ the right API, so we probably need to A) come up with the new
# API (Specio is a good start); B) refactor the core types to implement
# that API; C) do duck type checking on type objects.
# There are a _lot_ of methods that we expect from TC objects, but
# checking for a specific parent class via ->isa is gross, so we'll check
# for at least one method.
if ( blessed( $options->{isa} )
&& $options->{isa}->isa('Moose::Meta::TypeConstraint') ) {
$options->{type_constraint} = $options->{isa};
}
elsif (
blessed( $options->{isa} )
&& $options->{isa}->can('does')
&& $options->{isa}->does('Specio::Constraint::Role::Interface')
) {
&& $options->{isa}->can('has_coercion') ) {

$options->{type_constraint} = $options->{isa};
}
else {
Expand All @@ -357,7 +348,8 @@ sub _process_does_option {

# allow for anon-subtypes here ...
if ( blessed( $options->{does} )
&& $options->{does}->isa('Moose::Meta::TypeConstraint') ) {
&& $options->{does}->can('has_coercion') ) {

$options->{type_constraint} = $options->{does};
}
else {
Expand Down
4 changes: 1 addition & 3 deletions lib/Moose/Meta/Method/Accessor/Native/Collection.pm
Expand Up @@ -87,9 +87,7 @@ sub _check_new_members_only {
# not Paramet_erized_), we don't know what is being checked by the
# constraint, so we need to check the whole value, not just the members.
return 1
if $self->_is_root_type( $tc->parent )
&& ( $tc->isa('Moose::Meta::TypeConstraint::Parameterized')
|| $tc->isa('Specio::Constraint::Parameterized') );
if $self->_is_root_type( $tc->parent ) && !$tc->can('parameterize');

return 0;
}
Expand Down

0 comments on commit f18f44c

Please sign in to comment.