NAME
TB2::HasDefault - A role providing a shared default object
SYNOPSIS
package TB2::Thing;
use TB2::Mouse;
with 'TB2::HasDefault';
my $thing = TB2::Thing->default;
my $same_thing = TB2::Thing->default;
my $new_thing = TB2::Thing->create;
DESCRIPTION
FOR INTERNAL USE ONLY
A role implementing default for Test::Builder2 classes.
Strictly speaking, this isn't a default because you can create more instances. Its more like giving the class a default.
METHODS
Constructors
default
my $default = Class->default;
Class->default($default);
Gets/sets the default object.
If there is no default one will be created by calling create().
new
Because it is not clear if new() will make a new object or return a default (like Test::Builder does) new() will simply croak to force the user to make the decision.
create
my $obj = Class->create(@args);
Creates a new, non-default object.
Currently calls Mouse's new method.
make_default
my $default = $class->make_default;
Creates the object used as the default.
Defaults to calling $class->create
. You can override.
One of the reasons to override is to ensure your default contains other defaults. Like a Builder will want to use the default History and Formatter objects.