File: 014_immutable_metaclass_with_traits.t

package info (click to toggle)
libmoose-perl 1.09-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 3,004 kB
  • ctags: 1,472
  • sloc: perl: 25,387; makefile: 2
file content (37 lines) | stat: -rw-r--r-- 1,246 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#!/usr/bin/env perl
use strict;
use warnings;
use Test::More;

{
    package FooTrait;
    use Moose::Role;
}
{
    package Foo;
    use Moose -traits => ['FooTrait'];
}

is(Class::MOP::class_of('Foo'), Foo->meta,
    "class_of and ->meta are the same on Foo");
my $meta = Foo->meta;
is(Class::MOP::class_of($meta), $meta->meta,
    "class_of and ->meta are the same on Foo's metaclass");
isa_ok(Class::MOP::class_of($meta), 'Moose::Meta::Class');
isa_ok($meta->meta, 'Moose::Meta::Class');
ok($meta->is_mutable, "class is mutable");
ok(Class::MOP::class_of($meta)->is_mutable, "metaclass is mutable");
ok($meta->meta->does_role('FooTrait'), "does the trait");
Foo->meta->make_immutable;
is(Class::MOP::class_of('Foo'), Foo->meta,
    "class_of and ->meta are the same on Foo (immutable)");
$meta = Foo->meta;
isa_ok($meta->meta, 'Moose::Meta::Class');
ok($meta->is_immutable, "class is immutable");
ok($meta->meta->is_immutable, "metaclass is immutable (immutable class)");
is(Class::MOP::class_of($meta), $meta->meta,
    "class_of and ->meta are the same on Foo's metaclass (immutable)");
isa_ok(Class::MOP::class_of($meta), 'Moose::Meta::Class');
ok($meta->meta->does_role('FooTrait'), "still does the trait after immutable");

done_testing;