Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'issue/244' into Test-Builder1.5

  • Loading branch information...
commit f44e86d8f64a8259f7bab81aafc824d33aa90dbd 2 parents 0af116d + c3f6ead
@schwern schwern authored
View
44 lib/TB2/EventCoordinator.pm
@@ -85,7 +85,10 @@ An array ref of Formatter objects which are listening to events.
This is a special case of C<handlers> provided so you can distinguish
between formatters and other handlers.
-Defaults to C<< [ TB2::Formatter::TAP->new ] >>.
+Defaults to C<< [ $class->default_formatters ] >>.
+
+The default can be altered by overriding L<default_formatter_class>
+and/or L<default_formatters>.
=cut
@@ -96,10 +99,7 @@ has formatters =>
isa => 'ArrayRef',
lazy => 1,
trigger => sub { $_[0]->shared_clone($_[1]) },
- default => sub {
- $_[0]->load("TB2::Formatter::TAP");
- return $_[0]->shared_clone( [ TB2::Formatter::TAP->new ] );
- };
+ builder => 'default_formatters';
=head3 early_handlers
@@ -169,6 +169,40 @@ For example, to create an EventCoordinator without a formatter...
=head2 Methods
+=head3 default_formatter_class
+
+ my $formatter_class = $class->default_formatter_class;
+
+Returns the L<TB2::Formatter> subclass to be used for formatting by
+default.
+
+Defaults to the TB2_FORMATTER_CLASS environment variable, if set,
+or TB2::Formatter::TAP if not.
+
+=cut
+
+sub default_formatter_class {
+ return $ENV{TB2_FORMATTER_CLASS} || "TB2::Formatter::TAP";
+}
+
+
+=head3 default_formatters
+
+ my $formatters = $class->default_formatters;
+
+Returns the list of L<formatters> to be used by default.
+
+Defaults to a single instance of the L<default_formatter_class>.
+
+=cut
+
+sub default_formatters {
+ my $formatter_class = $_[0]->default_formatter_class;
+ $_[0]->load( $formatter_class );
+ return $_[0]->shared_clone( [ $formatter_class->new ] );
+}
+
+
=head3 post_event
$ec->post_event($event);
View
28 t/Event/default_formatter_class.t
@@ -0,0 +1,28 @@
+#!/usr/bin/perl -w
+
+use strict;
+use warnings;
+
+BEGIN { require "t/test.pl" }
+
+my $CLASS = 'TB2::EventCoordinator';
+use_ok $CLASS;
+
+note "default for default_formatter_class"; {
+ local $ENV{TB2_FORMATTER_CLASS};
+
+ my $ec = $CLASS->new;
+ is $ec->default_formatter_class, "TB2::Formatter::TAP";
+}
+
+
+note "env override"; {
+ local $ENV{TB2_FORMATTER_CLASS} = "TB2::Formatter::Null";
+
+ my $ec = $CLASS->new;
+ is $ec->default_formatter_class, "TB2::Formatter::Null";
+ is @{$ec->formatters}, 1;
+ ok $ec->formatters->[0]->isa("TB2::Formatter::Null");
+}
+
+done_testing;
View
3  t/lib/MyEventCoordinator.pm
@@ -25,8 +25,7 @@ It makes the following changes:
=cut
-has '+formatters' =>
- default => sub { [] };
+sub default_formatters { [] }
no TB2::Mouse;
Please sign in to comment.
Something went wrong with that request. Please try again.