From: Dave Rolsky Date: Thu, 9 Jul 2009 21:18:39 +0000 (-0500) Subject: make non-lazy builder work X-Git-Tag: 0.09~6 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=6048a0539081fb957a030fd99c442bf80ceed15e;p=gitmo%2FMooseX-ClassAttribute.git make non-lazy builder work --- diff --git a/lib/MooseX/ClassAttribute/Role/Meta/Attribute.pm b/lib/MooseX/ClassAttribute/Role/Meta/Attribute.pm index 1b1f1b5..66879ac 100644 --- a/lib/MooseX/ClassAttribute/Role/Meta/Attribute.pm +++ b/lib/MooseX/ClassAttribute/Role/Meta/Attribute.pm @@ -55,7 +55,8 @@ around 'detach_from_class' => sub sub _initialize { - my $self = shift; + my $self = shift; + my $metaclass = shift; if ( $self->has_default() ) { @@ -63,7 +64,7 @@ sub _initialize } elsif ( $self->has_builder() ) { - $self->set_value( undef, $self->_call_builder() ); + $self->set_value( undef, $self->_call_builder( $metaclass->name() ) ); } } diff --git a/t/03-introspection.t b/t/03-introspection.t index bfe6727..6818ab0 100644 --- a/t/03-introspection.t +++ b/t/03-introspection.t @@ -16,7 +16,7 @@ ok( HasClassAttribute->meta()->get_class_attribute('ObjectCount') ->meta()->does_role('MooseX::ClassAttribute::Role::Meta::Attribute'), 'get_class_attribute_list returns an object which does the MooseX::ClassAttribute::Role::Meta::Attribute role' ); -my @ca = qw( Delegatee LazyAttribute ManyNames Mapping ObjectCount ReadOnlyAttribute WeakAttribute ); +my @ca = qw( Delegatee LazyAttribute ManyNames Mapping ObjectCount ReadOnlyAttribute WeakAttribute Built LazyBuilt ); is_deeply( [ sort HasClassAttribute->meta()->get_class_attribute_list() ], [ sort @ca ], diff --git a/t/lib/SharedTests.pm b/t/lib/SharedTests.pm index 970bc94..1299263 100644 --- a/t/lib/SharedTests.pm +++ b/t/lib/SharedTests.pm @@ -76,6 +76,17 @@ use Test::More; }, ); + class_has 'Built' => + ( is => 'ro', + builder => '_BuildIt', + ); + + class_has 'LazyBuilt' => + ( is => 'ro', + lazy => 1, + builder => '_BuildIt', + ); + has 'size' => ( is => 'rw', isa => 'Int', @@ -91,6 +102,8 @@ use Test::More; $self->ObjectCount( $self->ObjectCount() + 1 ); } + sub _BuildIt { 42 } + sub make_immutable { my $class = shift; @@ -139,7 +152,7 @@ use Test::More; sub run_tests { - plan tests => 24; + plan tests => 26; local $Test::Builder::Level = $Test::Builder::Level + 1; @@ -243,6 +256,14 @@ sub run_tests is( HasClassAttribute->GetMapping('a'), 20, 'value for a in mapping is 20' ); } + + { + is( HasClassAttribute->Built(), 42, + 'attribute with builder works' ); + + is( HasClassAttribute->LazyBuilt(), 42, + 'attribute with lazy builder works' ); + } }