From: Shawn M Moore Date: Tue, 25 Nov 2008 08:20:09 +0000 (+0000) Subject: Begin writing excludes.. seeing some weird errors, but.. heading to bed X-Git-Tag: 0.05~69 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=fa62759642ad1cae5121dcb3a7c781171909d793;p=gitmo%2FMooseX-Role-Parameterized.git Begin writing excludes.. seeing some weird errors, but.. heading to bed --- diff --git a/lib/MooseX/Role/Parameterized.pm b/lib/MooseX/Role/Parameterized.pm index f145ca3..2db4d16 100644 --- a/lib/MooseX/Role/Parameterized.pm +++ b/lib/MooseX/Role/Parameterized.pm @@ -15,7 +15,7 @@ our $CURRENT_METACLASS; __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 { @@ -97,6 +97,13 @@ sub requires { $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'" } diff --git a/t/007-excludes.t b/t/007-excludes.t new file mode 100644 index 0000000..8762907 --- /dev/null +++ b/t/007-excludes.t @@ -0,0 +1,73 @@ +#!/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') ], +# ); +#}; +#