6 use Scalar::Util 'blessed', 'reftype';
8 use Test::More tests => 37;
16 This checks the get_read/write_method
17 and get_read/write_method_ref methods
25 Foo->meta->add_attribute('bar' =>
30 Foo->meta->add_attribute('baz' =>
34 Foo->meta->add_attribute('gorch' =>
35 reader => { 'get_gorch', => sub { (shift)->{gorch} } }
40 Bar->meta->superclasses('Foo');
42 Bar->meta->add_attribute('quux' =>
47 can_ok('Foo', 'get_bar');
48 can_ok('Foo', 'set_bar');
50 can_ok('Foo', 'get_gorch');
52 ok(Foo->meta->has_attribute('bar'), '... Foo has the attribute bar');
53 ok(Foo->meta->has_attribute('baz'), '... Foo has the attribute baz');
54 ok(Foo->meta->has_attribute('gorch'), '... Foo has the attribute gorch');
56 my $bar_attr = Foo->meta->get_attribute('bar');
57 my $baz_attr = Foo->meta->get_attribute('baz');
58 my $gorch_attr = Foo->meta->get_attribute('gorch');
60 is($bar_attr->reader, 'get_bar', '... the bar attribute has the reader get_bar');
61 is($bar_attr->writer, 'set_bar', '... the bar attribute has the writer set_bar');
62 is($bar_attr->associated_class, Foo->meta, '... and the bar attribute is associated with Foo->meta');
64 is($bar_attr->get_read_method, 'get_bar', '... $attr does have an read method');
65 is($bar_attr->get_write_method, 'set_bar', '... $attr does have an write method');
68 my $reader = $bar_attr->get_read_method_ref;
69 my $writer = $bar_attr->get_write_method_ref;
71 isa_ok($reader, 'Class::MOP::Method');
72 isa_ok($writer, 'Class::MOP::Method');
74 is($reader->fully_qualified_name, 'Foo::get_bar', '... it is the sub we are looking for');
75 is($writer->fully_qualified_name, 'Foo::set_bar', '... it is the sub we are looking for');
77 is(reftype($reader->body), 'CODE', '... it is a plain old sub');
78 is(reftype($writer->body), 'CODE', '... it is a plain old sub');
81 is($baz_attr->accessor, 'baz', '... the bar attribute has the accessor baz');
82 is($baz_attr->associated_class, Foo->meta, '... and the bar attribute is associated with Foo->meta');
84 is($baz_attr->get_read_method, 'baz', '... $attr does have an read method');
85 is($baz_attr->get_write_method, 'baz', '... $attr does have an write method');
88 my $reader = $baz_attr->get_read_method_ref;
89 my $writer = $baz_attr->get_write_method_ref;
91 isa_ok($reader, 'Class::MOP::Method');
92 isa_ok($writer, 'Class::MOP::Method');
94 is($reader, $writer, '... they are the same method');
96 is($reader->fully_qualified_name, 'Foo::baz', '... it is the sub we are looking for');
97 is($writer->fully_qualified_name, 'Foo::baz', '... it is the sub we are looking for');
100 is(ref($gorch_attr->reader), 'HASH', '... the gorch attribute has the reader get_gorch (HASH ref)');
101 is($gorch_attr->associated_class, Foo->meta, '... and the gorch attribute is associated with Foo->meta');
103 is($gorch_attr->get_read_method, 'get_gorch', '... $attr does have an read method');
104 ok(!$gorch_attr->get_write_method, '... $attr does not have an write method');
107 my $reader = $gorch_attr->get_read_method_ref;
108 my $writer = $gorch_attr->get_write_method_ref;
110 isa_ok($reader, 'Class::MOP::Method');
111 ok(blessed($writer), '... it is not a plain old sub');
112 isa_ok($writer, 'Class::MOP::Method');
114 is($reader->fully_qualified_name, 'Foo::get_gorch', '... it is the sub we are looking for');
115 is($writer->fully_qualified_name, 'Foo::__ANON__', '... it is the sub we are looking for');