Skip distro which requires rpm
[gitmo/Moose.git] / t / metaclasses / goto_moose_import.t
CommitLineData
e16d86b9 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
a28e50e4 6use Test::More;
b10dde3a 7use Test::Fatal;
e16d86b9 8
9# Some packages out in the wild cooperate with Moose by using goto
10# &Moose::import. we want to make sure it still works.
11
12{
13 package MooseAlike1;
14
15 use strict;
16 use warnings;
17
18 use Moose ();
19
20 sub import {
21 goto &Moose::import;
22 }
12fd2648 23
24 sub unimport {
25 goto &Moose::unimport;
26 }
e16d86b9 27}
28
29{
30 package Foo;
31
32 MooseAlike1->import();
33
b10dde3a 34 ::is( ::exception { has( 'size', is => 'bare' ) }, undef, 'has was exported via MooseAlike1' );
12fd2648 35
36 MooseAlike1->unimport();
e16d86b9 37}
38
12fd2648 39ok( ! Foo->can('has'),
40 'No has sub in Foo after MooseAlike1 is unimported' );
41ok( Foo->can('meta'),
42 'Foo has a meta method' );
43isa_ok( Foo->meta(), 'Moose::Meta::Class' );
44
45
e16d86b9 46{
47 package MooseAlike2;
48
49 use strict;
50 use warnings;
51
52 use Moose ();
53
54 my $import = \&Moose::import;
55 sub import {
56 goto $import;
57 }
12fd2648 58
59 my $unimport = \&Moose::unimport;
60 sub unimport {
61 goto $unimport;
62 }
e16d86b9 63}
64
65{
66 package Bar;
67
68 MooseAlike2->import();
69
b10dde3a 70 ::is( ::exception { has( 'size', is => 'bare' ) }, undef, 'has was exported via MooseAlike2' );
e16d86b9 71
12fd2648 72 MooseAlike2->unimport();
73}
e16d86b9 74
75
12fd2648 76ok( ! Bar->can('has'),
77 'No has sub in Bar after MooseAlike2 is unimported' );
78ok( Bar->can('meta'),
79 'Bar has a meta method' );
80isa_ok( Bar->meta(), 'Moose::Meta::Class' );
a28e50e4 81
82done_testing;