4 use Test::More tests => 8;
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
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' };
24 package ClassWithBUILD;
31 sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
35 package ExplicitClassWithBUILD;
39 with 'TestRole' => { excludes => 'BUILD' };
42 sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' }
46 package ClassWithoutBUILD;
52 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
56 is_deeply([splice @CALLS], [
57 'TestRole::BUILD:before',
58 'ClassWithBUILD::BUILD',
59 'TestRole::BUILD:after',
62 ClassWithoutBUILD->new;
64 is_deeply([splice @CALLS], [
65 'TestRole::BUILD:before',
67 'TestRole::BUILD:after',
70 if (ClassWithBUILD->meta->is_mutable) {
71 ClassWithBUILD->meta->make_immutable;
72 ClassWithoutBUILD->meta->make_immutable;