4 use Test::More tests => 6;
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 ClassWithoutBUILD;
36 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
40 is_deeply([splice @CALLS], [
41 'TestRole::BUILD:before',
42 'ClassWithBUILD::BUILD',
43 'TestRole::BUILD:after',
46 ClassWithoutBUILD->new;
48 is_deeply([splice @CALLS], [
49 'TestRole::BUILD:before',
51 'TestRole::BUILD:after',
54 ClassWithBUILD->meta->make_immutable;
55 ClassWithoutBUILD->meta->make_immutable;
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',