From: nperez Date: Wed, 13 Oct 2010 06:51:48 +0000 (-0500) Subject: Move logic into Moose::Meta::Role for deprecation check of excludes and alias. Add... X-Git-Tag: 1.16~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4c52e860380be0f4c928cd0171c4f4127edacaaf;p=gitmo%2FMoose.git Move logic into Moose::Meta::Role for deprecation check of excludes and alias. Add friendlier wording to the warning. Update the test to check for new wording --- diff --git a/lib/Moose/Meta/Role.pm b/lib/Moose/Meta/Role.pm index 1dd1a50..b711e4e 100644 --- a/lib/Moose/Meta/Role.pm +++ b/lib/Moose/Meta/Role.pm @@ -448,6 +448,40 @@ sub apply { } Class::MOP::load_class($application_class); + + my $deprecation_check = 0; + + if ( exists $args{excludes} && !exists $args{'-excludes'} ) { + $args{'-excludes'} = delete $args{excludes}; + $deprecation_check = 1; + } + if ( exists $args{alias} && !exists $args{'-alias'} ) { + $args{'-alias'} = delete $args{alias}; + $deprecation_check = 1; + } + + if ( $deprecation_check ) { + + Moose::Deprecated::deprecated( + feature => 'alias or excludes', + message => + 'The alias and excludes options for role application'. + ' have been renamed -alias and -excludes'. + " (${\$other->name} is consuming ${\$self->name}". + " - do you need to upgrade ${\$other->name}?)" + ); + } + + if ( exists $args{'-excludes'} ) { + + # I wish we had coercion here :) + $args{'-excludes'} = ( + ref $args{'-excludes'} eq 'ARRAY' + ? $args{'-excludes'} + : [ $args{'-excludes'} ] + ); + } + return $application_class->new(%args)->apply($self, $other, \%args); } diff --git a/lib/Moose/Meta/Role/Application.pm b/lib/Moose/Meta/Role/Application.pm index 7013094..34f6f58 100644 --- a/lib/Moose/Meta/Role/Application.pm +++ b/lib/Moose/Meta/Role/Application.pm @@ -20,36 +20,8 @@ __PACKAGE__->meta->add_attribute('method_aliases' => ( default => sub { {} } )); -__PACKAGE__->meta->add_attribute('fire_alias_excludes_warning' => ( - init_arg => 'fire_alias_excludes_warning', - reader => 'fire_alias_excludes_warning', - default => 0 -)); - sub new { my ($class, %params) = @_; - - if ( exists $params{excludes} || exists $params{alias} ) { - $params{fire_alias_excludes_warning} = 1; - } - - 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'} ] - ); - } - $class->_new(\%params); } @@ -75,14 +47,6 @@ sub is_aliased_method { sub apply { my $self = shift; - if ($self->fire_alias_excludes_warning) { - Moose::Deprecated::deprecated( - feature => 'alias or excludes', - message => - "The alias and excludes options for role application have been renamed -alias and -excludes (applying ${\$_[0]->name} to ${\$_[1]->name} - do you need to upgrade ${\$_[1]->name}?)" - ); - } - $self->check_role_exclusions(@_); $self->check_required_methods(@_); $self->check_required_attributes(@_); diff --git a/t/010_basics/030_deprecations.t b/t/010_basics/030_deprecations.t index 7074266..3354f2e 100644 --- a/t/010_basics/030_deprecations.t +++ b/t/010_basics/030_deprecations.t @@ -49,7 +49,7 @@ use Test::Requires { ::stderr_like{ with 'Role' => { excludes => ['thing'], alias => { thing => 'thing2' } }; } - qr/\QThe alias and excludes options for role application have been renamed -alias and -excludes (applying Role to Foo - do you need to upgrade Foo?)/, + qr/\QThe alias and excludes options for role application have been renamed -alias and -excludes (Foo is consuming Role - do you need to upgrade Foo?)/, 'passing excludes or alias with a leading dash warns'; ::ok( !Foo->meta->has_method('thing'), @@ -59,8 +59,9 @@ use Test::Requires { Foo->meta->has_method('thing2'), 'thing2 method is created as alias in role application' ); - } ); - } + } + ); +} { package Pack1; @@ -164,6 +165,18 @@ use Test::Requires { q{}, 'Providing a accessor for a String trait avoids default is warning'; } +<<<<<<< HEAD +======= + qr/\QThe alias and excludes options for role application have been renamed -alias and -excludes (Foo is consuming Role - do you need to upgrade Foo?)/, + 'passing excludes or alias with a leading dash warns'; + ::ok( + !Foo->meta->has_method('thing'), + 'thing method is excluded from role application' + ); + ::ok( + Foo->meta->has_method('thing2'), + 'thing2 method is created as alias in role application' +>>>>>>> Move logic into Moose::Meta::Role for deprecation check of excludes and alias. Add friendlier wording to the warning. Update the test to check for new wording ); sub _build_foo { q{} }