Test::Builder2::Singleton - A singleton role for TB2
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;
FOR INTERNAL USE ONLY
A role implementing singleton for Test::Builder2 classes.
Strictly speaking, this isn't a singleton because you can create more instances. Its more like giving the class a default.
my $singleton = Class->singleton; Class->singleton($singleton);
Gets/sets the singleton object.
If there is no singleton one will be created by calling create().
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.
my $obj = Class->create(@args);
Creates a new, non-singleton object.
Currently calls Mouse's new method.
my $singleton = $class->make_singleton;
Creates the object used as the singleton.
Defaults to calling $class->create. You can override.
$class->create
One of the reasons to override is to ensure your singleton contains other singletons. Like a Builder will want to use the singleton History and Formatter objects.
To install Test::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Simple
CPAN shell
perl -MCPAN -e shell install Test::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.