my $meta = Mouse::Meta::Class->initialize("$class_or_role"); # "" for stringify
return map { $_ => $_ }
grep { $_ ne 'meta' && !Mouse::Object->can($_) && $_ =~ $handles }
- Mouse::Util::TypeConstraints::_is_a_metarole($meta)
+ Mouse::Util::is_a_metarole($meta)
? $meta->get_method_list
: $meta->get_all_method_names;
}
foreach my $super(@_){
Mouse::Util::load_class($super);
my $meta = Mouse::Util::get_metaclass_by_name($super);
- if(Mouse::Util::TypeConstraints::_is_a_metarole($meta)){
+ if(Mouse::Util::is_a_metarole($meta)){
$self->throw_error("You cannot inherit from a Mouse Role ($super)");
}
}
my $superclasses;
if(exists $options{superclasses}){
- if(Mouse::Util::TypeConstraints::_is_a_metarole($self)){
+ if(Mouse::Util::is_a_metarole($self)){
delete $options{superclasses};
}
else{
my $instance;
- if(Mouse::Util::TypeConstraints::_is_a_metaclass($applicant)){ # Application::ToClass
+ if(Mouse::Util::is_a_metaclass($applicant)){ # Application::ToClass
$args{_to} = 'class';
}
- elsif(Mouse::Util::TypeConstraints::_is_a_metarole($applicant)){ # Application::ToRole
+ elsif(Mouse::Util::is_a_metarole($applicant)){ # Application::ToRole
$args{_to} = 'role';
}
else{ # Appplication::ToInstance
return *{$package . '::' . $name}{CODE};
}
-package
- Mouse::Util::TypeConstraints;
-
-use Scalar::Util qw(blessed looks_like_number openhandle);
-
-sub _generate_class_type_for{
+sub _generate_isa_predicate_for {
my($for_class, $name) = @_;
- my $predicate = sub{ blessed($_[0]) && $_[0]->isa($for_class) };
+ my $predicate = sub{ Scalar::Util::blessed($_[0]) && $_[0]->isa($for_class) };
if(defined $name){
no strict 'refs';
}
+package
+ Mouse::Util::TypeConstraints;
+
+use Scalar::Util qw(blessed looks_like_number openhandle);
+
sub Any { 1 }
sub Item { 1 }
*get_metaclass_by_name = \&Mouse::Meta::Module::get_metaclass_by_name;
*get_all_metaclass_instances = \&Mouse::Meta::Module::get_all_metaclass_instances;
*get_all_metaclass_names = \&Mouse::Meta::Module::get_all_metaclass_names;
+
+ # is-a predicates
+ _generate_isa_predicate_for('Mouse::Meta::TypeConstraint' => 'is_a_type_constraint');
+ _generate_isa_predicate_for('Mouse::Meta::Class' => 'is_a_metaclass');
+ _generate_isa_predicate_for('Mouse::Meta::Role' => 'is_a_metarole');
}
+
# Moose::Util compatible utilities
sub find_meta{
my $role_name = $roles[-1][0];
load_class($role_name);
- Mouse::Util::TypeConstraints::_is_a_metarole( get_metaclass_by_name($role_name) )
+ 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;
my $class = $options->{class} || $name;
return _create_type 'subtype', $name => (
as => 'Object',
- optimized_as => _generate_class_type_for($class),
+ optimized_as => Mouse::Util::_generate_isa_predicate_for($class),
type => 'Class',
);
my $meta = Mouse::Util::get_metaclass_by_name($spec)
or return undef;
- if(_is_a_metarole($meta)){
+ if(Mouse::Util::is_a_metarole($meta)){
return role_type($spec);
}
else{
sub find_type_constraint {
my($spec) = @_;
- return $spec if _is_a_type_constraint($spec);
+ return $spec if Mouse::Util::is_a_type_constraint($spec);
$spec =~ s/\s+//g;
return $TYPE{$spec};
sub find_or_parse_type_constraint {
my($spec) = @_;
- return $spec if _is_a_type_constraint($spec);
+ return $spec if Mouse::Util::is_a_type_constraint($spec);
$spec =~ s/\s+//g;
return $TYPE{$spec} || do{
int mouse_tc_FileHandle(pTHX_ SV* const sv);
int mouse_tc_Object (pTHX_ SV* const sv);
+const char* mouse_canonicalize_package_name(const char* name);
+
+XS(XS_isa_check);
+XS(XS_isa_check_for_universal);
#endif /* !MOUSE_H */
OUTPUT:
RETVAL
+void
+_generate_isa_predicate_for(SV* klass, const char* predicate_name = NULL)
+PPCODE:
+{
+ STRLEN klass_len;
+ const char* klass_pv;
+ HV* stash;
+ CV* xsub;
+
+ if(!SvOK(klass)){
+ croak("You must define a class name for generate_for");
+ }
+ klass_pv = SvPV_const(klass, klass_len);
+ klass_pv = mouse_canonicalize_package_name(klass_pv);
+
+ if(strNE(klass_pv, "UNIVERSAL")){
+ static MGVTBL mouse_util_type_constraints_vtbl; /* not used, only for identity */
+
+ xsub = newXS(predicate_name, XS_isa_check, __FILE__);
+
+ stash = gv_stashpvn(klass_pv, klass_len, GV_ADD);
+
+ CvXSUBANY(xsub).any_ptr = sv_magicext(
+ (SV*)xsub,
+ (SV*)stash, /* mg_obj */
+ PERL_MAGIC_ext,
+ &mouse_util_type_constraints_vtbl,
+ klass_pv, /* mg_ptr */
+ klass_len /* mg_len */
+ );
+ }
+ else{
+ xsub = newXS(predicate_name, XS_isa_check_for_universal, __FILE__);
+ }
+
+ if(predicate_name == NULL){ /* anonymous predicate */
+ XPUSHs( newRV_noinc((SV*)xsub) );
+ }
+}
+
MODULE = Mouse PACKAGE = Mouse::Meta::Module
static MGVTBL mouse_util_type_constraints_vtbl;
-static const char*
-canonicalize_package_name(const char* name){
+const char*
+mouse_canonicalize_package_name(const char* name){
/* "::Foo" -> "Foo" */
if(name[0] == ':' && name[1] == ':'){
while(svp != end){
assert(SvPVX(*svp));
- if(strEQ(klass_pv, canonicalize_package_name(SvPVX(*svp)))){
+ if(strEQ(klass_pv, mouse_canonicalize_package_name(SvPVX(*svp)))){
return TRUE;
}
svp++;
}
}
-XS(XS_isa_check); /* -W */
+
XS(XS_isa_check){
dVAR;
dXSARGS;
XSRETURN(1);
}
-XS(XS_isa_check_for_universal); /* -W */
+
XS(XS_isa_check_for_universal){
dVAR;
dXSARGS;
#endif /* !USE_ITHREADS */
void
-_generate_class_type_for(SV* klass, const char* predicate_name = NULL)
-PPCODE:
-{
- STRLEN klass_len;
- const char* klass_pv;
- HV* stash;
- CV* xsub;
-
- if(!SvOK(klass)){
- croak("You must define a class name for generate_for");
- }
- klass_pv = SvPV_const(klass, klass_len);
- klass_pv = canonicalize_package_name(klass_pv);
-
- if(strNE(klass_pv, "UNIVERSAL")){
- xsub = newXS(predicate_name, XS_isa_check, __FILE__);
-
- stash = gv_stashpvn(klass_pv, klass_len, GV_ADD);
-
- CvXSUBANY(xsub).any_ptr = sv_magicext(
- (SV*)xsub,
- (SV*)stash, /* mg_obj */
- PERL_MAGIC_ext,
- &mouse_util_type_constraints_vtbl,
- klass_pv, /* mg_ptr */
- klass_len /* mg_len */
- );
- }
- else{
- xsub = newXS(predicate_name, XS_isa_check_for_universal, __FILE__);
- }
-
- if(predicate_name == NULL){ /* anonymous predicate */
- XPUSHs( newRV_noinc((SV*)xsub) );
- }
-}
-
-void
Item(SV* sv = &PL_sv_undef)
ALIAS:
Any = MOUSE_TC_ANY