Deprecate get_attribute_map
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 71;
5 use Test::Exception;
6
7 use Class::MOP;
8
9 {
10     my $attr = Class::MOP::Attribute->new('$test');
11     is($attr->meta, Class::MOP::Attribute->meta, '... instance and class both lead to the same meta');
12 }
13
14 {
15     my $meta = Class::MOP::Attribute->meta();
16     isa_ok($meta, 'Class::MOP::Class');
17
18     my @methods = qw(
19         new
20         clone
21
22         initialize_instance_slot
23         _set_initial_slot_value
24
25         name
26         has_accessor      accessor
27         has_writer        writer
28         has_write_method  get_write_method  get_write_method_ref
29         has_reader        reader
30         has_read_method   get_read_method   get_read_method_ref
31         has_predicate     predicate
32         has_clearer       clearer
33         has_builder       builder
34         has_init_arg      init_arg
35         has_default       default           is_default_a_coderef
36         has_initializer   initializer
37         has_insertion_order insertion_order _set_insertion_order
38
39         definition_context
40
41         slots
42         get_value
43         set_value
44         get_raw_value
45         set_raw_value
46         set_initial_value
47         has_value
48         clear_value
49
50         associated_class
51         attach_to_class
52         detach_from_class
53
54         accessor_metaclass
55
56         associated_methods
57         associate_method
58
59         process_accessors
60         _process_accessors
61         install_accessors
62         remove_accessors
63
64         _new
65         );
66
67     is_deeply(
68         [ sort $meta->get_method_list ],
69         [ sort @methods ],
70         '... our method list matches');
71
72     foreach my $method_name (@methods) {
73         ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
74     }
75
76     my @attributes = (
77         'name',
78         'accessor',
79         'reader',
80         'writer',
81         'predicate',
82         'clearer',
83         'builder',
84         'init_arg',
85         'initializer',
86         'definition_context',
87         'default',
88         'associated_class',
89         'associated_methods',
90         'insertion_order',
91     );
92
93     is_deeply(
94         [ sort $meta->get_attribute_list ],
95         [ sort @attributes ],
96         '... our attribute list matches');
97
98     foreach my $attribute_name (@attributes) {
99         ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
100     }
101
102     # We could add some tests here to make sure that
103     # the attribute have the appropriate
104     # accessor/reader/writer/predicate combinations,
105     # but that is getting a little excessive so I
106     # wont worry about it for now. Maybe if I get
107     # bored I will do it.
108 }