Commit | Line | Data |
5659d76e |
1 | #!/usr/bin/perl |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
1bd2739a |
6 | use Test::More tests => 56; |
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( |
aa448b16 |
23 | meta |
5659d76e |
24 | new clone |
1d68af04 |
25 | |
bd4e03f9 |
26 | initialize_instance_slot |
1d68af04 |
27 | |
5659d76e |
28 | name |
29 | has_accessor accessor |
1bd2739a |
30 | has_writer writer get_write_method get_write_method_ref |
31 | has_reader reader get_read_method get_read_method_ref |
5659d76e |
32 | has_predicate predicate |
7d28758b |
33 | has_clearer clearer |
1d68af04 |
34 | has_builder builder |
5659d76e |
35 | has_init_arg init_arg |
495af518 |
36 | has_default default is_default_a_coderef |
1d68af04 |
37 | |
c57c8b10 |
38 | slots |
16e960bd |
39 | get_value |
40 | set_value |
3545c727 |
41 | has_value |
42 | clear_value |
1d68af04 |
43 | |
5659d76e |
44 | associated_class |
1d68af04 |
45 | attach_to_class detach_from_class |
46 | |
ba38bf08 |
47 | accessor_metaclass |
1d68af04 |
48 | |
3545c727 |
49 | associated_methods |
50 | associate_method |
1d68af04 |
51 | |
5659d76e |
52 | process_accessors |
53 | install_accessors |
54 | remove_accessors |
55 | ); |
1d68af04 |
56 | |
5659d76e |
57 | is_deeply( |
5659d76e |
58 | [ sort $meta->get_method_list ], |
7d28758b |
59 | [ sort @methods ], |
1d68af04 |
60 | '... our method list matches'); |
61 | |
5659d76e |
62 | foreach my $method_name (@methods) { |
63 | ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')'); |
64 | } |
1d68af04 |
65 | |
c23184fc |
66 | my @attributes = ( |
67 | '$!name', |
68 | '$!accessor', |
69 | '$!reader', |
70 | '$!writer', |
71 | '$!predicate', |
72 | '$!clearer', |
1d68af04 |
73 | '$!builder', |
c23184fc |
74 | '$!init_arg', |
75 | '$!default', |
76 | '$!associated_class', |
77 | '@!associated_methods', |
1bd2739a |
78 | ); |
5659d76e |
79 | |
80 | is_deeply( |
5659d76e |
81 | [ sort $meta->get_attribute_list ], |
7d28758b |
82 | [ sort @attributes ], |
5659d76e |
83 | '... our attribute list matches'); |
1d68af04 |
84 | |
5659d76e |
85 | foreach my $attribute_name (@attributes) { |
1d68af04 |
86 | ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')'); |
5659d76e |
87 | } |
1d68af04 |
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 |
5659d76e |
94 | # bored I will do it. |
2d711cc8 |
95 | } |