get_read_method and get_write_method + tests + POD
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
CommitLineData
5659d76e 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
b25109b1 6use Test::More tests => 51;
5659d76e 7use Test::Exception;
8
9BEGIN {
10 use_ok('Class::MOP');
11}
12
13{
013b1897 14 my $attr = Class::MOP::Attribute->new('$test');
15 is($attr->meta, Class::MOP::Attribute->meta, '... instance and class both lead to the same meta');
16}
17
18{
5659d76e 19 my $meta = Class::MOP::Attribute->meta();
20 isa_ok($meta, 'Class::MOP::Class');
21
22 my @methods = qw(
aa448b16 23 meta
5659d76e 24 new clone
bd4e03f9 25
26 initialize_instance_slot
27
5659d76e 28 name
29 has_accessor accessor
b25109b1 30 has_writer writer get_write_method
31 has_reader reader get_read_method
5659d76e 32 has_predicate predicate
7d28758b 33 has_clearer clearer
5659d76e 34 has_init_arg init_arg
495af518 35 has_default default is_default_a_coderef
5659d76e 36
c57c8b10 37 slots
16e960bd 38 get_value
39 set_value
3545c727 40 has_value
41 clear_value
c57c8b10 42
5659d76e 43 associated_class
ba38bf08 44 attach_to_class detach_from_class
5659d76e 45
ba38bf08 46 accessor_metaclass
495af518 47
3545c727 48 associated_methods
49 associate_method
50
5659d76e 51 process_accessors
52 install_accessors
53 remove_accessors
54 );
55
56 is_deeply(
5659d76e 57 [ sort $meta->get_method_list ],
7d28758b 58 [ sort @methods ],
5659d76e 59 '... our method list matches');
60
61 foreach my $method_name (@methods) {
62 ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
63 }
64
c23184fc 65 my @attributes = (
66 '$!name',
67 '$!accessor',
68 '$!reader',
69 '$!writer',
70 '$!predicate',
71 '$!clearer',
72 '$!init_arg',
73 '$!default',
74 '$!associated_class',
75 '@!associated_methods',
5659d76e 76 );
77
78 is_deeply(
5659d76e 79 [ sort $meta->get_attribute_list ],
7d28758b 80 [ sort @attributes ],
5659d76e 81 '... our attribute list matches');
82
83 foreach my $attribute_name (@attributes) {
84 ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
85 }
86
87 # We could add some tests here to make sure that
88 # the attribute have the appropriate
89 # accessor/reader/writer/predicate combinations,
90 # but that is getting a little excessive so I
91 # wont worry about it for now. Maybe if I get
92 # bored I will do it.
2d711cc8 93}