whoops
[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 => 56;
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         meta
24         new clone
25
26         initialize_instance_slot
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
38         slots
39         get_value
40         set_value
41         has_value
42         clear_value
43
44         associated_class
45         attach_to_class detach_from_class
46
47         accessor_metaclass
48
49         associated_methods
50         associate_method
51
52         process_accessors
53         install_accessors
54         remove_accessors
55         );
56
57     is_deeply(
58         [ sort $meta->get_method_list ],
59         [ sort @methods ],
60         '... our method list matches');
61
62     foreach my $method_name (@methods) {
63         ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
64     }
65
66     my @attributes = (
67         '$!name',
68         '$!accessor',
69         '$!reader',
70         '$!writer',
71         '$!predicate',
72         '$!clearer',
73         '$!builder',
74         '$!init_arg',
75         '$!default',
76         '$!associated_class',
77         '@!associated_methods',
78     );
79
80     is_deeply(
81         [ sort $meta->get_attribute_list ],
82         [ sort @attributes ],
83         '... our attribute list matches');
84
85     foreach my $attribute_name (@attributes) {
86         ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
87     }
88
89     # We could add some tests here to make sure that
90     # the attribute have the appropriate
91     # accessor/reader/writer/predicate combinations,
92     # but that is getting a little excessive so I
93     # wont worry about it for now. Maybe if I get
94     # bored I will do it.
95 }