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