NAME

Test::Builder2::Singleton - A singleton role for TB2

SYNOPSIS

package TB2::Thing;

use Test::Builder2::Mouse;
with 'Test::Builder2::Singleton';

my $thing      = TB2::Thing->singleton;
my $same_thing = TB2::Thing->singleton;

my $new_thing  = TB2::Thing->create;

DESCRIPTION

FOR INTERNAL USE ONLY

A role implementing singleton for Test::Builder2 classes.

METHODS

Constructors

singleton

my $singleton = Class->singleton;
Class->singleton($singleton);

Gets/sets the singleton object.

If there is no singleton one will be created by calling create().

new

Because it is not clear if new() will make a new object or return a singleton (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-singleton object.

Currently calls Mouse's new method.