On Sat, Jul 04, 2009 at 12:31:35AM +0100, Mark Morgan wrote: > In my case, I'm attempting to ensure that only a single attribute is > marked as 'asdf' for a given class. The specified attribute would be > treated specially during constuction
package My::Meta::Attribute::Trait::Highlander; use Moose::Role; before attach_to_class => sub { my ($self, $metaclass) = @_; my ($existing) = grep { $_->does(__PACKAGE__) } $metaclass->get_all_attributes; die "Can't add another highlander to " . $metaclass->name . " (found " . $existing->name . ")" if $existing; }; Untested, but you should be able to tweak this if it doesn't work right away. hdp.