my $meta = Mouse::Meta::Class->initialize("$class_or_role"); # "" for stringify
return map { $_ => $_ }
grep { $_ ne 'meta' && !Mouse::Object->can($_) && $_ =~ $handles }
- $meta->isa('Mouse::Meta::Class') ? $meta->get_all_method_names : $meta->get_method_list;
+ Mouse::Util::TypeConstraints::_is_a_metarole($meta)
+ ? $meta->get_method_list
+ : $meta->get_all_method_names;
}
else {
$self->throw_error("Unable to canonicalize the 'handles' option with $handles");
foreach my $super(@_){
Mouse::Util::load_class($super);
my $meta = Mouse::Util::get_metaclass_by_name($super);
- if($meta && $meta->isa('Mouse::Meta::Role')){
+ if(Mouse::Util::TypeConstraints::_is_a_metarole($meta)){
$self->throw_error("You cannot inherit from a Mouse Role ($super)");
}
}
package Mouse::Meta::Module;
use Mouse::Util qw/:meta get_code_package get_code_ref load_class not_supported/; # enables strict and warnings
+use Mouse::Util::TypeConstraints ();
+
use Carp ();
use Scalar::Util qw/blessed weaken/;
my $superclasses;
if(exists $options{superclasses}){
- if($self->isa('Mouse::Meta::Role')){
+ if(Mouse::Util::TypeConstraints::_is_a_metarole($self)){
delete $options{superclasses};
}
else{
my $instance;
- if($applicant->isa('Mouse::Meta::Class')){ # Application::ToClass
+ if(Mouse::Util::TypeConstraints::_is_a_metaclass($applicant)){ # Application::ToClass
$args{_to} = 'class';
}
- elsif($applicant->isa('Mouse::Meta::Role')){ # Application::ToRole
+ elsif(Mouse::Util::TypeConstraints::_is_a_metarole($applicant)){ # Application::ToRole
$args{_to} = 'role';
}
else{ # Appplication::ToInstance
my $role_name = $roles[-1][0];
load_class($role_name);
- my $metarole = get_metaclass_by_name($role_name);
- ( $metarole && $metarole->isa('Mouse::Meta::Role') )
+ Mouse::Util::TypeConstraints::_is_a_metarole( get_metaclass_by_name($role_name) )
|| $applicant->meta->throw_error("You can only consume roles, $role_name(".$role_name->meta.") is not a Mouse role");
}
sub list_all_type_constraints { keys %TYPE }
}
+# is-a predicates
+BEGIN{
+ _generate_class_type_for('Mouse::Meta::TypeConstraint' => '_is_a_type_constraint');
+ _generate_class_type_for('Mouse::Meta::Class' => '_is_a_metaclass');
+ _generate_class_type_for('Mouse::Meta::Role' => '_is_a_metarole');
+}
+
+
sub _create_type{
my $mode = shift;
return;
}
- if($meta->isa('Mouse::Meta::Role')){
+ if(_is_a_metarole($meta)){
return role_type($spec);
}
else{
sub find_type_constraint {
my($spec) = @_;
- return $spec if blessed($spec) && $spec->isa('Mouse::Meta::TypeConstraint');
+ return $spec if _is_a_type_constraint($spec);
$spec =~ s/\s+//g;
return $TYPE{$spec};
sub find_or_parse_type_constraint {
my($spec) = @_;
- return $spec if blessed($spec) && $spec->isa('Mouse::Meta::TypeConstraint');
+ return $spec if _is_a_type_constraint($spec);
$spec =~ s/\s+//g;
return $TYPE{$spec} || do{