Add tests and fix for implicit object construction skipping BUILD &
[gitmo/MooseX-Singleton.git] / t / 005-build_bug-immutable.t
diff --git a/t/005-build_bug-immutable.t b/t/005-build_bug-immutable.t
new file mode 100644 (file)
index 0000000..4b6c1d3
--- /dev/null
@@ -0,0 +1,38 @@
+use strict;
+use warnings;
+
+use Test::More 'no_plan';
+
+{
+    package MySingleton;
+    use MooseX::Singleton;
+
+    has 'attrib' =>
+        is      => 'rw',
+        isa     => 'Str',
+        default => 'foo';
+
+    sub hello {'world'}
+
+    sub BUILDARGS {
+        my ( $class, %opts ) = @_;
+
+        { attrib => 'bar', %opts };
+    }
+
+    __PACKAGE__->meta->make_immutable;
+}
+
+is(
+    MySingleton->attrib, 'bar',
+    'BUILDARGS changed value of attrib when instance was auto-instantiated'
+);
+
+MySingleton->meta->remove_package_glob('singleton');
+
+MySingleton->instance;
+
+is(
+    MySingleton->attrib, 'bar',
+    'BUILDARGS changed value of attrib when instance was explicitly instantiated'
+);