fix t/082_get_code_info.t for bleadperl
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
CommitLineData
5659d76e 1use strict;
2use warnings;
3
7e5efe15 4use Test::More tests => 71;
5659d76e 5use Test::Exception;
6
efd3d14c 7use Class::MOP;
5659d76e 8
9{
013b1897 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{
5659d76e 15 my $meta = Class::MOP::Attribute->meta();
16 isa_ok($meta, 'Class::MOP::Class');
1d68af04 17
5659d76e 18 my @methods = qw(
89871ad6 19 new
20 clone
1d68af04 21
bd4e03f9 22 initialize_instance_slot
8ee74136 23 _set_initial_slot_value
1d68af04 24
5659d76e 25 name
89871ad6 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
df3ea00c 37 has_insertion_order insertion_order _set_insertion_order
1d68af04 38
d9d99689 39 definition_context
40
c57c8b10 41 slots
16e960bd 42 get_value
43 set_value
7e5efe15 44 get_raw_value
45 set_raw_value
ef91a0e2 46 set_initial_value
3545c727 47 has_value
48 clear_value
1d68af04 49
5659d76e 50 associated_class
89871ad6 51 attach_to_class
52 detach_from_class
1d68af04 53
ba38bf08 54 accessor_metaclass
1d68af04 55
3545c727 56 associated_methods
57 associate_method
1d68af04 58
5659d76e 59 process_accessors
45a183fb 60 _process_accessors
5659d76e 61 install_accessors
62 remove_accessors
4b698b1a 63
64 _new
5659d76e 65 );
1d68af04 66
5659d76e 67 is_deeply(
5659d76e 68 [ sort $meta->get_method_list ],
7d28758b 69 [ sort @methods ],
1d68af04 70 '... our method list matches');
71
5659d76e 72 foreach my $method_name (@methods) {
73 ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
74 }
1d68af04 75
c23184fc 76 my @attributes = (
8683db0e 77 'name',
78 'accessor',
79 'reader',
80 'writer',
81 'predicate',
82 'clearer',
83 'builder',
84 'init_arg',
85 'initializer',
d9d99689 86 'definition_context',
8683db0e 87 'default',
88 'associated_class',
89 'associated_methods',
223ec6f9 90 'insertion_order',
1bd2739a 91 );
5659d76e 92
93 is_deeply(
5659d76e 94 [ sort $meta->get_attribute_list ],
7d28758b 95 [ sort @attributes ],
5659d76e 96 '... our attribute list matches');
1d68af04 97
5659d76e 98 foreach my $attribute_name (@attributes) {
1d68af04 99 ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
5659d76e 100 }
1d68af04 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
5659d76e 107 # bored I will do it.
2d711cc8 108}