Make $role->get_method_list() include meta() (Moose 0.90 feature)
[gitmo/Mouse.git] / t / 030_roles / 019_build.t
1 #!/usr/bin/env perl
2 use strict;
3 use warnings;
4 use Test::More;
5 BEGIN {
6     plan skip_all => 
7             "This test requires Class::Method::Modifiers or Class::Method::Modifiers::Fast" 
8         unless eval { 
9             require Class::Method::Modifiers::Fast;
10         } or   eval {
11             require Class::Method::Modifiers;
12         };
13 }
14
15 plan tests => 6;
16
17
18 # this test script ensures that my idiom of:
19 # role: sub BUILD, after BUILD
20 # continues to work to run code after object initialization, whether the class
21 # has a BUILD method or not
22
23 my @CALLS;
24
25 do {
26     package TestRole;
27     use Mouse::Role;
28
29     sub BUILD           { push @CALLS, 'TestRole::BUILD' }
30     before BUILD => sub { push @CALLS, 'TestRole::BUILD:before' };
31     after  BUILD => sub { push @CALLS, 'TestRole::BUILD:after' };
32 };
33
34 do {
35     package ClassWithBUILD;
36     use Mouse;
37     with 'TestRole';
38
39     sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
40 };
41
42 do {
43     package ClassWithoutBUILD;
44     use Mouse;
45     with 'TestRole';
46 };
47
48 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
49
50 ClassWithBUILD->new;
51
52 is_deeply([splice @CALLS], [
53     'TestRole::BUILD:before',
54     'ClassWithBUILD::BUILD',
55     'TestRole::BUILD:after',
56 ]);
57
58 ClassWithoutBUILD->new;
59
60 is_deeply([splice @CALLS], [
61     'TestRole::BUILD:before',
62     'TestRole::BUILD',
63     'TestRole::BUILD:after',
64 ]);
65
66 ClassWithBUILD->meta->make_immutable;
67 ClassWithoutBUILD->meta->make_immutable;
68
69 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
70
71 ClassWithBUILD->new;
72
73 is_deeply([splice @CALLS], [
74     'TestRole::BUILD:before',
75     'ClassWithBUILD::BUILD',
76     'TestRole::BUILD:after',
77 ]);
78
79 ClassWithoutBUILD->new;
80
81 is_deeply([splice @CALLS], [
82     'TestRole::BUILD:before',
83     'TestRole::BUILD',
84     'TestRole::BUILD:after',
85 ]);
86