6 use Test::More tests => 73;
11 use_ok('Class::MOP::Attribute');
15 my $attr = Class::MOP::Attribute->new('$foo');
16 isa_ok($attr, 'Class::MOP::Attribute');
18 is($attr->name, '$foo', '... $attr->name == $foo');
19 ok($attr->has_init_arg, '... $attr does have an init_arg');
20 is($attr->init_arg, '$foo', '... $attr init_arg is the name');
22 ok(!$attr->has_accessor, '... $attr does not have an accessor');
23 ok(!$attr->has_reader, '... $attr does not have an reader');
24 ok(!$attr->has_writer, '... $attr does not have an writer');
25 ok(!$attr->has_default, '... $attr does not have an default');
26 ok(!$attr->has_builder, '... $attr does not have a builder');
28 my $class = Class::MOP::Class->initialize('Foo');
29 isa_ok($class, 'Class::MOP::Class');
32 $attr->attach_to_class($class);
33 } '... attached a class successfully';
35 is($attr->associated_class, $class, '... the class was associated correctly');
37 my $attr_clone = $attr->clone();
38 isa_ok($attr_clone, 'Class::MOP::Attribute');
39 isnt($attr, $attr_clone, '... but they are different instances');
41 is($attr->associated_class, $attr_clone->associated_class, '... the associated classes are the same though');
42 is($attr->associated_class, $class, '... the associated classes are the same though');
43 is($attr_clone->associated_class, $class, '... the associated classes are the same though');
45 is_deeply($attr, $attr_clone, '... but they are the same inside');
49 my $attr = Class::MOP::Attribute->new('$foo', (
53 isa_ok($attr, 'Class::MOP::Attribute');
55 is($attr->name, '$foo', '... $attr->name == $foo');
57 ok($attr->has_init_arg, '... $attr does have an init_arg');
58 is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
59 ok($attr->has_default, '... $attr does have an default');
60 is($attr->default, 'BAR', '... $attr->default == BAR');
61 ok(!$attr->has_builder, '... $attr does not have a builder');
63 ok(!$attr->has_accessor, '... $attr does not have an accessor');
64 ok(!$attr->has_reader, '... $attr does not have an reader');
65 ok(!$attr->has_writer, '... $attr does not have an writer');
67 my $attr_clone = $attr->clone();
68 isa_ok($attr_clone, 'Class::MOP::Attribute');
69 isnt($attr, $attr_clone, '... but they are different instances');
71 is($attr->associated_class, $attr_clone->associated_class, '... the associated classes are the same though');
72 is($attr->associated_class, undef, '... the associated class is actually undef');
73 is($attr_clone->associated_class, undef, '... the associated class is actually undef');
75 is_deeply($attr, $attr_clone, '... but they are the same inside');
79 my $attr = Class::MOP::Attribute->new('$foo', (
84 isa_ok($attr, 'Class::MOP::Attribute');
86 is($attr->name, '$foo', '... $attr->name == $foo');
88 ok($attr->has_init_arg, '... $attr does have an init_arg');
89 is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
90 ok($attr->has_default, '... $attr does have an default');
91 is($attr->default, 'BAR', '... $attr->default == BAR');
93 ok($attr->has_accessor, '... $attr does have an accessor');
94 is($attr->accessor, 'foo', '... $attr->accessor == foo');
96 ok(!$attr->has_reader, '... $attr does not have an reader');
97 ok(!$attr->has_writer, '... $attr does not have an writer');
99 my $attr_clone = $attr->clone();
100 isa_ok($attr_clone, 'Class::MOP::Attribute');
101 isnt($attr, $attr_clone, '... but they are different instances');
103 is_deeply($attr, $attr_clone, '... but they are the same inside');
107 my $attr = Class::MOP::Attribute->new('$foo', (
113 isa_ok($attr, 'Class::MOP::Attribute');
115 is($attr->name, '$foo', '... $attr->name == $foo');
117 ok($attr->has_init_arg, '... $attr does have an init_arg');
118 is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
119 ok($attr->has_default, '... $attr does have an default');
120 is($attr->default, 'BAR', '... $attr->default == BAR');
122 ok($attr->has_reader, '... $attr does have an reader');
123 is($attr->reader, 'get_foo', '... $attr->reader == get_foo');
124 ok($attr->has_writer, '... $attr does have an writer');
125 is($attr->writer, 'set_foo', '... $attr->writer == set_foo');
127 ok(!$attr->has_accessor, '... $attr does not have an accessor');
129 my $attr_clone = $attr->clone();
130 isa_ok($attr_clone, 'Class::MOP::Attribute');
131 isnt($attr, $attr_clone, '... but they are different instances');
133 is_deeply($attr, $attr_clone, '... but they are the same inside');
137 my $attr = Class::MOP::Attribute->new('$foo');
138 isa_ok($attr, 'Class::MOP::Attribute');
140 my $attr_clone = $attr->clone('name' => '$bar');
141 isa_ok($attr_clone, 'Class::MOP::Attribute');
142 isnt($attr, $attr_clone, '... but they are different instances');
144 isnt($attr->name, $attr_clone->name, '... we changes the name parameter');
146 is($attr->name, '$foo', '... $attr->name == $foo');
147 is($attr_clone->name, '$bar', '... $attr_clone->name == $bar');
151 my $attr = Class::MOP::Attribute->new('$foo', (builder => 'foo_builder'));
152 isa_ok($attr, 'Class::MOP::Attribute');
154 ok(!$attr->has_default, '... $attr does not have a default');
155 ok($attr->has_builder, '... $attr does have a builder');
156 is($attr->builder, 'foo_builder', '... $attr->builder == foo_builder');