Revert "Moose now warns about class implicitly overriding methods from local"
[gitmo/Moose.git] / t / 030_roles / 019_build.t
CommitLineData
39443466 1#!/usr/bin/env perl
2use strict;
3use warnings;
f6bee6fe 4use Test::More tests => 8;
e394f5e7 5use Test::Output;
39443466 6
7# this test script ensures that my idiom of:
8# role: sub BUILD, after BUILD
9# continues to work to run code after object initialization, whether the class
10# has a BUILD method or not
11
39443466 12my @CALLS;
13
14do {
15 package TestRole;
16 use Moose::Role;
17
18 sub BUILD { push @CALLS, 'TestRole::BUILD' }
19 before BUILD => sub { push @CALLS, 'TestRole::BUILD:before' };
20 after BUILD => sub { push @CALLS, 'TestRole::BUILD:after' };
21};
22
23do {
24 package ClassWithBUILD;
25 use Moose;
e394f5e7 26
f6bee6fe 27 ::stderr_is {
e394f5e7 28 with 'TestRole';
f6bee6fe 29 } '';
39443466 30
31 sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
32};
33
34do {
d443cad0 35 package ExplicitClassWithBUILD;
36 use Moose;
e394f5e7 37
38 ::stderr_is {
39 with 'TestRole' => { excludes => 'BUILD' };
40 } '';
d443cad0 41
42 sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' }
43};
44
45do {
39443466 46 package ClassWithoutBUILD;
47 use Moose;
48 with 'TestRole';
49};
50
27f4baaf 51{
52 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
53
54 ClassWithBUILD->new;
55
56 is_deeply([splice @CALLS], [
57 'TestRole::BUILD:before',
58 'ClassWithBUILD::BUILD',
59 'TestRole::BUILD:after',
60 ]);
61
62 ClassWithoutBUILD->new;
63
64 is_deeply([splice @CALLS], [
65 'TestRole::BUILD:before',
66 'TestRole::BUILD',
67 'TestRole::BUILD:after',
68 ]);
69
70 if (ClassWithBUILD->meta->is_mutable) {
71 ClassWithBUILD->meta->make_immutable;
72 ClassWithoutBUILD->meta->make_immutable;
73 redo;
74 }
75}
39443466 76