--- /dev/null
+#!/usr/bin/env perl
+
+use Module::Build;
+
+use strict;
+use warnings;
+
+Module::Build->new (
+ module_name => 'MooseX::Singleton',
+ license => 'perl',
+ requires => {
+ 'Moose' => '0.20',
+ },
+ build_requires => {
+ 'Test::More' => '0.70',
+ 'Test::Exception' => '0.25',
+ },
+)->create_build_script;
+
--- /dev/null
+package MooseX::Singleton;
+
+use Moose::Role;
+
+our $VERSION = 0.01;
+
+override new => sub {
+ my ($class) = @_;
+
+ no strict qw/refs/;
+
+ my $instance = super;
+
+ ${"$class\::singleton"} = $instance;
+
+ return $instance;
+};
+
+sub instance {
+ my ($class) = @_;
+
+ no strict qw/refs/;
+
+ return ${"$class\::singleton"};
+}
+
+1;
+
--- /dev/null
+use Test::More tests => 2;
+
+use strict;
+use warnings;
+
+{
+ package Foo::Singleton;
+
+ use Moose;
+
+ has gravy => (is => 'rw');
+
+ with qw/MooseX::Singleton/;
+}
+
+ok (Foo::Singleton->new,'new');
+
+my $foo = Foo::Singleton->instance;
+
+my $bar = Foo::Singleton->instance;
+
+$foo->gravy ('sauce');
+
+is ($bar->gravy,'sauce','singleton');
+