From: Dave Rolsky Date: Wed, 14 Jul 2010 16:12:38 +0000 (-0500) Subject: Add Moose::Deprecated, and clean up use of deprecated features in tests X-Git-Tag: 1.09~44 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3b400403de25dc3988b05a7b56a714db8f57f029;p=gitmo%2FMoose.git Add Moose::Deprecated, and clean up use of deprecated features in tests --- diff --git a/lib/Moose/Deprecated.pm b/lib/Moose/Deprecated.pm new file mode 100644 index 0000000..d2db110 --- /dev/null +++ b/lib/Moose/Deprecated.pm @@ -0,0 +1,17 @@ +package Moose::Deprecated; + +use strict; +use warnings; + +our $VERSION = '1.08'; +$VERSION = eval $VERSION; +our $AUTHORITY = 'cpan:STEVAN'; + +use Package::DeprecationManager -deprecations => { + 'pre-0.94 MetaRole API' => '0.93', + 'Moose::Exporter with_caller' => '0.89', + }, + -ignore => [qw( Moose Moose::Exporter Moose::Util::MetaRole )], + ; + +1; diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index be1a3c8..9a74e19 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -10,6 +10,7 @@ our $AUTHORITY = 'cpan:STEVAN'; use Class::MOP; use List::MoreUtils qw( first_index uniq ); +use Moose::Deprecated; use Moose::Util::MetaRole; use Sub::Exporter 0.980; use Sub::Name qw(subname); @@ -36,6 +37,14 @@ sub build_import_methods { my $exporting_package = $args{exporting_package} ||= caller(); + if ( $args{with_caller} ) { + Moose::Deprecated::deprecated( + feature => 'Moose::Exporter with_caller', + message => + 'The with_caller argument for Moose::Exporter has been deprecated' + ); + } + $EXPORT_SPEC{$exporting_package} = \%args; my @exports_from = $class->_follow_also($exporting_package); @@ -545,11 +554,13 @@ sub _make_init_meta { return unless Class::MOP::class_of( $options{for_class} ); - Moose::Util::MetaRole::apply_metaroles( - for => $options{for_class}, - %new_style_roles, - %old_style_roles, - ); + if ( %new_style_roles || %old_style_roles ) { + Moose::Util::MetaRole::apply_metaroles( + for => $options{for_class}, + %new_style_roles, + %old_style_roles, + ); + } Moose::Util::MetaRole::apply_base_class_roles( for_class => $options{for_class}, diff --git a/lib/Moose/Util/MetaRole.pm b/lib/Moose/Util/MetaRole.pm index 6b06d0f..eee501f 100644 --- a/lib/Moose/Util/MetaRole.pm +++ b/lib/Moose/Util/MetaRole.pm @@ -10,8 +10,15 @@ our $AUTHORITY = 'cpan:STEVAN'; use List::MoreUtils qw( all ); use List::Util qw( first ); +use Moose::Deprecated; sub apply_metaclass_roles { + Moose::Deprecated::deprecated( + feature => 'pre-0.94 MetaRole API', + message => + 'The old Moose::Util::MetaRole API (before version 0.94) has been deprecated' + ); + goto &apply_metaroles; } @@ -36,7 +43,13 @@ sub apply_metaroles { sub _fixup_old_style_args { my $args = shift; - return if $args->{class_metaroles} || $args->{roles_metaroles}; + return if $args->{class_metaroles} || $args->{role_metaroles}; + + Moose::Deprecated::deprecated( + feature => 'pre-0.94 MetaRole API', + message => + 'The old Moose::Util::MetaRole API (before version 0.94) has been deprecated' + ); $args->{for} = delete $args->{for_class} if exists $args->{for_class}; diff --git a/t/050_metaclasses/012_moose_exporter.t b/t/050_metaclasses/012_moose_exporter.t index c6c1f4d..d693b83 100644 --- a/t/050_metaclasses/012_moose_exporter.t +++ b/t/050_metaclasses/012_moose_exporter.t @@ -111,7 +111,7 @@ BEGIN { use Moose (); sub wrapped2 { - my $caller = shift; + my $caller = shift->name; return $caller . ' called wrapped2'; } @@ -120,9 +120,9 @@ BEGIN { } Moose::Exporter->setup_import_methods( - with_caller => ['wrapped2'], - as_is => ['as_is1'], - also => 'MooseX::Sugar', + with_meta => ['wrapped2'], + as_is => ['as_is1'], + also => 'MooseX::Sugar', ); } @@ -262,13 +262,13 @@ BEGIN { use Moose (); sub has { - my $caller = shift; + my $caller = shift->name; return $caller . ' called has'; } Moose::Exporter->setup_import_methods( - with_caller => ['has'], - also => 'Moose', + with_meta => ['has'], + also => 'Moose', ); } @@ -298,7 +298,7 @@ BEGIN { ::stderr_like { Moose::Exporter->setup_import_methods( also => ['Moose'], - with_caller => ['does_not_exist'], + with_meta => ['does_not_exist'], ); } qr/^Trying to export undefined sub NonExistentExport::does_not_exist/, "warns when a non-existent method is requested to be exported"; @@ -316,6 +316,7 @@ BEGIN { { package AllOptions; use Moose (); + use Moose::Deprecated -api_version => '0.88'; use Moose::Exporter; Moose::Exporter->setup_import_methods( diff --git a/t/050_metaclasses/015_metarole.t b/t/050_metaclasses/015_metarole.t index c91c2a6..6d80c50 100644 --- a/t/050_metaclasses/015_metarole.t +++ b/t/050_metaclasses/015_metarole.t @@ -572,10 +572,10 @@ use Moose::Util::MetaRole; my %p = @_; Moose->init_meta(%p); return Moose::Util::MetaRole::apply_metaroles( - for_class => $p{for_class}, + for => $p{for_class}, # Causes us to recurse through init_meta, as we have to # load MyMetaclassRole from disk. - metaclass_roles => [qw/MyMetaclassRole/], + class_metaroles => { class => [qw/MyMetaclassRole/] }, ); } } diff --git a/t/050_metaclasses/023_easy_init_meta.t b/t/050_metaclasses/023_easy_init_meta.t index 5f2c28e..ac7eda8 100644 --- a/t/050_metaclasses/023_easy_init_meta.t +++ b/t/050_metaclasses/023_easy_init_meta.t @@ -26,10 +26,12 @@ use Test::Moose qw(does_ok); use Moose::Exporter; Moose::Exporter->setup_import_methods( - metaclass_roles => ['Foo::Trait::Class'], - role_metaclass_roles => ['Foo::Trait::Class'], - attribute_metaclass_roles => ['Foo::Trait::Attribute'], - base_class_roles => ['Foo::Role::Base'], + class_metaroles => { + class => ['Foo::Trait::Class'], + attribute => ['Foo::Trait::Attribute'], + }, + role_metaroles => { role => ['Foo::Trait::Class'] }, + base_class_roles => ['Foo::Role::Base'], ); } @@ -50,13 +52,15 @@ use Test::Moose qw(does_ok); use Moose (); use Moose::Exporter; - my ($import, $unimport, $init_meta) = - Moose::Exporter->build_import_methods( - also => 'Moose', - metaclass_roles => ['Foo::Trait::Class'], - attribute_metaclass_roles => ['Foo::Trait::Attribute'], - base_class_roles => ['Foo::Role::Base'], - install => [qw(import unimport)], + my ( $import, $unimport, $init_meta ) + = Moose::Exporter->build_import_methods( + also => 'Moose', + class_metaroles => { + class => ['Foo::Trait::Class'], + attribute => ['Foo::Trait::Attribute'], + }, + base_class_roles => ['Foo::Role::Base'], + install => [qw(import unimport)], ); sub init_meta { diff --git a/t/050_metaclasses/030_metarole_combination.t b/t/050_metaclasses/030_metarole_combination.t index 899b042..31a8ed8 100644 --- a/t/050_metaclasses/030_metarole_combination.t +++ b/t/050_metaclasses/030_metarole_combination.t @@ -114,7 +114,7 @@ our @applications; sub init_meta { my ( $self, %options ) = @_; return Moose::Util::MetaRole::apply_metaroles( - for_class => Moose::Role->init_meta(%options), + for => Moose::Role->init_meta(%options), role_metaroles => { role => ['Role::WithCustomApplication'], application_to_class => diff --git a/t/050_metaclasses/050_metarole_backcompat.t b/t/050_metaclasses/050_metarole_backcompat.t index d4a6adf..2ded6e4 100644 --- a/t/050_metaclasses/050_metarole_backcompat.t +++ b/t/050_metaclasses/050_metarole_backcompat.t @@ -13,6 +13,10 @@ use Test::Exception; use Moose::Util::MetaRole; +{ + no warnings 'redefine'; + *Moose::Deprecated::deprecated = sub { return }; +} { package My::Meta::Class; diff --git a/t/lib/MyExporter.pm b/t/lib/MyExporter.pm index 78836e0..a2bc67f 100644 --- a/t/lib/MyExporter.pm +++ b/t/lib/MyExporter.pm @@ -5,8 +5,8 @@ use Moose::Exporter; use Test::More; Moose::Exporter->setup_import_methods( - with_caller => [ qw(with_prototype) ], - as_is => [ qw(as_is_prototype) ], + with_meta => [qw(with_prototype)], + as_is => [qw(as_is_prototype)], ); sub with_prototype (&) { @@ -21,4 +21,4 @@ sub as_is_prototype (&) { $code->(); } -1; \ No newline at end of file +1;