From: Dave Rolsky Date: Tue, 30 Aug 2011 05:34:27 +0000 (-0500) Subject: Deprecating calling Moose->init_meta directly X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7df88bfa059827872bebb093855d9597f285823f;p=gitmo%2FMoose.git Deprecating calling Moose->init_meta directly The hack is kind of gross but I think it can safely go away once it finds all the culprits doing this. --- diff --git a/lib/Moose.pm b/lib/Moose.pm index f776e12..1defef9 100644 --- a/lib/Moose.pm +++ b/lib/Moose.pm @@ -131,10 +131,16 @@ Moose::Exporter->setup_import_methods( ], ); +our $CALLED_VIA_EXPORT_HACK; sub init_meta { shift; my %args = @_; + Moose::Deprecated::deprecated( + 'Calling Moose->init_meta directly has been deprecated.' + . ' Use Moose::Exporter and let it call init_meta for you' ) + unless $CALLED_VIA_EXPORT_HACK; + my $class = $args{for_class} or Moose->throw_error("Cannot call init_meta without specifying a for_class"); my $base_class = $args{base_class} || 'Moose::Object'; diff --git a/lib/Moose/Deprecated.pm b/lib/Moose/Deprecated.pm index 1df1f05..e457778 100644 --- a/lib/Moose/Deprecated.pm +++ b/lib/Moose/Deprecated.pm @@ -4,6 +4,7 @@ use strict; use warnings; use Package::DeprecationManager 0.07 -deprecations => { + 'calling Moose->init_meta directly' => '2.0200', 'optimized type constraint sub ref' => '2.0000', 'default is for Native Trait' => '1.14', 'default default for Native Trait' => '1.14', diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index fad3c25..4bc5b2c 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -418,6 +418,8 @@ sub _make_import_sub { strict->import; warnings->import; + local $Moose::CALLED_VIA_EXPORT_HACK = 1; + my $did_init_meta; for my $c ( grep { $_->can('init_meta') } $class, @{$exports_from} ) { diff --git a/t/basics/deprecations.t b/t/basics/deprecations.t index 2466f6f..bfbe93b 100644 --- a/t/basics/deprecations.t +++ b/t/basics/deprecations.t @@ -172,5 +172,17 @@ use Test::Requires { ); } +{ + package Pack4; + +} + +stderr_like { + Moose->init_meta( for_class => __PACKAGE__ ); +} +qr/\QCalling Moose->init_meta directly has been deprecated/, + 'deprecation warning when calling init_meta directly'; + + done_testing;