From: Jesse Luehrs Date: Fri, 9 Apr 2010 02:19:18 +0000 (-0500) Subject: no strict and no warnings when 'no Moose' is called X-Git-Tag: 1.04~7 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2fee26f19eb97613d727e5b04ad9563639d7348b;p=gitmo%2FMoose.git no strict and no warnings when 'no Moose' is called --- diff --git a/Changes b/Changes index a40a91d..eff16cc 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,11 @@ for, noteworthy changes. * BUILDALL is now called by Moose::Meta::Class::new_object, rather than by Moose::Object::new. (doy) + [NEW FEATURES] + + * strict and warnings are now unimported when Moose, Moose::Role, or + Moose::Exporter are unimported. (doy, Adam Kennedy) + [BUG FIXES] * Fix has '+attr' in Roles to explode immediately, rather than when the role diff --git a/lib/Moose/Exporter.pm b/lib/Moose/Exporter.pm index fcd3e0d..bc13b20 100644 --- a/lib/Moose/Exporter.pm +++ b/lib/Moose/Exporter.pm @@ -475,6 +475,8 @@ sub _make_unimport_sub { $export_recorder, $is_reexport, ); + strict->unimport; + warnings->unimport; }; } @@ -567,6 +569,11 @@ sub import { warnings->import; } +sub unimport { + strict->unimport; + warnings->unimport; +} + 1; __END__ diff --git a/lib/Moose/Manual/Delta.pod b/lib/Moose/Manual/Delta.pod index 81e097a..28a7417 100644 --- a/lib/Moose/Manual/Delta.pod +++ b/lib/Moose/Manual/Delta.pod @@ -26,6 +26,12 @@ C. C methods are an inherent part of the object construction process, and this should make C<< $meta->new_object >> actually usable without forcing people to use C<< $meta->name->new >>. +=item C, C, and C now unimport strict and warnings + +In the interest of having C clean up everything that C +does in the calling scope, C (as well as all other +L-using modules) now unimports strict and warnings. + =back =head1 1.02 diff --git a/t/010_basics/007_always_strict_warnings.t b/t/010_basics/007_always_strict_warnings.t index a10d94a..454891e 100644 --- a/t/010_basics/007_always_strict_warnings.t +++ b/t/010_basics/007_always_strict_warnings.t @@ -22,6 +22,22 @@ use Test::More; ::ok($warn, '... got a warning'); ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning'); } + + no Moose; + undef $@; + eval '$foo = 5;'; + ::ok(!$@, "... no error after no Moose"); + + { + my $warn; + local $SIG{__WARN__} = sub { $warn = $_[0] }; + + ::ok(!$warn, '... no warning yet'); + + eval 'my $bar = 1 + "hello"'; + + ::ok(!$warn, '... still no warning'); + } } # and for roles ... @@ -44,6 +60,22 @@ use Test::More; ::ok($warn, '... got a warning'); ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning'); } + + no Moose::Role; + undef $@; + eval '$foo = 5;'; + ::ok(!$@, "... no error after no Moose::Role"); + + { + my $warn; + local $SIG{__WARN__} = sub { $warn = $_[0] }; + + ::ok(!$warn, '... no warning yet'); + + eval 'my $bar = 1 + "hello"'; + + ::ok(!$warn, '... still no warning'); + } } # and for exporters @@ -51,9 +83,9 @@ use Test::More; package Bar; use Moose::Exporter; - eval '$foo = 5;'; + eval '$foo2 = 5;'; ::ok($@, '... got an error because strict is on'); - ::like($@, qr/Global symbol \"\$foo\" requires explicit package name at/, '... got the right error'); + ::like($@, qr/Global symbol \"\$foo2\" requires explicit package name at/, '... got the right error'); { my $warn; @@ -66,6 +98,22 @@ use Test::More; ::ok($warn, '... got a warning'); ::like($warn, qr/Argument \"hello\" isn\'t numeric in addition \(\+\)/, '.. and it is the right warning'); } + + no Moose::Exporter; + undef $@; + eval '$foo = 5;'; + ::ok(!$@, "... no error after no Moose::Exporter"); + + { + my $warn; + local $SIG{__WARN__} = sub { $warn = $_[0] }; + + ::ok(!$warn, '... no warning yet'); + + eval 'my $bar = 1 + "hello"'; + + ::ok(!$warn, '... still no warning'); + } } done_testing; diff --git a/xt/author/pod_coverage.t b/xt/author/pod_coverage.t index acfdff6..7544c2c 100644 --- a/xt/author/pod_coverage.t +++ b/xt/author/pod_coverage.t @@ -14,6 +14,7 @@ my @modules = all_modules(); plan tests => scalar @modules; my %trustme = ( + 'Moose::Exporter' => ['unimport'], 'Moose::Meta::Attribute' => [ qw( interpolate_class throw_error