Tweaks and documenting Mouse::Exporter
[gitmo/Mouse.git] / t / 023-builder.t
index 82aed53..6b3e35e 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env perl
 use strict;
 use warnings;
-use Test::More tests => 37;
+use Test::More tests => 47;
 use Test::Exception;
 
 my $builder_called = 0;
@@ -106,7 +106,7 @@ do {
             lazy_build => 1,
             default => 1,
         );
-    } qr/You can not use lazy_build and default for the same attribute error/;
+    } qr/You can not use lazy_build and default for the same attribute \(error\)/;
 };
 
 my @calls;
@@ -117,7 +117,9 @@ do {
     has custom => (
         is => 'ro',
         lazy_build => 1,
-        builder => 'build_my_customs',
+        builder    => 'build_my_customs',
+        predicate  => 'has_my_customs',
+        clearer    => 'clear_my_customs',
     );
 
     sub build_my_customs {
@@ -126,7 +128,34 @@ do {
     }
 };
 
-
 my $cb = Class::CustomBuilder->new;
+ok(!$cb->has_my_customs, "correct predicate");
 is($cb->custom, 'yo');
-is_deeply(\@calls, ['build_my_customs']);
+is_deeply([splice @calls], ['build_my_customs']);
+ok($cb->has_my_customs, "correct predicate");
+ok($cb->clear_my_customs, "correct clearer");
+ok(!$cb->has_my_customs, "correct predicate");
+
+do {
+    package Class::UnderscoreBuilder;
+    use Mouse;
+
+    has _attr => (
+        is => 'ro',
+        lazy_build => 1,
+    );
+
+    sub _build__attr {
+        push @calls, '_build__attr';
+        return 'ping';
+    }
+};
+
+my $cub = Class::UnderscoreBuilder->new;
+ok(!$cub->_has_attr, "correct predicate");
+is($cub->_attr, 'ping');
+is_deeply([splice @calls], ['_build__attr']);
+ok($cub->_has_attr, "correct predicate");
+ok($cub->_clear_attr, "correct clearer");
+ok(!$cub->_has_attr, "correct predicate");
+