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