X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FReaction%2FRole%2FMeta%2FClass.pm;fp=lib%2FReaction%2FRole%2FMeta%2FClass.pm;h=3e3841c5a288ae287a71b7cd78cd85fd1a264c83;hb=065f3d3d9498c82e25bc2e4c4d175d1ef1a9233f;hp=6d91e3f42b88d11b99bba521a79e6a684411c248;hpb=b906915263f2a47af1a711575718aea0133564b2;p=catagits%2FReaction.git diff --git a/lib/Reaction/Role/Meta/Class.pm b/lib/Reaction/Role/Meta/Class.pm index 6d91e3f..3e3841c 100644 --- a/lib/Reaction/Role/Meta/Class.pm +++ b/lib/Reaction/Role/Meta/Class.pm @@ -9,4 +9,35 @@ around initialize => sub { $super->($class, $pkg, 'attribute_metaclass' => 'Reaction::Meta::Attribute', @_ ); }; +around add_role => sub { + my $orig = shift; + my $self = shift; + my ($role) = @_; + + my @roles = grep { !$_->isa('Moose::Meta::Role::Composite') } + $role->calculate_all_roles; + my @bad_roles = map { Moose::Util::does_role($_, 'MooseX::Role::Parameterized::Meta::Trait::Parameterized') ? $_->genitor->name : $_->name } + grep { $_->get_attribute_list > 0 } + grep { !Moose::Util::does_role($_->applied_attribute_metaclass, 'Reaction::Role::Meta::Attribute') } + @roles; + + if (@bad_roles) { + my $plural = @bad_roles > 1; + warn "You are applying the role" . ($plural ? "s " : " ") + . join(", ", @bad_roles) + . " to the Reaction::Class " . $self->name + . ", but " . ($plural ? "these roles do" : "that role does") + . " not use Reaction::Role or" + . " Reaction::Role::Parameterized. In Moose versions greater than" + . " 2.0, this will cause the special behavior of Reaction" + . " attributes to no longer be applied to attributes defined" + . " in " . ($plural ? "these roles" : "this role") + . ". You should replace 'use Moose::Role' with" + . " 'use Reaction::Role' or 'use MooseX::Role::Parameterized' with" + . " 'use Reaction::Role::Parameterized'."; + } + + $self->$orig(@_); +} if Moose->VERSION >= 1.9900; + 1;