Move attribute triggers from Moose, breaking no compatibility
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
CommitLineData
5659d76e 1use strict;
2use warnings;
3
7813a0c5 4use Test::More tests => 72;
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
7813a0c5 38 has_trigger trigger call_trigger
1d68af04 39
d9d99689 40 definition_context
41
c57c8b10 42 slots
16e960bd 43 get_value
44 set_value
ef91a0e2 45 set_initial_value
3545c727 46 has_value
47 clear_value
1d68af04 48
5659d76e 49 associated_class
89871ad6 50 attach_to_class
51 detach_from_class
1d68af04 52
ba38bf08 53 accessor_metaclass
1d68af04 54
3545c727 55 associated_methods
56 associate_method
1d68af04 57
5659d76e 58 process_accessors
45a183fb 59 _process_accessors
5659d76e 60 install_accessors
61 remove_accessors
4b698b1a 62
63 _new
5659d76e 64 );
1d68af04 65
5659d76e 66 is_deeply(
5659d76e 67 [ sort $meta->get_method_list ],
7d28758b 68 [ sort @methods ],
1d68af04 69 '... our method list matches');
70
5659d76e 71 foreach my $method_name (@methods) {
72 ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
73 }
1d68af04 74
c23184fc 75 my @attributes = (
8683db0e 76 'name',
77 'accessor',
78 'reader',
79 'writer',
80 'predicate',
81 'clearer',
82 'builder',
83 'init_arg',
84 'initializer',
d9d99689 85 'definition_context',
8683db0e 86 'default',
87 'associated_class',
88 'associated_methods',
223ec6f9 89 'insertion_order',
1bd2739a 90 );
5659d76e 91
92 is_deeply(
5659d76e 93 [ sort $meta->get_attribute_list ],
7d28758b 94 [ sort @attributes ],
5659d76e 95 '... our attribute list matches');
1d68af04 96
5659d76e 97 foreach my $attribute_name (@attributes) {
1d68af04 98 ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
5659d76e 99 }
1d68af04 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
5659d76e 106 # bored I will do it.
2d711cc8 107}