Class::MOP fixes
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 60;
7 use Test::Exception;
8
9 BEGIN {
10     use_ok('Class::MOP');
11 }
12
13 {
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 {
19     my $meta = Class::MOP::Attribute->meta();
20     isa_ok($meta, 'Class::MOP::Class');
21
22     my @methods = qw(
23         new clone
24
25         initialize_instance_slot
26         _set_initial_slot_value
27
28         name
29         has_accessor  accessor
30         has_writer    writer     get_write_method get_write_method_ref
31         has_reader    reader     get_read_method  get_read_method_ref
32         has_predicate predicate
33         has_clearer   clearer
34         has_builder   builder
35         has_init_arg  init_arg
36         has_default   default    is_default_a_coderef
37         has_initializer initializer
38
39         slots
40         get_value
41         set_value
42         set_initial_value
43         has_value
44         clear_value
45
46         associated_class
47         attach_to_class detach_from_class
48
49         accessor_metaclass
50
51         associated_methods
52         associate_method
53
54         process_accessors
55         install_accessors
56         remove_accessors
57         );
58
59     is_deeply(
60         [ sort $meta->get_method_list ],
61         [ sort @methods ],
62         '... our method list matches');
63
64     foreach my $method_name (@methods) {
65         ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
66     }
67
68     my @attributes = (
69         '$!name',
70         '$!accessor',
71         '$!reader',
72         '$!writer',
73         '$!predicate',
74         '$!clearer',
75         '$!builder',
76         '$!init_arg',
77         '$!initializer',
78         '$!default',
79         '$!associated_class',
80         '@!associated_methods',
81     );
82
83     is_deeply(
84         [ sort $meta->get_attribute_list ],
85         [ sort @attributes ],
86         '... our attribute list matches');
87
88     foreach my $attribute_name (@attributes) {
89         ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
90     }
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
97     # bored I will do it.
98 }