X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F024_attribute_initializer.t;h=328ff7c34475ec7f3ee8f97d3cf2ef2f8ad772f9;hb=6db5c459d895adc8cea8f285f26aca1ea3c3cd14;hp=76e5834a363a10c0260fb86007fc8334a95e3205;hpb=0ab65f99f6aadf14b5b686e6e6a1f3c14c14272e;p=gitmo%2FClass-MOP.git diff --git a/t/024_attribute_initializer.t b/t/024_attribute_initializer.t index 76e5834..328ff7c 100644 --- a/t/024_attribute_initializer.t +++ b/t/024_attribute_initializer.t @@ -1,15 +1,11 @@ -#!/usr/bin/perl - use strict; use warnings; use Scalar::Util 'blessed', 'reftype'; -use Test::More tests => 4; +use Test::More tests => 9; -BEGIN { - use_ok('Class::MOP'); -} +use Class::MOP; =pod @@ -22,11 +18,15 @@ This checks that the initializer is used to set the initial value. use metaclass; Foo->meta->add_attribute('bar' => - reader => 'get_bar', - writer => 'set_bar', + reader => 'get_bar', + writer => 'set_bar', initializer => sub { - my ($self, $value, $callback) = @_; - $callback->($value * 2); + my ($self, $value, $callback, $attr) = @_; + + ::isa_ok($attr, 'Class::MOP::Attribute'); + ::is($attr->name, 'bar', '... the attribute is our own'); + + $callback->($value * 2); }, ); } @@ -34,10 +34,26 @@ This checks that the initializer is used to set the initial value. can_ok('Foo', 'get_bar'); can_ok('Foo', 'set_bar'); -my $foo = Foo->meta->construct_instance(bar => 10); -is( - $foo->get_bar, - 20, - "initial argument was doubled as expected", -); +my $foo = Foo->meta->new_object(bar => 10); +is($foo->get_bar, 20, "... initial argument was doubled as expected"); + +$foo->set_bar(30); + +is($foo->get_bar, 30, "... and setter works correctly"); + +# meta tests ... + +my $bar = Foo->meta->get_attribute('bar'); +isa_ok($bar, 'Class::MOP::Attribute'); + +ok($bar->has_initializer, '... bar has an initializer'); +is(reftype $bar->initializer, 'CODE', '... the initializer is a CODE ref'); + + + + + + + +