use List::MoreUtils 'all';
use Scalar::Util 'blessed', 'weaken';
-our $VERSION = '0.93_01';
-our $AUTHORITY = 'cpan:STEVAN';
-
-use base 'Moose::Meta::Mixin::AttributeCore';
+use base 'Moose::Meta::Mixin::AttributeCore', 'Class::MOP::Object';
__PACKAGE__->meta->add_attribute(
'metaclass' => (
reader => 'metaclass',
+ Class::MOP::_definition_context(),
)
);
__PACKAGE__->meta->add_attribute(
'associated_role' => (
reader => 'associated_role',
+ Class::MOP::_definition_context(),
+ )
+);
+
+__PACKAGE__->meta->add_attribute(
+ '_original_role' => (
+ reader => '_original_role',
+ Class::MOP::_definition_context(),
)
);
__PACKAGE__->meta->add_attribute(
'is' => (
reader => 'is',
+ Class::MOP::_definition_context(),
)
);
__PACKAGE__->meta->add_attribute(
'original_options' => (
reader => 'original_options',
+ Class::MOP::_definition_context(),
)
);
(defined $name)
|| confess "You must provide a name for the attribute";
+ my $role = delete $options{_original_role};
+
return bless {
name => $name,
original_options => \%options,
+ _original_role => $role,
%options,
}, $class;
}
weaken( $self->{'associated_role'} = $role );
}
+sub original_role {
+ my $self = shift;
+
+ return $self->_original_role || $self->associated_role;
+}
+
sub attribute_for_class {
- my $self = shift;
- my $metaclass = shift;
+ my $self = shift;
+
+ my $metaclass = $self->original_role->applied_attribute_metaclass;
return $metaclass->interpolate_class_and_new(
$self->name => %{ $self->original_options } );
sub clone {
my $self = shift;
- return ( ref $self )->new( $self->name, %{ $self->original_options } );
+ my $role = $self->original_role;
+
+ return ( ref $self )->new(
+ $self->name,
+ %{ $self->original_options },
+ _original_role => $role,
+ );
}
sub is_same_as {
1;
-=pod
+# ABSTRACT: The Moose attribute metaclass for Roles
-=head1 NAME
+__END__
-Moose::Meta::Role::Attribute - A Moose Attribute metaclass for Roles
+=pod
=head1 DESCRIPTION
Returns the L<Moose::Meta::Role> to which this attribute belongs, if any.
+=item B<< $attr->original_role >>
+
+Returns the L<Moose::Meta::Role> in which this attribute was first
+defined. This may not be the same as the value C<associated_role()> in the
+case of composite role, or the case where one role consumes other roles.
+
=item B<< $attr->original_options >>
Returns a hash reference of options passed to the constructor. This is used
See L<Moose/BUGS> for details on reporting bugs.
-=head1 AUTHOR
-
-Dave Rolsky E<lt>autarch@urth.orgE<gt>
-
-=head1 COPYRIGHT AND LICENSE
-
-Copyright 2006-2010 by Infinity Interactive, Inc.
-
-L<http://www.iinteractive.com>
-
-This library is free software; you can redistribute it and/or modify
-it under the same terms as Perl itself.
-
=cut