Revision history for Perl extension MooseX-Singleton
+0.17
+ - Add ClassName->_clear_instance. (hdp)
+
0.16 2009-04-24
- Changes to keep constructor inlining working with latest Moose &
Class::MOP. This module will still work with any Moose from 0.74
C<use MooseX::Singleton>. This module uses a new class metaclass and instance
metaclass, so if you're doing metamagic you may not be able to use this.
-C<MooseX::Singleton> gives your class an C<instance> method that can be used to get a handle on the singleton. It's actually just an alias for C<new>.
+C<MooseX::Singleton> gives your class an C<instance> method that can be used to
+get a handle on the singleton. It's actually just an alias for C<new>.
Alternatively, C<< YourPackage->method >> should just work. This includes
accessors.
+If you need to reset your class's singleton object for some reason (e.g.
+tests), you can call C<< YourPackage->_clear_instance >>.
+
=head1 TODO
=over
return;
}
+sub clear_singleton {
+ my ($class) = @_;
+ my $pkg = $class->name;
+ no strict 'refs';
+ undef ${"$pkg\::singleton"};
+}
+
override _construct_instance => sub {
my ($class) = @_;
return $class->SUPER::new(@args);
}
+sub _clear_instance {
+ my ($class) = @_;
+ $class->meta->clear_singleton;
+}
+
no Moose;
1;
use strict;
use warnings;
-use Test::More tests => 16;
+use Test::More tests => 17;
BEGIN {
package MooseX::Singleton::Test;
is($mst2->distinct_keys, 0, "Package->clear works");
is(MooseX::Singleton::Test->distinct_keys, 0, "Package->clear works");
+MooseX::Singleton::Test->_clear_instance;
+$mst = $mst2 = undef;
+is(MooseX::Singleton::Test->new->distinct_keys, 1, "back to the default");