12 package My::Meta::Attribute::DefaultReadOnly;
15 extends 'Moose::Meta::Attribute';
19 my ($self, $name, %options) = @_;
21 unless exists $options{is};
22 $next->($self, $name, %options);
27 package My::Attribute::Trait;
30 has 'alias_to' => (is => 'ro', isa => 'Str');
32 after 'install_accessors' => sub {
34 $self->associated_class->add_method(
36 $self->get_read_method_ref
46 metaclass => 'My::Meta::Attribute::DefaultReadOnly',
47 traits => [qw/My::Attribute::Trait/],
53 my $c = My::Class->new(bar => 100);
54 isa_ok($c, 'My::Class');
56 is($c->bar, 100, '... got the right value for bar');
59 is($c->baz, 100, '... got the right value for baz');
61 isa_ok($c->meta->get_attribute('bar'), 'My::Meta::Attribute::DefaultReadOnly');
62 does_ok($c->meta->get_attribute('bar'), 'My::Attribute::Trait');
63 is($c->meta->get_attribute('bar')->_is_metadata, 'ro', '... got the right metaclass customization');