6 eval "use Test::Output;";
7 plan skip_all => "Test::Output is required for this test" if $@;
10 # this test script ensures that my idiom of:
11 # role: sub BUILD, after BUILD
12 # continues to work to run code after object initialization, whether the class
13 # has a BUILD method or not
21 sub BUILD { push @CALLS, 'TestRole::BUILD' }
22 before BUILD => sub { push @CALLS, 'TestRole::BUILD:before' };
23 after BUILD => sub { push @CALLS, 'TestRole::BUILD:after' };
27 package ClassWithBUILD;
34 sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
38 package ExplicitClassWithBUILD;
42 with 'TestRole' => { excludes => 'BUILD' };
45 sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' }
49 package ClassWithoutBUILD;
55 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
59 is_deeply([splice @CALLS], [
60 'TestRole::BUILD:before',
61 'ClassWithBUILD::BUILD',
62 'TestRole::BUILD:after',
65 ClassWithoutBUILD->new;
67 is_deeply([splice @CALLS], [
68 'TestRole::BUILD:before',
70 'TestRole::BUILD:after',
73 if (ClassWithBUILD->meta->is_mutable) {
74 ClassWithBUILD->meta->make_immutable;
75 ClassWithoutBUILD->meta->make_immutable;