From: Stevan Little Date: Mon, 14 Jan 2008 22:59:15 +0000 (+0000) Subject: * role exclusion and aliasiing now works in composite roles too X-Git-Tag: 0_35~17 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=28412c0b280c30cfd1eac1579b9f5953b5e1850e;p=gitmo%2FMoose.git * role exclusion and aliasiing now works in composite roles too * added plans to all the composite role tests now * cleaned up some of nothingmuch's stuff --- diff --git a/Changes b/Changes index 6c07474..b91c65a 100644 --- a/Changes +++ b/Changes @@ -15,9 +15,14 @@ Revision history for Perl extension Moose * Moose::Meta::Method::Accessor Moose::Meta::Method::Constructor - Moose::Meta::Method::Attribute - - cleanup of some of the generated methods - (thanks to nothingmuch) + Moose::Meta::Attribute + Moose::Meta::TypeConstraint + Moose::Meta::TypeCoercion + - lots of cleanup of such things as: + - generated methods + - type constraint handling + - error handling/messages + (thanks to nothingmuch) * Moose::Util::TypeConstraints - all optimized type constraint subs are now diff --git a/Makefile.PL b/Makefile.PL index aaf852f..2569da9 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -12,7 +12,7 @@ my $win32 = !! ( $^O eq 'Win32' or $^O eq 'cygwin' ); # prereqs requires 'Scalar::Util' => $win32 ? '1.17' : '1.18'; requires 'Carp'; -requires 'Class::MOP' => '0.49'; +requires 'Class::MOP' => '0.51'; requires 'Sub::Name' => '0.02'; requires 'Sub::Exporter' => '0.972'; diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 9a7545e..72e6bd7 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -9,7 +9,7 @@ use Carp 'confess'; use Sub::Name 'subname'; use overload (); -our $VERSION = '0.17'; +our $VERSION = '0.18'; our $AUTHORITY = 'cpan:STEVAN'; use Moose::Meta::Method::Accessor; @@ -403,6 +403,9 @@ sub install_accessors { $associated_class->add_method($handle => subname $name, sub { my $proxy = (shift)->$accessor(); @_ = ($proxy, @_); + (defined $proxy) + || confess "Cannot delegate $handle to $method_to_call because " . + "the value of " . $self->name . " is not defined"; goto &{ $proxy->can($method_to_call) || return }; }); } diff --git a/lib/Moose/Meta/Method/Accessor.pm b/lib/Moose/Meta/Method/Accessor.pm index 55ad087..d878ed5 100644 --- a/lib/Moose/Meta/Method/Accessor.pm +++ b/lib/Moose/Meta/Method/Accessor.pm @@ -6,7 +6,7 @@ use warnings; use Carp 'confess'; -our $VERSION = '0.10'; +our $VERSION = '0.11'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Method', diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 97f51ca..55bd4fe 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -7,7 +7,7 @@ use warnings; use Carp 'confess'; use Scalar::Util 'blessed', 'weaken', 'looks_like_number'; -our $VERSION = '0.04'; +our $VERSION = '0.05'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Method', diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 2039b12..d7270ca 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -380,15 +380,19 @@ sub combine { require Moose::Meta::Role::Application::RoleSummation; require Moose::Meta::Role::Composite; - my @roles = map { $_->[0]->meta } @role_specs; - - my %params; - # how do I do this ... + my (@roles, %role_params); + while (@role_specs) { + my ($role, $params) = @{ splice @role_specs, 0, 1 }; + push @roles => $role->meta; + next unless defined $params; + $role_params{$role} = $params; + } my $c = Moose::Meta::Role::Composite->new(roles => \@roles); Moose::Meta::Role::Application::RoleSummation->new( - %params + role_params => \%role_params )->apply($c); + return $c; } diff --git a/lib/Moose/Meta/Role/Application/RoleSummation.pm b/lib/Moose/Meta/Role/Application/RoleSummation.pm index 0c1bb79..99f4771 100644 --- a/lib/Moose/Meta/Role/Application/RoleSummation.pm +++ b/lib/Moose/Meta/Role/Application/RoleSummation.pm @@ -15,6 +15,51 @@ our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Role::Application'; +__PACKAGE__->meta->add_attribute('role_params' => ( + reader => 'role_params', + default => sub { {} } +)); + +sub get_exclusions_for_role { + my ($self, $role) = @_; + $role = $role->name if blessed $role; + if ($self->role_params->{$role} && defined $self->role_params->{$role}->{excludes}) { + if (ref $self->role_params->{$role}->{excludes} eq 'ARRAY') { + return $self->role_params->{$role}->{excludes}; + } + return [ $self->role_params->{$role}->{excludes} ]; + } + return []; +} + +sub get_method_aliases_for_role { + my ($self, $role) = @_; + $role = $role->name if blessed $role; + if ($self->role_params->{$role} && defined $self->role_params->{$role}->{alias}) { + return $self->role_params->{$role}->{alias}; + } + return {}; +} + +sub is_method_excluded { + my ($self, $role, $method_name) = @_; + foreach ($self->get_exclusions_for_role($role->name)) { + return 1 if $_ eq $method_name; + } + return 0; +} + +sub is_method_aliased { + my ($self, $role, $method_name) = @_; + exists $self->get_method_aliases_for_role($role->name)->{$method_name} ? 1 : 0 +} + +sub is_aliased_method { + my ($self, $role, $method_name) = @_; + my %aliased_names = reverse %{$self->get_method_aliases_for_role($role->name)}; + exists $aliased_names{$method_name} ? 1 : 0; +} + # stolen from List::MoreUtils ... my $uniq = sub { my %h; map { $h{$_}++ == 0 ? $_ : () } @_ }; @@ -44,8 +89,10 @@ sub check_required_methods { foreach my $role (@{$c->get_roles}) { foreach my $required (keys %all_required_methods) { + delete $all_required_methods{$required} - if $role->has_method($required); + if $role->has_method($required) + || $self->is_aliased_method($role, $required); } } @@ -88,13 +135,26 @@ sub apply_methods { my ($self, $c) = @_; my @all_methods = map { - my $role = $_; - map { - +{ - name => $_, - method => $role->get_method($_), - } - } $role->get_method_list; + my $role = $_; + my $aliases = $self->get_method_aliases_for_role($role); + my %excludes = map { $_ => undef } @{ $self->get_exclusions_for_role($role) }; + ( + (map { + exists $excludes{$_} ? () : + +{ + role => $role, + name => $_, + method => $role->get_method($_), + } + } $role->get_method_list), + (map { + +{ + role => $role, + name => $aliases->{$_}, + method => $role->get_method($_), + } + } keys %$aliases) + ); } @{$c->get_roles}; my (%seen, %method_map); @@ -105,7 +165,8 @@ sub apply_methods { delete $method_map{$method->{name}}; next; } - } + } + $seen{$method->{name}} = $method->{method}; $method_map{$method->{name}} = $method->{method}; } @@ -184,6 +245,18 @@ bindings and 'disabling' the conflicting bindings =item B +=item B + +=item B + +=item B + +=item B + +=item B + +=item B + =item B =item B diff --git a/lib/Moose/Meta/Role/Composite.pm b/lib/Moose/Meta/Role/Composite.pm index 3461e84..281e9dc 100644 --- a/lib/Moose/Meta/Role/Composite.pm +++ b/lib/Moose/Meta/Role/Composite.pm @@ -4,10 +4,8 @@ use strict; use warnings; use metaclass; -use Carp 'confess'; -use Scalar::Util 'blessed', 'reftype'; - -use Data::Dumper; +use Carp 'confess'; +use Scalar::Util 'blessed', 'reftype'; our $VERSION = '0.01'; our $AUTHORITY = 'cpan:STEVAN'; diff --git a/lib/Moose/Meta/TypeCoercion.pm b/lib/Moose/Meta/TypeCoercion.pm index 7ace8e7..aaae013 100644 --- a/lib/Moose/Meta/TypeCoercion.pm +++ b/lib/Moose/Meta/TypeCoercion.pm @@ -10,7 +10,7 @@ use Carp 'confess'; use Moose::Meta::Attribute; use Moose::Util::TypeConstraints (); -our $VERSION = '0.05'; +our $VERSION = '0.06'; our $AUTHORITY = 'cpan:STEVAN'; __PACKAGE__->meta->add_attribute('type_coercion_map' => ( diff --git a/lib/Moose/Meta/TypeConstraint.pm b/lib/Moose/Meta/TypeConstraint.pm index b37ee8a..ad5094b 100644 --- a/lib/Moose/Meta/TypeConstraint.pm +++ b/lib/Moose/Meta/TypeConstraint.pm @@ -12,7 +12,7 @@ use Sub::Name 'subname'; use Carp 'confess'; use Scalar::Util 'blessed'; -our $VERSION = '0.10'; +our $VERSION = '0.11'; our $AUTHORITY = 'cpan:STEVAN'; __PACKAGE__->meta->add_attribute('name' => (reader => 'name')); diff --git a/lib/Moose/Meta/TypeConstraint/Class.pm b/lib/Moose/Meta/TypeConstraint/Class.pm index 5569cc5..a14ace5 100644 --- a/lib/Moose/Meta/TypeConstraint/Class.pm +++ b/lib/Moose/Meta/TypeConstraint/Class.pm @@ -4,15 +4,19 @@ use strict; use warnings; use metaclass; -use Scalar::Util qw(blessed); +use Scalar::Util 'blessed'; +use Moose::Util::TypeConstraints (); -use base 'Moose::Meta::TypeConstraint'; +our $VERSION = '0.01'; +our $AUTHORITY = 'cpan:STEVAN'; -use Moose::Util::TypeConstraints (); +use base 'Moose::Meta::TypeConstraint'; sub new { my $class = shift; - my $self = $class->meta->new_object(@_, parent => Moose::Util::TypeConstraints::find_type_constraint('Object') ); + my $self = $class->meta->new_object(@_, + parent => Moose::Util::TypeConstraints::find_type_constraint('Object') + ); $self->compile_type_constraint() unless $self->_has_compiled_type_constraint; return $self; @@ -22,12 +26,18 @@ sub parents { my $self = shift; return ( $self->parent, - map { Moose::Util::TypeConstraints::find_type_constraint($_) } $self->name->meta->superclasses, + map { + # NOTE: + # Hmm, should this be find_or_create_type_constraint? + # What do you think nothingmuch?? + # - SL + Moose::Util::TypeConstraints::find_type_constraint($_) + } $self->name->meta->superclasses, ); } sub hand_optimized_type_constraint { - my $self = shift; + my $self = shift; my $class = $self->name; sub { blessed( $_[0] ) && $_[0]->isa($class) } } @@ -50,6 +60,7 @@ sub is_subtype_of { 1; __END__ + =pod =head1 NAME @@ -60,20 +71,41 @@ Moose::Meta::TypeConstraint::Class - Class/TypeConstraint parallel hierarchy =over 4 -=item new +=item B -=item hand_optimized_type_constraint +=item B -=item has_hand_optimized_type_constraint +=item B -=item is_a_type_of +=item B -=item is_subtype_of +=item B -=item parents +=item B Return all the parent types, corresponding to the parent classes. +=item B + =back +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Yuval Kogman Enothingmuch@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + =cut diff --git a/lib/Moose/Meta/TypeConstraint/Parameterized.pm b/lib/Moose/Meta/TypeConstraint/Parameterized.pm index cb2c580..7020507 100644 --- a/lib/Moose/Meta/TypeConstraint/Parameterized.pm +++ b/lib/Moose/Meta/TypeConstraint/Parameterized.pm @@ -100,8 +100,6 @@ __END__ Moose::Meta::TypeConstraint::Parameterized - Higher Order type constraints for Moose -=head1 DESCRIPTION - =head1 METHODS =over 4 diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 409db5d..58af227 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -9,7 +9,7 @@ use if ( not our $__mx_is_compiled ), metaclass => 'Moose::Meta::Class'; use Carp 'confess'; -our $VERSION = '0.09'; +our $VERSION = '0.10'; our $AUTHORITY = 'cpan:STEVAN'; sub new { diff --git a/lib/Moose/Util/TypeConstraints.pm b/lib/Moose/Util/TypeConstraints.pm index 2d6a438..9ebc42f 100644 --- a/lib/Moose/Util/TypeConstraints.pm +++ b/lib/Moose/Util/TypeConstraints.pm @@ -8,7 +8,7 @@ use Carp 'confess'; use Scalar::Util 'blessed', 'reftype'; use Sub::Exporter; -our $VERSION = '0.19'; +our $VERSION = '0.20'; our $AUTHORITY = 'cpan:STEVAN'; ## -------------------------------------------------------- diff --git a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm index 0576a14..d45d30b 100644 --- a/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm +++ b/lib/Moose/Util/TypeConstraints/OptimizedConstraints.pm @@ -1,18 +1,12 @@ -#!/usr/bin/perl - -=begin comment - -04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz -04:09 <@konobi> or utilxs.tar.gz iirc - -=cut - package Moose::Util::TypeConstraints::OptimizedConstraints; use strict; use warnings; -use Scalar::Util qw(blessed looks_like_number); +use Scalar::Util 'blessed', 'looks_like_number'; + +our $VERSION = '0.01'; +our $AUTHORITY = 'cpan:STEVAN'; sub Value { defined($_[0]) && !ref($_[0]) } @@ -27,11 +21,11 @@ sub Int { defined($_[0]) && !ref($_[0]) && $_[0] =~ /^-?[0-9]+$/ } { no warnings 'uninitialized'; sub ScalarRef { ref($_[0]) eq 'SCALAR' } - sub ArrayRef { ref($_[0]) eq 'ARRAY' } - sub HashRef { ref($_[0]) eq 'HASH' } - sub CodeRef { ref($_[0]) eq 'CODE' } + sub ArrayRef { ref($_[0]) eq 'ARRAY' } + sub HashRef { ref($_[0]) eq 'HASH' } + sub CodeRef { ref($_[0]) eq 'CODE' } sub RegexpRef { ref($_[0]) eq 'Regexp' } - sub GlobRef { ref($_[0]) eq 'GLOB' } + sub GlobRef { ref($_[0]) eq 'GLOB' } } sub FileHandle { ref($_[0]) eq 'GLOB' && Scalar::Util::openhandle($_[0]) } @@ -40,8 +34,12 @@ sub Object { blessed($_[0]) && blessed($_[0]) ne 'Regexp' } sub Role { blessed($_[0]) && $_[0]->can('does') } +# NOTE: +# we have XS versions too, ... +# 04:09 <@konobi> nothingmuch: konobi.co.uk/code/utilsxs.tar.gz +# 04:09 <@konobi> or utilxs.tar.gz iirc -__PACKAGE__ +1; __END__ @@ -52,11 +50,9 @@ __END__ Moose::Util::TypeConstraints::OptimizedConstraints - Optimized constraint bodies for various moose types -=head1 SYNOPSIS - =head1 DESCRIPTION -This file contains optimized versions of Moose type constraints. +This file contains the hand optimized versions of Moose type constraints. =head1 FUNCTIONS @@ -91,3 +87,24 @@ This file contains optimized versions of Moose type constraints. =item Role =back + +=head1 BUGS + +All complex software has bugs lurking in it, and this module is no +exception. If you find a bug please either email me, or add the bug +to cpan-RT. + +=head1 AUTHOR + +Yuval Kogman Enothingmuch@cpan.orgE + +=head1 COPYRIGHT AND LICENSE + +Copyright 2006-2008 by Infinity Interactive, Inc. + +L + +This library is free software; you can redistribute it and/or modify +it under the same terms as Perl itself. + +=cut diff --git a/t/000_recipes/011_recipe.t b/t/000_recipes/011_recipe.t index b71ac11..5e30e36 100644 --- a/t/000_recipes/011_recipe.t +++ b/t/000_recipes/011_recipe.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 2; use Test::Exception; BEGIN { diff --git a/t/030_roles/011_overriding.t b/t/030_roles/011_overriding.t index 10c149f..1ebc3eb 100644 --- a/t/030_roles/011_overriding.t +++ b/t/030_roles/011_overriding.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 40; use Test::Exception; BEGIN { diff --git a/t/030_roles/012_method_exclusion_during_composition.t b/t/030_roles/012_method_exclusion_during_composition.t index 7275d37..30f77f4 100644 --- a/t/030_roles/012_method_exclusion_during_composition.t +++ b/t/030_roles/012_method_exclusion_during_composition.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 20; use Test::Exception; BEGIN { @@ -42,7 +42,76 @@ ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo bar ba ok(!My::OtherRole->meta->requires_method('foo'), '... and the &foo method is not required'); ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required'); +{ + package Foo::Role; + use Moose::Role; + + sub foo { 'Foo::Role::foo' } + + package Bar::Role; + use Moose::Role; + + sub foo { 'Bar::Role::foo' } + + package Baz::Role; + use Moose::Role; + + sub foo { 'Baz::Role::foo' } + + package My::Foo::Class; + use Moose; + + ::lives_ok { + with 'Foo::Role' => { excludes => 'foo' }, + 'Bar::Role' => { excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; + + package My::Foo::Class::Broken; + use Moose; + + ::throws_ok { + with 'Foo::Role', + 'Bar::Role' => { excludes => 'foo' }, + 'Baz::Role'; + } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo\' to be implemented by \'My::Foo::Class::Broken\'/, + '... composed our roles correctly'; +} + +{ + my $foo = My::Foo::Class->new; + isa_ok($foo, 'My::Foo::Class'); + can_ok($foo, 'foo'); + is($foo->foo, 'Baz::Role::foo', '... got the right method'); +} + +{ + package My::Foo::Role; + use Moose::Role; + + ::lives_ok { + with 'Foo::Role' => { excludes => 'foo' }, + 'Bar::Role' => { excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; +} + +ok(My::Foo::Role->meta->has_method('foo'), "we have a foo method"); +ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required'); + +{ + package My::Foo::Role::Other; + use Moose::Role; + + ::lives_ok { + with 'Foo::Role', + 'Bar::Role' => { excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; +} +ok(!My::Foo::Role::Other->meta->has_method('foo'), "we dont have a foo method"); +ok(My::Foo::Role::Other->meta->requires_method('foo'), '... and the &foo method is required'); diff --git a/t/030_roles/013_method_aliasing_during_composition.t b/t/030_roles/013_method_aliasing_during_composition.t index c0587fe..42d3400 100644 --- a/t/030_roles/013_method_aliasing_during_composition.t +++ b/t/030_roles/013_method_aliasing_during_composition.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 31; use Test::Exception; BEGIN { @@ -63,7 +63,77 @@ ok(My::OtherRole->meta->has_method($_), "we have a $_ method") for qw(foo baz ro ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is required'); ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar method is not required'); +{ + package Foo::Role; + use Moose::Role; + + sub foo { 'Foo::Role::foo' } + + package Bar::Role; + use Moose::Role; + + sub foo { 'Bar::Role::foo' } + package Baz::Role; + use Moose::Role; + + sub foo { 'Baz::Role::foo' } + + package My::Foo::Class; + use Moose; + + ::lives_ok { + with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; + + package My::Foo::Class::Broken; + use Moose; + + ::throws_ok { + with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + 'Baz::Role'; + } qr/\'Foo::Role\|Bar::Role\|Baz::Role\' requires the method \'foo_foo\' to be implemented by \'My::Foo::Class::Broken\'/, + '... composed our roles correctly'; +} +{ + my $foo = My::Foo::Class->new; + isa_ok($foo, 'My::Foo::Class'); + can_ok($foo, $_) for qw/foo foo_foo bar_foo/; + is($foo->foo, 'Baz::Role::foo', '... got the right method'); + is($foo->foo_foo, 'Foo::Role::foo', '... got the right method'); + is($foo->bar_foo, 'Bar::Role::foo', '... got the right method'); +} + +{ + package My::Foo::Role; + use Moose::Role; + + ::lives_ok { + with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; +} + +ok(My::Foo::Role->meta->has_method($_), "we have a $_ method") for qw/foo foo_foo bar_foo/;; +ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not required'); + + +{ + package My::Foo::Role::Other; + use Moose::Role; + + ::lives_ok { + with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + 'Baz::Role'; + } '... composed our roles correctly'; +} +ok(!My::Foo::Role::Other->meta->has_method('foo_foo'), "we dont have a foo_foo method"); +ok(My::Foo::Role::Other->meta->requires_method('foo_foo'), '... and the &foo method is required'); diff --git a/t/030_roles/014_more_alias_and_exclude.t b/t/030_roles/014_more_alias_and_exclude.t new file mode 100644 index 0000000..3fce48d --- /dev/null +++ b/t/030_roles/014_more_alias_and_exclude.t @@ -0,0 +1,74 @@ +#!/usr/bin/perl + +use strict; +use warnings; + +use Test::More tests => 10; +use Test::Exception; + +BEGIN { + use_ok('Moose'); +} + +{ + package Foo; + use Moose::Role; + + sub foo { 'Foo::foo' } + sub bar { 'Foo::bar' } + sub baz { 'Foo::baz' } + sub gorch { 'Foo::gorch' } + + package Bar; + use Moose::Role; + + sub foo { 'Bar::foo' } + sub bar { 'Bar::bar' } + sub baz { 'Bar::baz' } + sub gorch { 'Bar::gorch' } + + package Baz; + use Moose::Role; + + sub foo { 'Baz::foo' } + sub bar { 'Baz::bar' } + sub baz { 'Baz::baz' } + sub gorch { 'Baz::gorch' } + + package Gorch; + use Moose::Role; + + sub foo { 'Gorch::foo' } + sub bar { 'Gorch::bar' } + sub baz { 'Gorch::baz' } + sub gorch { 'Gorch::gorch' } +} + +{ + package My::Class; + use Moose; + + ::lives_ok { + with 'Foo' => { excludes => [qw/bar baz gorch/], alias => { gorch => 'foo_gorch' } }, + 'Bar' => { excludes => [qw/foo baz gorch/] }, + 'Baz' => { excludes => [qw/foo bar gorch/], alias => { foo => 'baz_foo', bar => 'baz_bar' } }, + 'Gorch' => { excludes => [qw/foo bar baz/] }; + } '... everything works out all right'; +} + +my $c = My::Class->new; +isa_ok($c, 'My::Class'); + +is($c->foo, 'Foo::foo', '... got the right method'); +is($c->bar, 'Bar::bar', '... got the right method'); +is($c->baz, 'Baz::baz', '... got the right method'); +is($c->gorch, 'Gorch::gorch', '... got the right method'); + +is($c->foo_gorch, 'Foo::gorch', '... got the right method'); +is($c->baz_foo, 'Baz::foo', '... got the right method'); +is($c->baz_bar, 'Baz::bar', '... got the right method'); + + + + + diff --git a/t/030_roles/020_role_composite.t b/t/030_roles/020_role_composite.t index 76db467..ff70579 100644 --- a/t/030_roles/020_role_composite.t +++ b/t/030_roles/020_role_composite.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 17; use Test::Exception; BEGIN { diff --git a/t/030_roles/021_role_composite_exclusion.t b/t/030_roles/021_role_composite_exclusion.t index 7866b5e..4a1cad6 100644 --- a/t/030_roles/021_role_composite_exclusion.t +++ b/t/030_roles/021_role_composite_exclusion.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 15; use Test::Exception; BEGIN { diff --git a/t/030_roles/022_role_composition_required_methods.t b/t/030_roles/022_role_composition_required_methods.t index f00f1e5..0d04cbc 100644 --- a/t/030_roles/022_role_composition_required_methods.t +++ b/t/030_roles/022_role_composition_required_methods.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 19; use Test::Exception; BEGIN { diff --git a/t/030_roles/023_role_composition_attributes.t b/t/030_roles/023_role_composition_attributes.t index abbae81..bc6da7e 100644 --- a/t/030_roles/023_role_composition_attributes.t +++ b/t/030_roles/023_role_composition_attributes.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 10; use Test::Exception; BEGIN { diff --git a/t/030_roles/024_role_composition_methods.t b/t/030_roles/024_role_composition_methods.t index 35b6a0d..a77a4dc 100644 --- a/t/030_roles/024_role_composition_methods.t +++ b/t/030_roles/024_role_composition_methods.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 22; use Test::Exception; BEGIN { diff --git a/t/030_roles/025_role_composition_override.t b/t/030_roles/025_role_composition_override.t index d0aaa47..9f38de3 100644 --- a/t/030_roles/025_role_composition_override.t +++ b/t/030_roles/025_role_composition_override.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 11; use Test::Exception; BEGIN { diff --git a/t/030_roles/026_role_composition_method_modifiers.t b/t/030_roles/026_role_composition_method_modifiers.t index ab5b240..365da92 100644 --- a/t/030_roles/026_role_composition_method_modifiers.t +++ b/t/030_roles/026_role_composition_method_modifiers.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 9; use Test::Exception; BEGIN { diff --git a/t/040_type_constraints/020_class_type_constraint.t b/t/040_type_constraints/020_class_type_constraint.t index f565e23..628dd19 100644 --- a/t/040_type_constraints/020_class_type_constraint.t +++ b/t/040_type_constraints/020_class_type_constraint.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More 'no_plan'; +use Test::More tests => 7; BEGIN { use_ok('Moose::Util::TypeConstraints'); diff --git a/t/200_examples/006_example_Protomoose.t b/t/200_examples/006_example_Protomoose.t index 7b7364a..b1e3f2a 100644 --- a/t/200_examples/006_example_Protomoose.t +++ b/t/200_examples/006_example_Protomoose.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More no_plan => 1; +use Test::More tests => 28; =pod