use strict;
use warnings;
-use Test::More tests => 58;
+use Test::More tests => 73;
use Test::Exception;
BEGIN {
is($attr->name, '$foo', '... $attr->name == $foo');
ok($attr->has_init_arg, '... $attr does have an init_arg');
- is($attr->init_arg, '$foo', '... $attr init_arg is the name');
-
+ is($attr->init_arg, '$foo', '... $attr init_arg is the name');
+
ok(!$attr->has_accessor, '... $attr does not have an accessor');
ok(!$attr->has_reader, '... $attr does not have an reader');
ok(!$attr->has_writer, '... $attr does not have an writer');
- ok(!$attr->has_default, '... $attr does not have an default');
-
+ ok(!$attr->has_default, '... $attr does not have an default');
+ ok(!$attr->has_builder, '... $attr does not have a builder');
+
+ my $class = Class::MOP::Class->initialize('Foo');
+ isa_ok($class, 'Class::MOP::Class');
+
+ lives_ok {
+ $attr->attach_to_class($class);
+ } '... attached a class successfully';
+
+ is($attr->associated_class, $class, '... the class was associated correctly');
+
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
-
+
+ is($attr->associated_class, $attr_clone->associated_class, '... the associated classes are the same though');
+ is($attr->associated_class, $class, '... the associated classes are the same though');
+ is($attr_clone->associated_class, $class, '... the associated classes are the same though');
+
is_deeply($attr, $attr_clone, '... but they are the same inside');
}
isa_ok($attr, 'Class::MOP::Attribute');
is($attr->name, '$foo', '... $attr->name == $foo');
-
+
ok($attr->has_init_arg, '... $attr does have an init_arg');
is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
- ok($attr->has_default, '... $attr does have an default');
+ ok($attr->has_default, '... $attr does have an default');
is($attr->default, 'BAR', '... $attr->default == BAR');
-
+ ok(!$attr->has_builder, '... $attr does not have a builder');
+
ok(!$attr->has_accessor, '... $attr does not have an accessor');
ok(!$attr->has_reader, '... $attr does not have an reader');
- ok(!$attr->has_writer, '... $attr does not have an writer');
-
+ ok(!$attr->has_writer, '... $attr does not have an writer');
+
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
-
- is_deeply($attr, $attr_clone, '... but they are the same inside');
+
+ is($attr->associated_class, $attr_clone->associated_class, '... the associated classes are the same though');
+ is($attr->associated_class, undef, '... the associated class is actually undef');
+ is($attr_clone->associated_class, undef, '... the associated class is actually undef');
+
+ is_deeply($attr, $attr_clone, '... but they are the same inside');
}
{
isa_ok($attr, 'Class::MOP::Attribute');
is($attr->name, '$foo', '... $attr->name == $foo');
-
+
ok($attr->has_init_arg, '... $attr does have an init_arg');
is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
- ok($attr->has_default, '... $attr does have an default');
+ ok($attr->has_default, '... $attr does have an default');
is($attr->default, 'BAR', '... $attr->default == BAR');
- ok($attr->has_accessor, '... $attr does have an accessor');
+ ok($attr->has_accessor, '... $attr does have an accessor');
is($attr->accessor, 'foo', '... $attr->accessor == foo');
-
+
ok(!$attr->has_reader, '... $attr does not have an reader');
- ok(!$attr->has_writer, '... $attr does not have an writer');
-
+ ok(!$attr->has_writer, '... $attr does not have an writer');
+
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
-
- is_deeply($attr, $attr_clone, '... but they are the same inside');
+
+ is_deeply($attr, $attr_clone, '... but they are the same inside');
}
{
my $attr = Class::MOP::Attribute->new('$foo', (
reader => 'get_foo',
- writer => 'set_foo',
+ writer => 'set_foo',
init_arg => '-foo',
default => 'BAR'
));
isa_ok($attr, 'Class::MOP::Attribute');
is($attr->name, '$foo', '... $attr->name == $foo');
-
+
ok($attr->has_init_arg, '... $attr does have an init_arg');
is($attr->init_arg, '-foo', '... $attr->init_arg == -foo');
- ok($attr->has_default, '... $attr does have an default');
+ ok($attr->has_default, '... $attr does have an default');
is($attr->default, 'BAR', '... $attr->default == BAR');
ok($attr->has_reader, '... $attr does have an reader');
- is($attr->reader, 'get_foo', '... $attr->reader == get_foo');
+ is($attr->reader, 'get_foo', '... $attr->reader == get_foo');
ok($attr->has_writer, '... $attr does have an writer');
- is($attr->writer, 'set_foo', '... $attr->writer == set_foo');
+ is($attr->writer, 'set_foo', '... $attr->writer == set_foo');
+
+ ok(!$attr->has_accessor, '... $attr does not have an accessor');
- ok(!$attr->has_accessor, '... $attr does not have an accessor');
-
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
-
- is_deeply($attr, $attr_clone, '... but they are the same inside');
+
+ is_deeply($attr, $attr_clone, '... but they are the same inside');
}
{
my $attr = Class::MOP::Attribute->new('$foo');
isa_ok($attr, 'Class::MOP::Attribute');
-
+
my $attr_clone = $attr->clone('name' => '$bar');
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
-
+
isnt($attr->name, $attr_clone->name, '... we changes the name parameter');
-
+
is($attr->name, '$foo', '... $attr->name == $foo');
- is($attr_clone->name, '$bar', '... $attr_clone->name == $bar');
+ is($attr_clone->name, '$bar', '... $attr_clone->name == $bar');
}
+{
+ my $attr = Class::MOP::Attribute->new('$foo', (builder => 'foo_builder'));
+ isa_ok($attr, 'Class::MOP::Attribute');
+
+ ok(!$attr->has_default, '... $attr does not have a default');
+ ok($attr->has_builder, '... $attr does have a builder');
+ is($attr->builder, 'foo_builder', '... $attr->builder == foo_builder');
+
+}