#!/usr/bin/env perl
use strict;
use warnings;
-use Test::More tests => 6;
+use Test::More;
+
+use Test::Requires {
+ 'Test::Output' => '0.01', # skip all if not installed
+};
# this test script ensures that my idiom of:
# role: sub BUILD, after BUILD
do {
package ClassWithBUILD;
use Moose;
- with 'TestRole';
+
+ ::stderr_is {
+ with 'TestRole';
+ } '';
sub BUILD { push @CALLS, 'ClassWithBUILD::BUILD' }
};
do {
- package ClassWithoutBUILD;
+ package ExplicitClassWithBUILD;
use Moose;
- with 'TestRole';
-};
-
-is_deeply([splice @CALLS], [], "no calls to BUILD yet");
-ClassWithBUILD->new;
+ ::stderr_is {
+ with 'TestRole' => { -excludes => 'BUILD' };
+ } '';
-is_deeply([splice @CALLS], [
- 'TestRole::BUILD:before',
- 'ClassWithBUILD::BUILD',
- 'TestRole::BUILD:after',
-]);
-
-ClassWithoutBUILD->new;
+ sub BUILD { push @CALLS, 'ExplicitClassWithBUILD::BUILD' }
+};
-is_deeply([splice @CALLS], [
- 'TestRole::BUILD:before',
- 'TestRole::BUILD',
- 'TestRole::BUILD:after',
-]);
+do {
+ package ClassWithoutBUILD;
+ use Moose;
+ with 'TestRole';
+};
-ClassWithBUILD->meta->make_immutable;
-ClassWithoutBUILD->meta->make_immutable;
+{
+ is_deeply([splice @CALLS], [], "no calls to BUILD yet");
-is_deeply([splice @CALLS], [], "no calls to BUILD yet");
+ ClassWithBUILD->new;
-ClassWithBUILD->new;
+ is_deeply([splice @CALLS], [
+ 'TestRole::BUILD:before',
+ 'ClassWithBUILD::BUILD',
+ 'TestRole::BUILD:after',
+ ]);
-is_deeply([splice @CALLS], [
- 'TestRole::BUILD:before',
- 'ClassWithBUILD::BUILD',
- 'TestRole::BUILD:after',
-]);
+ ClassWithoutBUILD->new;
-ClassWithoutBUILD->new;
+ is_deeply([splice @CALLS], [
+ 'TestRole::BUILD:before',
+ 'TestRole::BUILD',
+ 'TestRole::BUILD:after',
+ ]);
-is_deeply([splice @CALLS], [
- 'TestRole::BUILD:before',
- 'TestRole::BUILD',
- 'TestRole::BUILD:after',
-]);
+ if (ClassWithBUILD->meta->is_mutable) {
+ ClassWithBUILD->meta->make_immutable;
+ ClassWithoutBUILD->meta->make_immutable;
+ redo;
+ }
+}
+done_testing;