6 use Test::More tests => 16;
13 This test demonstrates the ability to extend
14 Moose meta-level classes using Moose itself.
19 package My::Meta::Class;
22 extends 'Moose::Meta::Class';
24 around 'create_anon_class' => sub {
26 my ($self, %options) = @_;
27 $options{superclasses} = [ 'Moose::Object' ]
28 unless exists $options{superclasses};
29 $next->($self, %options);
33 my $anon = My::Meta::Class->create_anon_class();
34 isa_ok($anon, 'My::Meta::Class');
35 isa_ok($anon, 'Moose::Meta::Class');
36 isa_ok($anon, 'Class::MOP::Class');
39 [ $anon->superclasses ],
41 'got the default superclasses');
44 package My::Meta::Attribute::DefaultReadOnly;
47 extends 'Moose::Meta::Attribute';
51 my ($self, $name, %options) = @_;
53 unless exists $options{is};
54 $next->($self, $name, %options);
59 my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo');
60 isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly');
61 isa_ok($attr, 'Moose::Meta::Attribute');
62 isa_ok($attr, 'Class::MOP::Attribute');
64 ok($attr->has_reader, 'the attribute has a reader (as expected)');
65 ok(!$attr->has_writer, 'the attribute does not have a writer (as expected)');
66 ok(!$attr->has_accessor, 'the attribute does not have an accessor (as expected)');
70 my $attr = My::Meta::Attribute::DefaultReadOnly->new('foo', (is => 'rw'));
71 isa_ok($attr, 'My::Meta::Attribute::DefaultReadOnly');
72 isa_ok($attr, 'Moose::Meta::Attribute');
73 isa_ok($attr, 'Class::MOP::Attribute');
75 ok(!$attr->has_reader, 'the attribute does not have a reader (as expected)');
76 ok(!$attr->has_writer, 'the attribute does not have a writer (as expected)');
77 ok($attr->has_accessor, 'the attribute does have an accessor (as expected)');