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