__PACKAGE__->setup_import_methods(
with_caller => ['parameter', 'role', 'method'],
- as_is => ['has', 'with', 'extends', 'requires', 'augment', 'inner'],
+ as_is => ['has', 'with', 'extends', 'requires', 'excludes', 'augment', 'inner'],
);
sub parameter {
$CURRENT_METACLASS->add_required_methods(@_);
}
+sub excludes {
+ confess "excludes must be called within the role { ... } block."
+ unless $CURRENT_METACLASS;
+ croak "Must specify at least one role" unless @_;
+ $CURRENT_METACLASS->add_excluded_roles(@_);
+}
+
sub extends { croak "Roles do not currently support 'extends'" }
sub inner { croak "Roles cannot support 'inner'" }
--- /dev/null
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Test::More tests => 1;
+use Test::Exception;
+
+do {
+ package MyRole::Excluder;
+ use MooseX::Role::Parameterized;
+
+ parameter exclude => (
+ is => 'rw',
+ isa => 'Str',
+ );
+
+ role {
+ my $p = shift;
+ excludes $p->exclude;
+ };
+};
+
+Moose::Meta::Role->create("Role::A");
+Moose::Meta::Role->create("Role::B");
+
+sub excludes_roles {
+ map {
+ MyRole::Excluder->meta->generate_role(exclude => $_)->name
+ } @_
+}
+
+throws_ok {
+ Moose::Meta::Class->create_anon_class(
+ roles => [ 'Role::A', excludes_roles('Role::A') ],
+ );
+} qr/^Conflict detected: Role::A excludes role 'Role::A'/;
+
+#lives_ok {
+# Moose::Meta::Class->create_anon_class(
+# methods => {
+# alpha => sub {},
+# },
+# roles => [ requires_names('alpha') ],
+# );
+#};
+#
+#throws_ok {
+# Moose::Meta::Class->create_anon_class(
+# methods => {
+# alpha => sub {},
+# },
+# roles => [ requires_names('alpha', 'beta') ],
+# );
+#} qr/'Moose::Meta::Role::__ANON__::SERIAL::\d+\|Moose::Meta::Role::__ANON__::SERIAL::\d+' requires the method 'beta' to be implemented by 'Class::MOP::Class::__ANON__::SERIAL::\d+'/;
+#
+#throws_ok {
+# Moose::Meta::Class->create_anon_class(
+# methods => {
+# beta => sub {},
+# },
+# roles => [ requires_names('alpha', 'beta') ],
+# );
+#} qr/'Moose::Meta::Role::__ANON__::SERIAL::\d+\|Moose::Meta::Role::__ANON__::SERIAL::\d+' requires the method 'alpha' to be implemented by 'Class::MOP::Class::__ANON__::SERIAL::\d+'/;
+#
+#lives_ok {
+# Moose::Meta::Class->create_anon_class(
+# methods => {
+# alpha => sub {},
+# beta => sub {},
+# },
+# roles => [ requires_names('alpha', 'beta') ],
+# );
+#};
+#