From: Dave Rolsky Date: Tue, 29 Jul 2008 15:10:39 +0000 (+0000) Subject: more metaclass trait tests X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=139d7e40e03eec9e4c95fbf3ceaa5654e00be096;p=gitmo%2FMoose.git more metaclass trait tests --- diff --git a/t/050_metaclasses/012_metaclass_traits.t b/t/050_metaclasses/012_metaclass_traits.t index dbcc55f..44fdb18 100644 --- a/t/050_metaclasses/012_metaclass_traits.t +++ b/t/050_metaclasses/012_metaclass_traits.t @@ -70,7 +70,6 @@ is( Bar->meta()->attr(), 'something', sub simple2 { return 55 } } - { package Baz; @@ -89,3 +88,35 @@ is( Baz->meta()->simple2(), 55, can_ok( Baz->meta(), 'attr2' ); is( Baz->meta()->attr2(), 'something', 'Baz->meta()->attr2() returns expected value' ); + +{ + package My::Trait::AlwaysRO; + + use Moose::Role; + + around '_process_new_attribute', '_process_inherited_attribute' => + sub { + my $orig = shift; + my ( $self, $name, %args ) = @_; + + $args{is} = 'ro'; + + return $self->$orig( $name, %args ); + }; +} + +{ + package Quux; + + use Moose -traits => [ 'My::Trait::AlwaysRO' ]; + + has 'size' => + ( is => 'rw', + isa => 'Int', + ); +} + +ok( Quux->meta()->has_attribute('size'), + 'Quux has size attribute' ); +ok( ! Quux->meta()->get_attribute('size')->writer(), + 'size attribute does not have a writer' );