4 use Test::More tests => 10;
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;
29 } qr/The ClassWithBUILD class has implicitly overridden the method \(BUILD\) from role TestRole\./;
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 ExplicitClassWithBUILD->new;
64 is_deeply([splice @CALLS], [
65 'TestRole::BUILD:before',
66 'ExplicitClassWithBUILD::BUILD',
67 'TestRole::BUILD:after',
70 ClassWithoutBUILD->new;
72 is_deeply([splice @CALLS], [
73 'TestRole::BUILD:before',
75 'TestRole::BUILD:after',
78 if (ClassWithBUILD->meta->is_mutable) {
79 ClassWithBUILD->meta->make_immutable;
80 ExplicitClassWithBUILD->meta->make_immutable;
81 ClassWithoutBUILD->meta->make_immutable;