Docs, small fixes, find_method_by_name and the get_value/set_value abstraction for...
[gitmo/Class-MOP.git] / t / 014_attribute_introspection.t
CommitLineData
5659d76e 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
16e960bd 6use Test::More tests => 48;
5659d76e 7use Test::Exception;
8
9BEGIN {
10 use_ok('Class::MOP');
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');
21
22 my @methods = qw(
aa448b16 23 meta
5659d76e 24 new clone
bd4e03f9 25
26 initialize_instance_slot
27
5659d76e 28 name
29 has_accessor accessor
30 has_writer writer
31 has_reader reader
32 has_predicate predicate
33 has_init_arg init_arg
495af518 34 has_default default is_default_a_coderef
5659d76e 35
c57c8b10 36 slots
16e960bd 37 get_value
38 set_value
c57c8b10 39
5659d76e 40 associated_class
41 attach_to_class detach_from_class
42
43 generate_accessor_method
44 generate_reader_method
45 generate_writer_method
46 generate_predicate_method
47
495af518 48 generate_accessor_method_inline
49 generate_reader_method_inline
50 generate_writer_method_inline
51 generate_predicate_method_inline
52
5659d76e 53 process_accessors
54 install_accessors
55 remove_accessors
56 );
57
58 is_deeply(
59 [ sort @methods ],
60 [ sort $meta->get_method_list ],
61 '... our method list matches');
62
63 foreach my $method_name (@methods) {
64 ok($meta->has_method($method_name), '... Class::MOP::Attribute->has_method(' . $method_name . ')');
65 }
66
67 my @attributes = qw(
68 name accessor reader writer predicate
69 init_arg default associated_class
70 );
71
72 is_deeply(
73 [ sort @attributes ],
74 [ sort $meta->get_attribute_list ],
75 '... our attribute list matches');
76
77 foreach my $attribute_name (@attributes) {
78 ok($meta->has_attribute($attribute_name), '... Class::MOP::Attribute->has_attribute(' . $attribute_name . ')');
79 }
80
81 # We could add some tests here to make sure that
82 # the attribute have the appropriate
83 # accessor/reader/writer/predicate combinations,
84 # but that is getting a little excessive so I
85 # wont worry about it for now. Maybe if I get
86 # bored I will do it.
2d711cc8 87}