summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2010-05-07 05:46:25 -0500
committerJesse Luehrs <doy@tozt.net>2010-05-07 05:46:25 -0500
commit284e13a66b70c0281290be84d88e382d516f739b (patch)
tree3d172d298a3c5941dd9974d6c0fcdfc2c78828d9
parente0b21df6d7872b520dd4694c07608f99813ba9bd (diff)
downloadmoosex-attribute-shorthand-284e13a66b70c0281290be84d88e382d516f739b.tar.gz
moosex-attribute-shorthand-284e13a66b70c0281290be84d88e382d516f739b.zip
expand test a bit
-rw-r--r--t/001-basic.t51
1 files changed, 51 insertions, 0 deletions
diff --git a/t/001-basic.t b/t/001-basic.t
index f3445a4..139e33c 100644
--- a/t/001-basic.t
+++ b/t/001-basic.t
@@ -21,4 +21,55 @@ my $foo = Foo->new;
is($foo->foo, 'FOO', "expanded properly");
dies_ok { $foo->foo('sldkfj') } "expanded properly";
+{
+ package Bar;
+ use Moose;
+ use MooseX::Attribute::Shorthand my_lazy_build => {
+ lazy => 1,
+ builder => sub { "_build_$_[0]" },
+ predicate => sub {
+ my $name = shift;
+ my $private = $name =~ s/^_//;
+ $private ? "_has_$name" : "has_$name";
+ },
+ clearer => sub {
+ my $name = shift;
+ my $private = $name =~ s/^_//;
+ $private ? "_clear_$name" : "clear_$name";
+ },
+ };
+
+ has public => (
+ is => 'ro',
+ isa => 'Str',
+ my_lazy_build => 1,
+ );
+
+ sub _build_public { 'PUBLIC' }
+
+ has _private => (
+ is => 'ro',
+ isa => 'Str',
+ my_lazy_build => 1,
+ );
+
+ sub _build__private { 'PRIVATE' }
+}
+
+my $bar = Bar->new;
+can_ok($bar, $_) for qw(has_public clear_public _has_private _clear_private);
+ok(!$bar->can($_), "Bar can't $_") for qw(has__private clear__private);
+
+ok(!$bar->has_public, "doesn't have a value yet");
+is($bar->public, 'PUBLIC', "gets a lazy value");
+ok($bar->has_public, "has a value now");
+$bar->clear_public;
+ok(!$bar->has_public, "doesn't have a value again");
+
+ok(!$bar->_has_private, "doesn't have a value yet");
+is($bar->_private, 'PRIVATE', "gets a lazy value");
+ok($bar->_has_private, "has a value now");
+$bar->_clear_private;
+ok(!$bar->_has_private, "doesn't have a value again");
+
done_testing;