Commit | Line | Data |
5659d76e |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
89871ad6 |
6 | use Test::More tests => 62; |
5659d76e |
7 | use Test::Exception; |
8 | |
9 | BEGIN { |
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( |
89871ad6 |
23 | new |
24 | clone |
1d68af04 |
25 | |
bd4e03f9 |
26 | initialize_instance_slot |
8ee74136 |
27 | _set_initial_slot_value |
1d68af04 |
28 | |
5659d76e |
29 | name |
89871ad6 |
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 |
1d68af04 |
41 | |
c57c8b10 |
42 | slots |
16e960bd |
43 | get_value |
44 | set_value |
ef91a0e2 |
45 | set_initial_value |
3545c727 |
46 | has_value |
47 | clear_value |
1d68af04 |
48 | |
5659d76e |
49 | associated_class |
89871ad6 |
50 | attach_to_class |
51 | detach_from_class |
1d68af04 |
52 | |
ba38bf08 |
53 | accessor_metaclass |
1d68af04 |
54 | |
3545c727 |
55 | associated_methods |
56 | associate_method |
1d68af04 |
57 | |
5659d76e |
58 | process_accessors |
59 | install_accessors |
60 | remove_accessors |
61 | ); |
1d68af04 |
62 | |
5659d76e |
63 | is_deeply( |
5659d76e |
64 | [ sort $meta->get_method_list ], |
7d28758b |
65 | [ sort @methods ], |
1d68af04 |
66 | '... our method list matches'); |
67 | |
5659d76e |
68 | foreach my $method_name (@methods) { |
69 | ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')'); |
70 | } |
1d68af04 |
71 | |
c23184fc |
72 | my @attributes = ( |
73 | '$!name', |
74 | '$!accessor', |
75 | '$!reader', |
76 | '$!writer', |
77 | '$!predicate', |
78 | '$!clearer', |
1d68af04 |
79 | '$!builder', |
c23184fc |
80 | '$!init_arg', |
2f775ccd |
81 | '$!initializer', |
c23184fc |
82 | '$!default', |
83 | '$!associated_class', |
84 | '@!associated_methods', |
1bd2739a |
85 | ); |
5659d76e |
86 | |
87 | is_deeply( |
5659d76e |
88 | [ sort $meta->get_attribute_list ], |
7d28758b |
89 | [ sort @attributes ], |
5659d76e |
90 | '... our attribute list matches'); |
1d68af04 |
91 | |
5659d76e |
92 | foreach my $attribute_name (@attributes) { |
1d68af04 |
93 | ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')'); |
5659d76e |
94 | } |
1d68af04 |
95 | |
96 | # We could add some tests here to make sure that |
97 | # the attribute have the appropriate |
98 | # accessor/reader/writer/predicate combinations, |
99 | # but that is getting a little excessive so I |
100 | # wont worry about it for now. Maybe if I get |
5659d76e |
101 | # bored I will do it. |
2d711cc8 |
102 | } |