6 eval "use Test::Output;";
7 plan skip_all => "Test::Output is required for this test" if $@;
11 # this test script ensures that my idiom of:
12 # role: sub BUILD, after BUILD
13 # continues to work to run code after object initialization, whether the class
14 # has a BUILD method or not
22 sub BUILD { push @CALLS, 'TestRole::BUILD' }
23 before BUILD => sub { push @CALLS, 'TestRole::BUILD:before' };
24 after BUILD => sub { push @CALLS, 'TestRole::BUILD:after' };
28 package ClassWithBUILD;
35 sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
39 package ExplicitClassWithBUILD;
43 with 'TestRole' => { excludes => 'BUILD' };
46 sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' }
50 package ClassWithoutBUILD;
56 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
60 is_deeply([splice @CALLS], [
61 'TestRole::BUILD:before',
62 'ClassWithBUILD::BUILD',
63 'TestRole::BUILD:after',
66 ClassWithoutBUILD->new;
68 is_deeply([splice @CALLS], [
69 'TestRole::BUILD:before',
71 'TestRole::BUILD:after',
74 if (ClassWithBUILD->meta->is_mutable) {
75 ClassWithBUILD->meta->make_immutable;
76 ClassWithoutBUILD->meta->make_immutable;