From: Shawn M Moore Date: Mon, 22 Dec 2008 02:23:01 +0000 (+0000) Subject: Test that we don't export sugar into main X-Git-Tag: 0.19~100 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7daedfff24bc2061ea1028f415b2e914bd8f1639;p=gitmo%2FMouse.git Test that we don't export sugar into main --- diff --git a/Changes b/Changes index bc53675..d4ca835 100644 --- a/Changes +++ b/Changes @@ -1,7 +1,7 @@ Revision history for Mouse 0.15 - + * Don't export Mouse's sugar into the package 'main' 0.14 Sat Dec 20 16:53:05 2008 * POD fix diff --git a/lib/Mouse.pm b/lib/Mouse.pm index 0606dcb..97914a6 100644 --- a/lib/Mouse.pm +++ b/lib/Mouse.pm @@ -85,6 +85,12 @@ sub import { my $caller = caller; + # we should never export to main + if ($caller eq 'main') { + warn qq{$class does not export its sugar to the 'main' package.\n}; + return; + } + my $meta = Mouse::Meta::Class->initialize($caller); $meta->superclasses('Mouse::Object') unless $meta->superclasses; diff --git a/lib/Mouse/Role.pm b/lib/Mouse/Role.pm index e607760..e905004 100644 --- a/lib/Mouse/Role.pm +++ b/lib/Mouse/Role.pm @@ -67,10 +67,19 @@ sub requires { sub excludes { confess "Mouse::Role does not currently support 'excludes'" } sub import { + my $class = shift; + strict->import; warnings->import; my $caller = caller; + + # we should never export to main + if ($caller eq 'main') { + warn qq{$class does not export its sugar to the 'main' package.\n}; + return; + } + my $meta = Mouse::Meta::Role->initialize(caller); no strict 'refs'; diff --git a/t/037-dont-load-test-exception.t b/t/037-dont-load-test-exception.t index e1b4bea..94a4ccd 100644 --- a/t/037-dont-load-test-exception.t +++ b/t/037-dont-load-test-exception.t @@ -1,3 +1,4 @@ +package Foo; use strict; use warnings; use Test::More tests => 1; diff --git a/t/038-main.t b/t/038-main.t new file mode 100644 index 0000000..6f68a4f --- /dev/null +++ b/t/038-main.t @@ -0,0 +1,23 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +BEGIN { + eval "use Test::Output;"; + plan skip_all => "Test::Output is required for this test" if $@; + plan tests => 2; +} + +stderr_is( + sub { package main; eval 'use Mouse' }, + "Mouse does not export its sugar to the 'main' package.\n", + 'Mouse warns when loaded from the main package', +); + +stderr_is( + sub { package main; eval 'use Mouse::Role' }, + "Mouse::Role does not export its sugar to the 'main' package.\n", + 'Mouse::Role warns when loaded from the main package', +); +