Skip to content

Instantly share code, notes, and snippets.

@masaki
Created Mar 6, 2009
Embed
What would you like to do?
diff --git a/lib/Mouse/Meta/Role.pm b/lib/Mouse/Meta/Role.pm
index 95bdca8..fd2fc11 100644
--- a/lib/Mouse/Meta/Role.pm
+++ b/lib/Mouse/Meta/Role.pm
@@ -107,7 +107,20 @@ sub apply {
for my $name ($self->get_attribute_list) {
next if $class->has_attribute($name);
my $spec = $self->get_attribute($name);
- Mouse::Meta::Attribute->create($class, $name, %$spec);
+
+ my $metaclass = 'Mouse::Meta::Attribute';
+ if ( my $metaclass_name = delete $spec->{metaclass} ) {
+ require Mouse::Util;
+ my $new_class = Mouse::Util::resolve_metaclass_alias(
+ 'Attribute',
+ $metaclass_name
+ );
+ if ( $metaclass ne $new_class ) {
+ $metaclass = $new_class;
+ }
+ }
+
+ $metaclass->create($class, $name, %$spec);
}
} else {
# apply role to role
@@ -188,7 +201,20 @@ sub combine_apply {
for my $name ($self->get_attribute_list) {
next if $class->has_attribute($name);
my $spec = $self->get_attribute($name);
- Mouse::Meta::Attribute->create($class, $name, %$spec);
+
+ my $metaclass = 'Mouse::Meta::Attribute';
+ if ( my $metaclass_name = delete $spec->{metaclass} ) {
+ require Mouse::Util;
+ my $new_class = Mouse::Util::resolve_metaclass_alias(
+ 'Attribute',
+ $metaclass_name
+ );
+ if ( $metaclass ne $new_class ) {
+ $metaclass = $new_class;
+ }
+ }
+
+ $metaclass->create($class, $name, %$spec);
}
}
} else {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment