Moose now warns when you try to load it from the main package. Added a
[gitmo/Moose.git] / t / 010_basics / 009_import_unimport.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 46;
7
8
9
10 my @moose_exports = qw(
11     extends with 
12     has 
13     before after around
14     override
15     augment
16     super inner
17     make_immutable
18 );
19
20 {
21     package Foo;
22 }
23
24 eval q{
25     package Foo;
26     use Moose;
27 };
28 ok(!$@, '... Moose succesfully exported into Foo');
29
30 can_ok('Foo', $_) for @moose_exports;
31
32 eval q{
33     package Foo;
34     no Moose;
35 };
36 ok(!$@, '... Moose succesfully un-exported from Foo');
37
38 ok(!Foo->can($_), '... Foo can no longer do ' . $_) for @moose_exports;
39
40 # and check the type constraints as well
41
42 my @moose_type_constraint_exports = qw(
43     type subtype as where message 
44     coerce from via 
45     enum
46     find_type_constraint
47 );
48
49 {
50     package Bar;
51 }
52
53 eval q{
54     package Bar;
55     use Moose::Util::TypeConstraints;
56 };
57 ok(!$@, '... Moose::Util::TypeConstraints succesfully exported into Bar');
58
59 can_ok('Bar', $_) for @moose_type_constraint_exports;
60
61 eval q{
62     package Bar;
63     no Moose::Util::TypeConstraints;
64 };
65 ok(!$@, '... Moose::Util::TypeConstraints succesfully un-exported from Bar');
66
67 ok(!Bar->can($_), '... Bar can no longer do ' . $_) for @moose_type_constraint_exports;
68