From: Matt S Trout Date: Wed, 13 Oct 2010 05:23:35 +0000 (+0100) Subject: improve alias/excludes warning X-Git-Tag: 1.16~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=a8eb9fe077a08efb845facc0ba156a79682fa546;p=gitmo%2FMoose.git improve alias/excludes warning --- diff --git a/lib/Moose/Meta/Role/Application.pm b/lib/Moose/Meta/Role/Application.pm index de1caf8..7013094 100644 --- a/lib/Moose/Meta/Role/Application.pm +++ b/lib/Moose/Meta/Role/Application.pm @@ -20,15 +20,17 @@ __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} ) { - Moose::Deprecated::deprecated( - feature => 'alias or excludes', - message => - "The alias and excludes options for role application have been renamed -alias and -excludes" - ); + $params{fire_alias_excludes_warning} = 1; } if ( exists $params{excludes} && !exists $params{'-excludes'} ) { @@ -73,6 +75,14 @@ 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 d4d4004..7074266 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/, + 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?)/, 'passing excludes or alias with a leading dash warns'; ::ok( !Foo->meta->has_method('thing'), @@ -59,9 +59,8 @@ use Test::Requires { Foo->meta->has_method('thing2'), 'thing2 method is created as alias in role application' ); - } - ); -} + } ); + } { package Pack1; @@ -131,7 +130,6 @@ use Test::Requires { q{}, 'Providing a writer for a String trait avoids default is warning'; } - ); } {