Require Dist::Zilla 4.200016+
[gitmo/Moose.git] / t / metaclasses / metarole_on_anon.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5
6 use Moose ();
7 use Moose::Meta::Class;
8 use Moose::Util::MetaRole;
9
10 {
11     package Foo;
12     use Moose;
13 }
14
15 {
16     package Role::Bar;
17     use Moose::Role;
18 }
19
20 my $anon_name;
21
22 {
23     my $anon_class = Moose::Meta::Class->create_anon_class(
24         superclasses => ['Foo'],
25         cache        => 1,
26     );
27
28     $anon_name = $anon_class->name;
29
30     ok( $anon_name->meta, 'anon class has a metaclass' );
31 }
32
33 ok(
34     $anon_name->meta,
35     'cached anon class still has a metaclass after \$anon_class goes out of scope'
36 );
37
38 Moose::Util::MetaRole::apply_metaroles(
39     for             => $anon_name,
40     class_metaroles => {
41         class => ['Role::Bar'],
42     },
43 );
44
45 BAIL_OUT('Cannot continue if the anon class does not have a metaclass')
46     unless $anon_name->can('meta');
47
48 my $meta = $anon_name->meta;
49 ok( $meta, 'cached anon class still has a metaclass applying a metarole' );
50
51 done_testing;