From: Dave Rolsky Date: Mon, 27 Sep 2010 22:03:35 +0000 (-0500) Subject: Deprecate _default_is and _default_default for native traits. X-Git-Tag: 1.15~20 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=34d6d196372ac514abfe975cef15e8afd0af04c4;p=gitmo%2FMoose.git Deprecate _default_is and _default_default for native traits. Add some tests for these and other deprecations --- diff --git a/lib/Moose/Deprecated.pm b/lib/Moose/Deprecated.pm index 99cfa26..d3725a2 100644 --- a/lib/Moose/Deprecated.pm +++ b/lib/Moose/Deprecated.pm @@ -8,13 +8,15 @@ $VERSION = eval $VERSION; our $AUTHORITY = 'cpan:STEVAN'; use Package::DeprecationManager -deprecations => { - 'coerce without coercion' => '1.08', - 'pre-0.94 MetaRole API' => '0.94', - 'alias or excludes' => '0.89', - 'Role type' => '0.84', - 'subtype without sugar' => '0.72', - 'type without sugar' => '0.72', - 'Moose::init_meta' => '0.56', + 'default is for Native Trait' => '1.14', + 'default default for Native Trait' => '1.14', + 'coerce without coercion' => '1.08', + 'pre-0.94 MetaRole API' => '0.94', + 'alias or excludes' => '0.89', + 'Role type' => '0.84', + 'subtype without sugar' => '0.72', + 'type without sugar' => '0.72', + 'Moose::init_meta' => '0.56', }, -ignore => [ qw( Moose diff --git a/lib/Moose/Meta/Attribute/Native/Trait.pm b/lib/Moose/Meta/Attribute/Native/Trait.pm index c8c0a6a..9fa865d 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait.pm @@ -2,6 +2,7 @@ package Moose::Meta::Attribute::Native::Trait; use Moose::Role; use Moose::Util::TypeConstraints; +use Moose::Deprecated; our $VERSION = '1.15'; $VERSION = eval $VERSION; @@ -14,11 +15,25 @@ before '_process_options' => sub { $self->_check_helper_type( $options, $name ); - $options->{is} = $self->_default_is - if !exists $options->{is} && $self->can('_default_is'); + if ( !exists $options->{is} && $self->can('_default_is') ) { + $options->{is} = $self->_default_is; - $options->{default} = $self->_default_default - if !exists $options->{default} && $self->can('_default_default'); + Moose::Deprecated::deprecated( + feature => 'default is for Native Trait', + message => + q{Allowing a native trait to automatically supply a value for "is" is deprecated} + ); + } + + if ( !exists $options->{default} && $self->can('_default_default') ) { + $options->{default} = $self->_default_default; + + Moose::Deprecated::deprecated( + feature => 'default default for Native Trait', + message => + 'Allowing a native trait to automatically supply a default is deprecated' + ); + } }; sub _check_helper_type { diff --git a/t/010_basics/030_deprecations.t b/t/010_basics/030_deprecations.t new file mode 100644 index 0000000..211e6df --- /dev/null +++ b/t/010_basics/030_deprecations.t @@ -0,0 +1,57 @@ +use strict; +use warnings; + +use Test::More; + +use Test::Requires { + 'Test::Output' => '0.01', +}; + +{ + package Role; + + use Moose::Role; + + sub thing { } +} + +{ + package Foo; + + use Moose; + + ::stderr_like{ has foo => ( + traits => ['String'], + is => 'ro', + isa => 'Str', + ); + } + qr/\QAllowing a native trait to automatically supply a default is deprecated/, + 'Not providing a default for native String trait warns'; + + ::stderr_like{ has bar => ( + traits => ['String'], + isa => 'Str', + default => q{}, + ); + } + qr/\QAllowing a native trait to automatically supply a value for "is" is deprecated/, + 'Not providing a value for is with native String trait warns'; + + ::stderr_like{ with 'Role' => + { excludes => ['thing'], alias => { thing => 'thing2' } }; + } + qr/\QThe alias and excludes options for role application have been renamed -alias and -excludes/, + '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' + ); +} + +done_testing; +