use strict;
use warnings;
-use Test::More tests => 70;
+use Test::More tests => 90;
use Test::Exception;
use Class::MOP;
}
{
+ 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');
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,
'... 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');
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,
'... 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');
}
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,
'... 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');
} '... we added a method to Buzz successfully';
}
-{
+
+
+for(1 .. 2){
my $buzz;
::lives_ok { $buzz = Buzz->meta->new_object } '...Buzz instantiated successfully';
::is($buzz->foo, 'Buzz', '...foo builder works as expected');
::ok($buzz2->has_bar, '...bar is set');
::is($buzz2->bar, undef, '...bar is undef');
-}
-
-{
- my $buzz;
- ::lives_ok { $buzz = Buzz->meta->new_object } '...Buzz instantiated successfully';
- ::ok($buzz->has_bah, '...bah is set');
- ::is($buzz->bah, 'BAH', '...bah returns "BAH" ');
+ my $buzz3;
+ ::lives_ok { $buzz3 = Buzz->meta->new_object } '...Buzz instantiated successfully';
+ ::ok($buzz3->has_bah, '...bah is set');
+ ::is($buzz3->bah, 'BAH', '...bah returns "BAH" ');
- my $buzz2;
- ::lives_ok { $buzz2 = Buzz->meta->new_object('$bah' => undef) } '...Buzz instantiated successfully';
- ::ok($buzz2->has_bah, '...bah is set');
- ::is($buzz2->bah, undef, '...bah is undef');
+ my $buzz4;
+ ::lives_ok { $buzz4 = Buzz->meta->new_object('$bah' => undef) } '...Buzz instantiated successfully';
+ ::ok($buzz4->has_bah, '...bah is set');
+ ::is($buzz4->bah, undef, '...bah is undef');
+ Buzz->meta->make_immutable();
}