#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use Test::More ( tests => 3, # Be gentle because Test::More::is # will conflict with our &is import => [ 'use_ok', 'is_deeply', 'diag' ] ); BEGIN { use_ok('Moose::Declare'); } { my @objects = moose { class Point => authority is 'cpan://JRANDOM', version is '0.0.1'; has x => is rw, isa Int, default is 0; has y => is rw, isa Int, default is 0; class Point3D => authority is 'cpan://JRANDOM', version is '0.0.1', subclass of 'Point'; has z => is readonly, isa Int, default is 0; }; #diag(Dumper(\@objects)); is_deeply( \@objects, [ 'Point', [ 'class', [ 'authority', 'cpan://JRANDOM', 'version', '0.0.1' ] ], 'x', [ 'attr', [ 'rw', 1, 'Int', 1, 'default', 0 ] ], 'y', [ 'attr', [ 'rw', 1, 'Int', 1, 'default', 0 ] ], 'Point3D', [ 'class', [ 'authority', 'cpan://JRANDOM', 'version', '0.0.1', 'subclass', 'Point' ] ], 'z', [ 'attr', [ 'readonly', 1, 'Int', 1, 'default', 0 ] ] ], '... got the right structure'); } { my $default_thunk = sub { BinaryTree->new(parent => $_[0]) }; my @objects = moose { class BinaryTree => authority is 'cpan://MOOSE', version is '0.01', is rw; has node => isa Any; has parent => isa BinaryTree, is weakref, predicate is 'has_parent'; has left => isa BinaryTree, is lazy, predicate is 'has_left', default is $default_thunk; has right => isa BinaryTree, is lazy, predicate is 'has_left', default is $default_thunk; }; #diag(Dumper(\@objects)); is_deeply( \@objects, [ 'BinaryTree', [ 'class', [ 'authority', 'cpan://MOOSE', 'version', '0.01', 'rw', 1 ] ], 'node', [ 'attr', [ 'Any', 1 ] ], 'parent', [ 'attr', [ 'BinaryTree', 1, 'weakref', 1, 'predicate', 'has_parent' ] ], 'left', [ 'attr', [ 'BinaryTree', 1, 'lazy', 1, 'predicate', 'has_left', 'default', $default_thunk ] ], 'right', [ 'attr', [ 'BinaryTree', 1, 'lazy', 1, 'predicate', 'has_left', 'default', $default_thunk ] ] ], '... got the right structure'); }