Changelogging
[gitmo/Mouse.git] / t / 030_roles / 019_build.t
CommitLineData
67199842 1#!/usr/bin/env perl
fde8e43f 2# This is automatically generated by author/import-moose-test.pl.
3# DO NOT EDIT THIS FILE. ANY CHANGES WILL BE LOST!!!
4use t::lib::MooseCompat;
67199842 5use strict;
6use warnings;
49a56bba 7use Test::More;
ad022aac 8
fde8e43f 9use Test::Requires {
10 'Test::Output' => '0.01', # skip all if not installed
11};
49a56bba 12
67199842 13# this test script ensures that my idiom of:
14# role: sub BUILD, after BUILD
15# continues to work to run code after object initialization, whether the class
16# has a BUILD method or not
17
18my @CALLS;
19
20do {
21 package TestRole;
22 use Mouse::Role;
23
24 sub BUILD { push @CALLS, 'TestRole::BUILD' }
25 before BUILD => sub { push @CALLS, 'TestRole::BUILD:before' };
26 after BUILD => sub { push @CALLS, 'TestRole::BUILD:after' };
27};
28
29do {
30 package ClassWithBUILD;
31 use Mouse;
6cfa1e5e 32
33 ::stderr_is {
34 with 'TestRole';
35 } '';
67199842 36
37 sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
38};
39
40do {
6cfa1e5e 41 package ExplicitClassWithBUILD;
67199842 42 use Mouse;
67199842 43
6cfa1e5e 44 ::stderr_is {
2bb76549 45 with 'TestRole' => { -excludes => 'BUILD' };
6cfa1e5e 46 } '';
67199842 47
6cfa1e5e 48 sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' }
49};
67199842 50
6cfa1e5e 51do {
52 package ClassWithoutBUILD;
53 use Mouse;
54 with 'TestRole';
55};
67199842 56
6cfa1e5e 57{
58 is_deeply([splice @CALLS], [], "no calls to BUILD yet");
67199842 59
6cfa1e5e 60 ClassWithBUILD->new;
67199842 61
6cfa1e5e 62 is_deeply([splice @CALLS], [
63 'TestRole::BUILD:before',
64 'ClassWithBUILD::BUILD',
65 'TestRole::BUILD:after',
66 ]);
67199842 67
6cfa1e5e 68 ClassWithoutBUILD->new;
67199842 69
6cfa1e5e 70 is_deeply([splice @CALLS], [
71 'TestRole::BUILD:before',
72 'TestRole::BUILD',
73 'TestRole::BUILD:after',
74 ]);
67199842 75
6cfa1e5e 76 if (ClassWithBUILD->meta->is_mutable) {
77 ClassWithBUILD->meta->make_immutable;
78 ClassWithoutBUILD->meta->make_immutable;
79 redo;
80 }
81}
67199842 82
fde8e43f 83done_testing;