X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F023-builder.t;h=6b3e35e2ab54de57657d6246308680a76e1d7976;hb=8a3e5c5d45741e488e89d5130b5dcb44f2c6a6f4;hp=82aed53544a8d9d8d5413c88d5479b399e19283a;hpb=dbf02164f96991f659df05853d0f12d86a8aabdb;p=gitmo%2FMouse.git diff --git a/t/023-builder.t b/t/023-builder.t index 82aed53..6b3e35e 100644 --- a/t/023-builder.t +++ b/t/023-builder.t @@ -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"); +