6 eval "use Test::Output;";
7 plan skip_all => "Test::Output is required for this test" if $@;
12 # this test script ensures that my idiom of:
13 # role: sub BUILD, after BUILD
14 # continues to work to run code after object initialization, whether the class
15 # has a BUILD method or not
23 sub BUILD { push @CALLS, 'TestRole::BUILD' }
24 before BUILD => sub { push @CALLS, 'TestRole::BUILD:before' };
25 after BUILD => sub { push @CALLS, 'TestRole::BUILD:after' };
29 package ClassWithBUILD;
36 sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
40 package ExplicitClassWithBUILD;
44 with 'TestRole' => { excludes => 'BUILD' };
47 sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' }
51 package ClassWithoutBUILD;
57 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
61 is_deeply([splice @CALLS], [
62 'TestRole::BUILD:before',
63 'ClassWithBUILD::BUILD',
64 'TestRole::BUILD:after',
67 ClassWithoutBUILD->new;
69 is_deeply([splice @CALLS], [
70 'TestRole::BUILD:before',
72 'TestRole::BUILD:after',
75 if (ClassWithBUILD->meta->is_mutable) {
76 ClassWithBUILD->meta->make_immutable;
77 ClassWithoutBUILD->meta->make_immutable;