add xt test for Moose + namespace::autoclean
Sawyer X [Fri, 20 Jul 2012 16:12:40 +0000 (19:12 +0300)]
xt/moose-autoclean-lazy-attr-builders.t [new file with mode: 0644]

diff --git a/xt/moose-autoclean-lazy-attr-builders.t b/xt/moose-autoclean-lazy-attr-builders.t
new file mode 100644 (file)
index 0000000..7b3eb5c
--- /dev/null
@@ -0,0 +1,31 @@
+use strict;
+use warnings;
+# when using an Moose object and namespace::autoclean
+# lazy attributes that get a value on initialize still
+# have their builders run
+
+{
+    package MyMooseObject;
+    use Moose;
+}
+
+{
+    package BadObject;
+    use Moo;
+    # use MyMooseObject <- this is inferred here
+    use namespace::autoclean;
+
+    has attr => ( is => 'lazy' );
+    sub _build_attr {2}
+}
+
+use Test::More;
+# use BadObject <- this is inferred here
+
+is(
+    BadObject->new( attr => 1 )->attr,
+    1,
+    q{namespace::autoclean doesn't run builders with default},
+);
+
+done_testing;