From: Jesse Luehrs Date: Wed, 12 Aug 2009 23:21:10 +0000 (-0500) Subject: rename alias and excludes to -alias and -excludes X-Git-Tag: 0.89_01~13 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c8b8d92f366e6d9c09c0bb2a54b4f1942fc665ef;p=gitmo%2FMoose.git rename alias and excludes to -alias and -excludes leave alias and excludes in for backcompat, but with the intention of deprecating and removing them in the future --- diff --git a/Changes b/Changes index 7412ed0..42391a7 100644 --- a/Changes +++ b/Changes @@ -35,6 +35,11 @@ for, noteworthy changes. - However, we will probably deprecate $obj->new, so please don't start using it for new code! + * Moose::Meta::Role::Application + * Moose::Meta::Role::Application::RoleSummation + - Rename alias and excludes to -alias and -excludes (but keep the old + names for now, for backcompat) (doy) + 0.88 Fri Jul 24, 2009 * Moose::Manual::Contributing - Re-write the Moose::Manual::Contributing document to reflect diff --git a/lib/Moose/Cookbook/Roles/Recipe2.pod b/lib/Moose/Cookbook/Roles/Recipe2.pod index 7a76c0f..7c77f68 100644 --- a/lib/Moose/Cookbook/Roles/Recipe2.pod +++ b/lib/Moose/Cookbook/Roles/Recipe2.pod @@ -26,7 +26,7 @@ Moose::Cookbook::Roles::Recipe2 - Advanced Role Composition - method exclusion a use Moose::Role; with 'Restartable' => { - alias => { + -alias => { stop => '_stop', start => '_start' } @@ -51,7 +51,7 @@ Moose::Cookbook::Roles::Recipe2 - Advanced Role Composition - method exclusion a package Restartable::ButBroken; use Moose::Role; - with 'Restartable' => { excludes => [ 'stop', 'start' ] }; + with 'Restartable' => { -excludes => [ 'stop', 'start' ] }; sub stop { my $self = shift; @@ -82,7 +82,7 @@ C to private methods, and provide wrappers around the originals (1). with 'Restartable' => { - alias => { + -alias => { stop => '_stop', start => '_start' } @@ -92,10 +92,10 @@ In the C role, we want to provide an entirely new behavior for C and C. We exclude them entirely when composing the C role into C. -It's worth noting that the C parameter also accepts a single +It's worth noting that the C<-excludes> parameter also accepts a single string as an argument if you just want to exclude one method. - with 'Restartable' => { excludes => [ 'stop', 'start' ] }; + with 'Restartable' => { -excludes => [ 'stop', 'start' ] }; =head1 CONCLUSION diff --git a/lib/Moose/Cookbook/Roles/Recipe3.pod b/lib/Moose/Cookbook/Roles/Recipe3.pod index 3c18955..a646b35 100644 --- a/lib/Moose/Cookbook/Roles/Recipe3.pod +++ b/lib/Moose/Cookbook/Roles/Recipe3.pod @@ -88,7 +88,7 @@ We could also pass parameters to the role we're applying: MyApp::Role::Job::Manager->meta->apply( $lisa, - alias => { assign_work => 'get_off_your_lazy_behind' }, + -alias => { assign_work => 'get_off_your_lazy_behind' }, ); We saw examples of how method exclusion and alias working in L and C role parameters have been renamed to C<-alias> +and C<-excludes>. The old names still work, but new code should use the new +names, and eventually the old ones will be deprecated and removed. + =head1 Version 0.84 When an attribute generates I accessors, we now warn. This is to help diff --git a/lib/Moose/Manual/Roles.pod b/lib/Moose/Manual/Roles.pod index 7108ded..938f348 100644 --- a/lib/Moose/Manual/Roles.pod +++ b/lib/Moose/Manual/Roles.pod @@ -227,19 +227,19 @@ from both its roles, we can alias the methods: use Moose; - with 'Breakable' => { alias => { break => 'break_bone' } }, - 'Breakdancer' => { alias => { break => 'break_dance' } }; + with 'Breakable' => { -alias => { break => 'break_bone' } }, + 'Breakdancer' => { -alias => { break => 'break_dance' } }; However, aliasing a method simply makes a I of the method with the new name. We also need to exclude the original name: with 'Breakable' => { - alias => { break => 'break_bone' }, - excludes => 'break', + -alias => { break => 'break_bone' }, + -excludes => 'break', }, 'Breakdancer' => { - alias => { break => 'break_dance' }, - excludes => 'break', + -alias => { break => 'break_dance' }, + -excludes => 'break', }; The excludes parameter prevents the C method from being composed diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 8e8aec5..a01a8db 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -812,8 +812,8 @@ This method creates a new role object with the provided name. This method accepts a list of array references. Each array reference should contain a role name as its first element. The second element is -an optional hash reference. The hash reference can contain C -and C keys to control how methods are composed from the role. +an optional hash reference. The hash reference can contain C<-excludes> +and C<-alias> keys to control how methods are composed from the role. The return value is a new L that represents the combined roles. diff --git a/lib/Moose/Meta/Role/Application.pm b/lib/Moose/Meta/Role/Application.pm index f59ae8e..e5e6243 100644 --- a/lib/Moose/Meta/Role/Application.pm +++ b/lib/Moose/Meta/Role/Application.pm @@ -9,13 +9,13 @@ $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; __PACKAGE__->meta->add_attribute('method_exclusions' => ( - init_arg => 'excludes', + init_arg => '-excludes', reader => 'get_method_exclusions', default => sub { [] } )); __PACKAGE__->meta->add_attribute('method_aliases' => ( - init_arg => 'alias', + init_arg => '-alias', reader => 'get_method_aliases', default => sub { {} } )); @@ -23,11 +23,18 @@ __PACKAGE__->meta->add_attribute('method_aliases' => ( sub new { my ($class, %params) = @_; - if (exists $params{excludes}) { + if (exists $params{excludes} && !exists $params{'-excludes'}) { + $params{'-excludes'} = delete $params{excludes}; + } + if (exists $params{alias} && !exists $params{'-alias'}) { + $params{'-alias'} = delete $params{alias}; + } + + if (exists $params{'-excludes'}) { # I wish we had coercion here :) - $params{excludes} = (ref $params{excludes} eq 'ARRAY' - ? $params{excludes} - : [ $params{excludes} ]); + $params{'-excludes'} = (ref $params{'-excludes'} eq 'ARRAY' + ? $params{'-excludes'} + : [ $params{'-excludes'} ]); } $class->_new(\%params); diff --git a/lib/Moose/Meta/Role/Application/RoleSummation.pm b/lib/Moose/Meta/Role/Application/RoleSummation.pm index 5125f95..d5b5e72 100644 --- a/lib/Moose/Meta/Role/Application/RoleSummation.pm +++ b/lib/Moose/Meta/Role/Application/RoleSummation.pm @@ -22,11 +22,13 @@ __PACKAGE__->meta->add_attribute('role_params' => ( 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}; + my $excludes_key = exists $self->role_params->{$role}->{'-excludes'} ? + '-excludes' : 'excludes'; + if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$excludes_key}) { + if (ref $self->role_params->{$role}->{$excludes_key} eq 'ARRAY') { + return $self->role_params->{$role}->{$excludes_key}; } - return [ $self->role_params->{$role}->{excludes} ]; + return [ $self->role_params->{$role}->{$excludes_key} ]; } return []; } @@ -34,8 +36,10 @@ sub get_exclusions_for_role { 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}; + my $alias_key = exists $self->role_params->{$role}->{'-alias'} ? + '-alias' : 'alias'; + if ($self->role_params->{$role} && defined $self->role_params->{$role}->{$alias_key}) { + return $self->role_params->{$role}->{$alias_key}; } return {}; } diff --git a/lib/Moose/Util.pm b/lib/Moose/Util.pm index fa0475b..1aff77a 100644 --- a/lib/Moose/Util.pm +++ b/lib/Moose/Util.pm @@ -308,8 +308,8 @@ applicant can be a role name, class name, or object. The C<$applicant> must already have a metaclass object. The list of C<@roles> should be a list of names, each of which can be -followed by an optional hash reference of options (C and -C). +followed by an optional hash reference of options (C<-excludes> and +C<-alias>). =item B diff --git a/t/020_attributes/024_attribute_traits_parameterized.t b/t/020_attributes/024_attribute_traits_parameterized.t index 86cc961..8b473e5 100644 --- a/t/020_attributes/024_attribute_traits_parameterized.t +++ b/t/020_attributes/024_attribute_traits_parameterized.t @@ -20,7 +20,7 @@ use Test::More tests => 5; has foo => ( traits => [ 'My::Attribute::Trait' => { - alias => { + -alias => { reversed_name => 'eman', }, }, @@ -36,10 +36,10 @@ use Test::More tests => 5; has foo => ( traits => [ 'My::Attribute::Trait' => { - alias => { + -alias => { reversed_name => 'reversed', }, - excludes => 'reversed_name', + -excludes => 'reversed_name', }, ], is => 'bare', diff --git a/t/030_roles/012_method_exclusion_in_composition.t b/t/030_roles/012_method_exclusion_in_composition.t index b0ae2df..8c3456e 100644 --- a/t/030_roles/012_method_exclusion_in_composition.t +++ b/t/030_roles/012_method_exclusion_in_composition.t @@ -19,7 +19,7 @@ use Test::Exception; package My::Class; use Moose; - with 'My::Role' => { excludes => 'bar' }; + with 'My::Role' => { -excludes => 'bar' }; } ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz); @@ -29,7 +29,7 @@ ok(!My::Class->meta->has_method('bar'), '... but we excluded bar'); package My::OtherRole; use Moose::Role; - with 'My::Role' => { excludes => 'foo' }; + with 'My::Role' => { -excludes => 'foo' }; sub foo { 'My::OtherRole::foo' } sub bar { 'My::OtherRole::bar' } @@ -60,8 +60,8 @@ ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is requ use Moose; ::lives_ok { - with 'Foo::Role' => { excludes => 'foo' }, - 'Bar::Role' => { excludes => 'foo' }, + with 'Foo::Role' => { -excludes => 'foo' }, + 'Bar::Role' => { -excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; @@ -70,7 +70,7 @@ ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is requ ::throws_ok { with 'Foo::Role', - 'Bar::Role' => { excludes => 'foo' }, + 'Bar::Role' => { -excludes => 'foo' }, 'Baz::Role'; } qr/Due to a method name conflict in roles 'Baz::Role' and 'Foo::Role', the method 'foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, '... composed our roles correctly'; @@ -88,8 +88,8 @@ ok(My::OtherRole->meta->requires_method('bar'), '... and the &bar method is requ use Moose::Role; ::lives_ok { - with 'Foo::Role' => { excludes => 'foo' }, - 'Bar::Role' => { excludes => 'foo' }, + with 'Foo::Role' => { -excludes => 'foo' }, + 'Bar::Role' => { -excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; } @@ -103,7 +103,7 @@ ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not ::lives_ok { with 'Foo::Role', - 'Bar::Role' => { excludes => 'foo' }, + 'Bar::Role' => { -excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; } diff --git a/t/030_roles/013_method_aliasing_in_composition.t b/t/030_roles/013_method_aliasing_in_composition.t index 787b2bb..d16ff10 100644 --- a/t/030_roles/013_method_aliasing_in_composition.t +++ b/t/030_roles/013_method_aliasing_in_composition.t @@ -22,14 +22,14 @@ use Test::Exception; use Moose; ::lives_ok { - with 'My::Role' => { alias => { bar => 'role_bar' } }; + with 'My::Role' => { -alias => { bar => 'role_bar' } }; } '... this succeeds'; package My::Class::Failure; use Moose; ::throws_ok { - with 'My::Role' => { alias => { bar => 'role_bar' } }; + with 'My::Role' => { -alias => { bar => 'role_bar' } }; } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds'; sub role_bar { 'FAIL' } @@ -42,7 +42,7 @@ ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar ro use Moose::Role; ::lives_ok { - with 'My::Role' => { alias => { bar => 'role_bar' } }; + with 'My::Role' => { -alias => { bar => 'role_bar' } }; } '... this succeeds'; sub bar { 'My::OtherRole::bar' } @@ -51,7 +51,7 @@ ok(My::Class->meta->has_method($_), "we have a $_ method") for qw(foo baz bar ro use Moose::Role; ::throws_ok { - with 'My::Role' => { alias => { bar => 'role_bar' } }; + with 'My::Role' => { -alias => { bar => 'role_bar' } }; } qr/Cannot create a method alias if a local method of the same name exists/, '... this succeeds'; sub role_bar { 'FAIL' } @@ -66,7 +66,7 @@ ok(!My::OtherRole->meta->requires_method('role_bar'), '... and the &role_bar met use Moose::Role; ::lives_ok { - with 'My::Role' => { alias => { bar => 'role_bar' } }; + with 'My::Role' => { -alias => { bar => 'role_bar' } }; } '... this succeeds'; } @@ -93,8 +93,8 @@ ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is r use Moose; ::lives_ok { - with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, - 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, + with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, + 'Bar::Role' => { -alias => { 'foo' => 'bar_foo' }, -excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; @@ -102,8 +102,8 @@ ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is r use Moose; ::throws_ok { - with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, - 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, + 'Bar::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, 'Baz::Role'; } qr/Due to a method name conflict in roles 'Bar::Role' and 'Foo::Role', the method 'foo_foo' must be implemented or excluded by 'My::Foo::Class::Broken'/, '... composed our roles correctly'; @@ -123,8 +123,8 @@ ok(My::AliasingRole->meta->requires_method('bar'), '... and the &bar method is r use Moose::Role; ::lives_ok { - with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, - 'Bar::Role' => { alias => { 'foo' => 'bar_foo' }, excludes => 'foo' }, + with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, + 'Bar::Role' => { -alias => { 'foo' => 'bar_foo' }, -excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; } @@ -138,8 +138,8 @@ ok(!My::Foo::Role->meta->requires_method('foo'), '... and the &foo method is not use Moose::Role; ::lives_ok { - with 'Foo::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, - 'Bar::Role' => { alias => { 'foo' => 'foo_foo' }, excludes => 'foo' }, + with 'Foo::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, + 'Bar::Role' => { -alias => { 'foo' => 'foo_foo' }, -excludes => 'foo' }, 'Baz::Role'; } '... composed our roles correctly'; } diff --git a/t/030_roles/014_more_alias_and_exclude.t b/t/030_roles/014_more_alias_and_exclude.t index a544600..60b3731 100644 --- a/t/030_roles/014_more_alias_and_exclude.t +++ b/t/030_roles/014_more_alias_and_exclude.t @@ -47,10 +47,10 @@ use Test::Exception; 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/] }; + 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'; } diff --git a/t/030_roles/033_role_exclusion_and_alias_bug.t b/t/030_roles/033_role_exclusion_and_alias_bug.t index 097356b..ac1b11a 100644 --- a/t/030_roles/033_role_exclusion_and_alias_bug.t +++ b/t/030_roles/033_role_exclusion_and_alias_bug.t @@ -19,8 +19,8 @@ use Test::Moose; use Moose; with 'My::Role' => { - alias => { foo => 'baz', bar => 'gorch' }, - excludes => ['foo', 'bar'], + -alias => { foo => 'baz', bar => 'gorch' }, + -excludes => ['foo', 'bar'], }; } @@ -42,8 +42,8 @@ use Test::Moose; use Moose::Role; with 'My::Role' => { - alias => { foo => 'baz', bar => 'gorch' }, - excludes => ['foo', 'bar'], + -alias => { foo => 'baz', bar => 'gorch' }, + -excludes => ['foo', 'bar'], }; package My::Class::Again; diff --git a/t/030_roles/039_application_toclass.t b/t/030_roles/039_application_toclass.t index 67c7d4e..573cec1 100644 --- a/t/030_roles/039_application_toclass.t +++ b/t/030_roles/039_application_toclass.t @@ -18,12 +18,12 @@ do { package Consumer::Excludes; use Moose; - with 'Role::Foo' => { excludes => 'foo' }; + with 'Role::Foo' => { -excludes => 'foo' }; package Consumer::Aliases; use Moose; - with 'Role::Foo' => { alias => { 'foo' => 'role_foo' } }; + with 'Role::Foo' => { -alias => { 'foo' => 'role_foo' } }; package Consumer::Overrides; use Moose; diff --git a/t/050_metaclasses/020_metaclass_parameterized_traits.t b/t/050_metaclasses/020_metaclass_parameterized_traits.t index 776be95..ac6f79a 100644 --- a/t/050_metaclasses/020_metaclass_parameterized_traits.t +++ b/t/050_metaclasses/020_metaclass_parameterized_traits.t @@ -17,7 +17,7 @@ use Test::More tests => 5; package My::Class; use Moose -traits => [ 'My::Trait' => { - alias => { + -alias => { reversed_name => 'enam', }, }, @@ -28,10 +28,10 @@ use Test::More tests => 5; package My::Other::Class; use Moose -traits => [ 'My::Trait' => { - alias => { + -alias => { reversed_name => 'reversed', }, - excludes => 'reversed_name', + -excludes => 'reversed_name', }, ]; }