1 package Moose::Meta::Attribute::Trait::InRole;
6 use Scalar::Util 'blessed', 'weaken';
9 our $AUTHORITY = 'cpan:STEVAN';
11 around attach_to_class => sub {
13 my ( $self, $class ) = @_;
15 ( blessed($class) && $class->isa('Moose::Meta::Role') )
17 "You must pass a Moose::Meta::Role instance (or a subclass)";
19 weaken( $self->{'associated_class'} = $class );
22 # XXX - This is a no-op, since trying to add accessors to a role just blows
23 # up. Ideally, we _would_ add accessors, or somehow make the role aware that
24 # they exist for the purposes of method conflict checking, etc.
25 around install_accessors => sub { };
27 around _check_associated_methods => sub { };
33 my $meta = $self->meta;
35 my @supers = $meta->superclasses();
36 my @traits_to_keep = grep { $_ ne __PACKAGE__ }
38 grep { !$_->isa('Moose::Meta::Role::Composite') }
39 $meta->calculate_all_roles;
43 if ( @traits_to_keep || @supers > 1 ) {
44 my $anon_class = Moose::Meta::Class->create_anon_class(
45 superclasses => \@supers,
46 roles => \@traits_to_keep,
50 $new_class = $anon_class->name;
53 $new_class = $supers[0];
56 return $self->$orig( @_, metaclass => $new_class );