immutable constructor for Attribute
[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 => 63;
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
24         clone
25
26         initialize_instance_slot
27         _set_initial_slot_value
28
29         name
30         has_accessor      accessor
31         has_writer        writer
32         has_write_method  get_write_method  get_write_method_ref
33         has_reader        reader
34         has_read_method   get_read_method   get_read_method_ref
35         has_predicate     predicate
36         has_clearer       clearer
37         has_builder       builder
38         has_init_arg      init_arg
39         has_default       default           is_default_a_coderef
40         has_initializer   initializer
41
42         slots
43         get_value
44         set_value
45         set_initial_value
46         has_value
47         clear_value
48
49         associated_class
50         attach_to_class
51         detach_from_class
52
53         accessor_metaclass
54
55         associated_methods
56         associate_method
57
58         process_accessors
59         install_accessors
60         remove_accessors
61
62         _new
63         );
64
65     is_deeply(
66         [ sort $meta->get_method_list ],
67         [ sort @methods ],
68         '... our method list matches');
69
70     foreach my $method_name (@methods) {
71         ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
72     }
73
74     my @attributes = (
75         'name',
76         'accessor',
77         'reader',
78         'writer',
79         'predicate',
80         'clearer',
81         'builder',
82         'init_arg',
83         'initializer',
84         'default',
85         'associated_class',
86         'associated_methods',
87     );
88
89     is_deeply(
90         [ sort $meta->get_attribute_list ],
91         [ sort @attributes ],
92         '... our attribute list matches');
93
94     foreach my $attribute_name (@attributes) {
95         ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
96     }
97
98     # We could add some tests here to make sure that
99     # the attribute have the appropriate
100     # accessor/reader/writer/predicate combinations,
101     # but that is getting a little excessive so I
102     # wont worry about it for now. Maybe if I get
103     # bored I will do it.
104 }