4 use Test::More tests => 7;
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
12 use_ok('Moose::Role');
21 sub BUILD { push @CALLS, 'TestRole::BUILD' }
22 before BUILD => sub { push @CALLS, 'TestRole::BUILD:before' };
23 after BUILD => sub { push @CALLS, 'TestRole::BUILD:after' };
27 package ClassWithBUILD;
31 sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
35 package ClassWithoutBUILD;
40 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
44 is_deeply([splice @CALLS], [
45 'TestRole::BUILD:before',
46 'ClassWithBUILD::BUILD',
47 'TestRole::BUILD:after',
50 ClassWithoutBUILD->new;
52 is_deeply([splice @CALLS], [
53 'TestRole::BUILD:before',
55 'TestRole::BUILD:after',
58 ClassWithBUILD->meta->make_immutable;
59 ClassWithoutBUILD->meta->make_immutable;
61 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
65 is_deeply([splice @CALLS], [
66 'TestRole::BUILD:before',
67 'ClassWithBUILD::BUILD',
68 'TestRole::BUILD:after',
71 ClassWithoutBUILD->new;
73 is_deeply([splice @CALLS], [
74 'TestRole::BUILD:before',
76 'TestRole::BUILD:after',