sub instance { shift->new }
+sub initialize {
+ my ($class, @args) = @_;
+
+ my $existing = $class->meta->existing_singleton;
+ confess "Singleton is already initialized" if $existing;
+
+ return $class->SUPER::new(@args);
+}
+
sub new {
my ($class, @args) = @_;
use strict;
use warnings;
-use Test::More tests => 8;
+use Test::More tests => 9;
my $i = 0;
sub new_singleton_pkg {
);
eval { $pkg->new(number => 3) };
- ok($@, "can't make new singleton with conflicting attributes");
+ like($@, qr/already/, "can't make new singleton with conflicting attributes");
my $second = eval { $pkg->new };
ok(!$@, "...but a second ->new without args is okay");
is($second->number, 5, "...we get the originally inited number from it");
+
+ eval { $pkg->initialize };
+ like($@, qr/already/, "...but ->initialize() is still an error");
}