X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F005_attributes.t;h=1429a0a846784ba32261ce503e0c25c0924ee4b7;hb=33ecbaa40bbcda7518cb3e5477d357e6b3d95ff6;hp=770991d94cda49037a479f9cb2bcdd7a1d53465a;hpb=efd3d14c1cf03120dfd1ed7787f8050e55bb8319;p=gitmo%2FClass-MOP.git diff --git a/t/005_attributes.t b/t/005_attributes.t index 770991d..1429a0a 100644 --- a/t/005_attributes.t +++ b/t/005_attributes.t @@ -1,9 +1,7 @@ -#!/usr/bin/perl - use strict; use warnings; -use Test::More tests => 70; +use Test::More tests => 73; use Test::Exception; use Class::MOP; @@ -90,6 +88,23 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); } { + package Foo2; + use metaclass; + + my $meta = Foo2->meta; + $meta->add_attribute( + Class::MOP::Attribute->new( '$foo2' => ( reader => 'foo2' ) ) ); + + ::ok( $meta->has_method('foo2'), '... a reader has been created' ); + + my $attr = $meta->get_attribute('$foo2'); + ::is( $attr->get_read_method, 'foo2', + '... got the right read method for Foo2' ); + ::is( $attr->get_write_method, undef, + '... got undef for the writer with a read-only attribute in Foo2' ); +} + +{ my $meta = Baz->meta; isa_ok($meta, 'Class::MOP::Class'); @@ -98,7 +113,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); is($meta->find_attribute_by_name('$foo'), $FOO_ATTR, '... got the right attribute for "foo"'); is_deeply( - [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ $BAR_ATTR, $BAZ_ATTR, @@ -107,7 +122,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); '... got the right list of applicable attributes for Baz'); is_deeply( - [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ Bar->meta, Baz->meta, Foo->meta ], '... got the right list of associated classes from the applicable attributes for Baz'); @@ -124,7 +139,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); ok(!$meta->has_method('set_baz'), '... a writer has been removed'); is_deeply( - [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ $BAR_ATTR, $FOO_ATTR, @@ -132,7 +147,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); '... got the right list of applicable attributes for Baz'); is_deeply( - [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ Bar->meta, Foo->meta ], '... got the right list of associated classes from the applicable attributes for Baz'); @@ -149,7 +164,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); } is_deeply( - [ sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ $BAR_ATTR_2, $FOO_ATTR, @@ -157,7 +172,7 @@ is($BAZ_ATTR->name, '$baz', '... got the attributes name correctly'); '... got the right list of applicable attributes for Baz'); is_deeply( - [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->compute_all_applicable_attributes() ], + [ map { $_->associated_class } sort { $a->name cmp $b->name } $meta->get_all_attributes() ], [ Foo->meta, Foo->meta ], '... got the right list of associated classes from the applicable attributes for Baz');