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
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;
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';
+package Foo;
use strict;
use warnings;
use Test::More tests => 1;
--- /dev/null
+#!/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',
+);
+