From c388fb9ba415d6543cff51aa35677f092cc0be93 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Wed, 30 Jun 2010 00:25:20 -0500 Subject: basic implementation --- t/01-basic.t | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 t/01-basic.t (limited to 't') diff --git a/t/01-basic.t b/t/01-basic.t new file mode 100644 index 0000000..2d75e59 --- /dev/null +++ b/t/01-basic.t @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +use strict; +use warnings; +use Test::More; + +use Scalar::Util qw(reftype); + +{ + package Foo; + use Moose; + use MooseX::ArrayRef; + + has foo => (is => 'rw'); + has bar => (is => 'ro', lazy_build => 1); + sub _build_bar { 'BAR' } +} + +my $foo = Foo->new; +is(reftype($foo), 'ARRAY', "got an array instance"); +isa_ok($foo, 'Foo'); +ok(!$foo->has_bar, "bar not initialized yet"); +is($foo->bar, 'BAR', "lazy-built properly"); +ok($foo->has_bar, "bar initialized now"); +is($foo->foo, undef, "foo not initialized yet"); +$foo->foo('FOO'); +is($foo->foo, 'FOO', "foo initialized now"); +my @contents = @$foo; +is_deeply(\@$foo, ['FOO', 'BAR'], "got the right instance data"); + +{ + package Bar; + use Moose; + extends 'Foo'; + + has baz => (is => 'rw'); +} + +my $bar = Bar->new; +is(reftype($bar), 'ARRAY', "got an array instance"); +isa_ok($bar, 'Bar'); +isa_ok($bar, 'Foo'); +ok(!$bar->has_bar, "bar not initialized yet"); +is($bar->bar, 'BAR', "lazy-built properly"); +ok($bar->has_bar, "bar initialized now"); +is($bar->foo, undef, "foo not initialized yet"); +$bar->foo('FOO'); +is($bar->foo, 'FOO', "foo initialized now"); +is($bar->baz, undef, "baz not initialized yet"); +$bar->baz('BAZ'); +is($bar->baz, 'BAZ', "baz initialized now"); +is_deeply(\@$bar, ['FOO', 'BAR', 'BAZ'], "got the right instance data"); + +done_testing; -- cgit v1.2.3-54-g00ecf