Change clearers to return true for compatibility
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
1 use strict;
2 use warnings;
3
4 use Test::More tests => 72;
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         has_trigger       trigger           call_trigger
39
40         definition_context
41
42         slots
43         get_value
44         set_value
45         set_initial_value
46         has_value
47         clear_value
48
49         associated_class
50         attach_to_class
51         detach_from_class
52
53         accessor_metaclass
54
55         associated_methods
56         associate_method
57
58         process_accessors
59         _process_accessors
60         install_accessors
61         remove_accessors
62
63         _new
64         );
65
66     is_deeply(
67         [ sort $meta->get_method_list ],
68         [ sort @methods ],
69         '... our method list matches');
70
71     foreach my $method_name (@methods) {
72         ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
73     }
74
75     my @attributes = (
76         'name',
77         'accessor',
78         'reader',
79         'writer',
80         'predicate',
81         'clearer',
82         'builder',
83         'init_arg',
84         'initializer',
85         'definition_context',
86         'default',
87         'associated_class',
88         'associated_methods',
89         'insertion_order',
90     );
91
92     is_deeply(
93         [ sort $meta->get_attribute_list ],
94         [ sort @attributes ],
95         '... our attribute list matches');
96
97     foreach my $attribute_name (@attributes) {
98         ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
99     }
100
101     # We could add some tests here to make sure that
102     # the attribute have the appropriate
103     # accessor/reader/writer/predicate combinations,
104     # but that is getting a little excessive so I
105     # wont worry about it for now. Maybe if I get
106     # bored I will do it.
107 }