From: Dave Rolsky Date: Fri, 15 Oct 2010 01:40:41 +0000 (-0500) Subject: Fix deprecation so we ignore all CMOP & Moose packages in the stack X-Git-Tag: 1.16~34 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3cf2f9ecb85e30c5bf843f8248802aa9de04942c;p=gitmo%2FMoose.git Fix deprecation so we ignore all CMOP & Moose packages in the stack Fix native traits deprecation warnings to be smarter --- diff --git a/Changes b/Changes index 8c7cf41..6052cb1 100644 --- a/Changes +++ b/Changes @@ -31,6 +31,15 @@ NEXT something that can be assigned to). This should fix issues with KiokuDB::Class. (doy) + * The deprecated "default is" warning no longer happens is the attribute has + any accessor method defined (accessor, reader, writer). + + * The "default default" code for some native delegations no longer issues a + deprecation warning when the attribute is required or has a builder. + + * Setting a "default default" caused a fatal error if you defined a builder + for the attribute. + 1.15 Tue, Oct 5, 2010 [API CHANGES] diff --git a/Makefile.PL b/Makefile.PL index 524daf0..2f73418 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -17,7 +17,7 @@ requires 'Carp'; requires 'Class::MOP' => '1.10'; requires 'Data::OptList' => '0'; requires 'List::MoreUtils' => '0.12'; -requires 'Package::DeprecationManager' => '0.04'; +requires 'Package::DeprecationManager' => '0.07'; requires 'Params::Util' => '1.00'; requires 'Scalar::Util' => '1.19'; requires 'Sub::Exporter' => '0.980'; diff --git a/lib/Moose/Deprecated.pm b/lib/Moose/Deprecated.pm index d3725a2..78d3e8d 100644 --- a/lib/Moose/Deprecated.pm +++ b/lib/Moose/Deprecated.pm @@ -18,14 +18,7 @@ use Package::DeprecationManager -deprecations => { 'type without sugar' => '0.72', 'Moose::init_meta' => '0.56', }, - -ignore => [ - qw( Moose - Moose::Exporter - Moose::Meta::Attribute - Moose::Meta::Class - Moose::Util::MetaRole - ) - ], + -ignore => [qr/^(?:Class::MOP|Moose)(?:::)?/], ; 1; diff --git a/lib/Moose/Meta/Attribute/Native/Trait.pm b/lib/Moose/Meta/Attribute/Native/Trait.pm index a44b7dd..4406d02 100644 --- a/lib/Moose/Meta/Attribute/Native/Trait.pm +++ b/lib/Moose/Meta/Attribute/Native/Trait.pm @@ -1,6 +1,8 @@ package Moose::Meta::Attribute::Native::Trait; use Moose::Role; + +use List::MoreUtils qw( any ); use Moose::Util::TypeConstraints; use Moose::Deprecated; @@ -15,7 +17,9 @@ before '_process_options' => sub { $self->_check_helper_type( $options, $name ); - if ( !exists $options->{is} && $self->can('_default_is') ) { + if ( !( any { exists $options->{$_} } qw( is reader writer accessor ) ) + && $self->can('_default_is') ) { + $options->{is} = $self->_default_is; Moose::Deprecated::deprecated( @@ -25,7 +29,14 @@ before '_process_options' => sub { ); } - if ( !exists $options->{default} && $self->can('_default_default') ) { + if ( + !( + $options->{required} + || any { exists $options->{$_} } qw( default builder ) + ) + && $self->can('_default_default') + ) { + $options->{default} = $self->_default_default; Moose::Deprecated::deprecated( diff --git a/t/010_basics/030_deprecations.t b/t/010_basics/030_deprecations.t index 211e6df..5db3574 100644 --- a/t/010_basics/030_deprecations.t +++ b/t/010_basics/030_deprecations.t @@ -53,5 +53,72 @@ use Test::Requires { ); } +{ + package Pack1; + + use Moose; + + ::stderr_is{ has foo => ( + traits => ['String'], + reader => '_foo', + isa => 'Str', + default => q{}, + ); + } q{}, + 'Providing a reader for a String trait avoids default is warning'; + + ::stderr_is{ has bar => ( + traits => ['String'], + is => 'ro', + isa => 'Str', + builder => '_build_foo', + ); + } q{}, + 'Providing a builder for a String trait avoids default default warning'; + + sub _build_foo { } +} + +{ + package Pack2; + + use Moose; + + ::stderr_is{ has foo => ( + traits => ['String'], + writer => '_foo', + isa => 'Str', + default => q{}, + ); + } q{}, + 'Providing a writer for a String trait avoids default is warning'; + + ::stderr_is{ has bar => ( + traits => ['String'], + is => 'ro', + isa => 'Str', + required => 1, + ); + } q{}, + 'Making a String trait required avoids default default warning'; + + sub _build_foo { } +} + +{ + package Pack3; + + use Moose; + + ::stderr_is{ has foo => ( + traits => ['String'], + accessor => '_foo', + isa => 'Str', + default => q{}, + ); + } q{}, + 'Providing an accessor for a String trait avoids default is warning'; +} + done_testing;