6 use Test::More tests => 17;
15 This test demonstrates the ability to extend
16 Moose meta-level classes using Moose itself.
21 package My::Meta::Class;
26 extends 'Moose::Meta::Class';
28 around 'create_anon_class' => sub {
30 my ($self, %options) = @_;
31 $options{superclasses} = [ 'Moose::Object' ]
32 unless exists $options{superclasses};
33 $next->($self, %options);
37 my $anon = My::Meta::Class->create_anon_class();
38 isa_ok($anon, 'My::Meta::Class');
39 isa_ok($anon, 'Moose::Meta::Class');
40 isa_ok($anon, 'Class::MOP::Class');
43 [ $anon->superclasses ],
45 '... got the default superclasses');
48 package My::Meta::Attribute::DefaultReadOnly;
53 extends 'Moose::Meta::Attribute';
57 my ($self, $name, %options) = @_;
59 unless exists $options{is};
60 $next->($self, $name, %options);
65 my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo');
66 isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly');
67 isa_ok($attr, 'Moose::Meta::Attribute');
68 isa_ok($attr, 'Class::MOP::Attribute');
70 ok($attr->has_reader, '... the attribute has a reader (as expected)');
71 ok(!$attr->has_writer, '... the attribute does not have a writer (as expected)');
72 ok(!$attr->has_accessor, '... the attribute does not have an accessor (as expected)');
76 my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo', (is => 'rw'));
77 isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly');
78 isa_ok($attr, 'Moose::Meta::Attribute');
79 isa_ok($attr, 'Class::MOP::Attribute');
81 ok(!$attr->has_reader, '... the attribute does not have a reader (as expected)');
82 ok(!$attr->has_writer, '... the attribute does not have a writer (as expected)');
83 ok($attr->has_accessor, '... the attribute does have an accessor (as expected)');