6 use Scalar::Util 'blessed', 'reftype';
8 use Test::More tests => 9;
14 This checks that the initializer is used to set the initial value.
22 Foo->meta->add_attribute('bar' =>
26 my ($self, $value, $callback, $attr) = @_;
28 ::isa_ok($attr, 'Class::MOP::Attribute');
29 ::is($attr->name, 'bar', '... the attribute is our own');
31 $callback->($value * 2);
36 can_ok('Foo', 'get_bar');
37 can_ok('Foo', 'set_bar');
39 my $foo = Foo->meta->construct_instance(bar => 10);
40 is($foo->get_bar, 20, "... initial argument was doubled as expected");
44 is($foo->get_bar, 30, "... and setter works correctly");
48 my $bar = Foo->meta->get_attribute('bar');
49 isa_ok($bar, 'Class::MOP::Attribute');
51 ok($bar->has_initializer, '... bar has an initializer');
52 is(reftype $bar->initializer, 'CODE', '... the initializer is a CODE ref');