4 use Test::More tests => 8;
6 # this test script ensures that my idiom of:
7 # role: sub BUILD, after BUILD
8 # continues to work to run code after object initialization, whether the class
9 # has a BUILD method or not
17 sub BUILD { push @CALLS, 'TestRole::BUILD' }
18 before BUILD => sub { push @CALLS, 'TestRole::BUILD:before' };
19 after BUILD => sub { push @CALLS, 'TestRole::BUILD:after' };
23 package ClassWithBUILD;
27 sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
31 package ExplicitClassWithBUILD;
33 with 'TestRole' => { excludes => 'BUILD' };
35 sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' }
39 package ClassWithoutBUILD;
45 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
49 is_deeply([splice @CALLS], [
50 'TestRole::BUILD:before',
51 'ClassWithBUILD::BUILD',
52 'TestRole::BUILD:after',
55 ExplicitClassWithBUILD->new;
57 is_deeply([splice @CALLS], [
58 'TestRole::BUILD:before',
59 'ExplicitClassWithBUILD::BUILD',
60 'TestRole::BUILD:after',
63 ClassWithoutBUILD->new;
65 is_deeply([splice @CALLS], [
66 'TestRole::BUILD:before',
68 'TestRole::BUILD:after',
71 if (ClassWithBUILD->meta->is_mutable) {
72 ClassWithBUILD->meta->make_immutable;
73 ExplicitClassWithBUILD->meta->make_immutable;
74 ClassWithoutBUILD->meta->make_immutable;