sub _initialize
{
- my $self = shift;
+ my $self = shift;
+ my $metaclass = shift;
if ( $self->has_default() )
{
}
elsif ( $self->has_builder() )
{
- $self->set_value( undef, $self->_call_builder() );
+ $self->set_value( undef, $self->_call_builder( $metaclass->name() ) );
}
}
->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 ],
},
);
+ class_has 'Built' =>
+ ( is => 'ro',
+ builder => '_BuildIt',
+ );
+
+ class_has 'LazyBuilt' =>
+ ( is => 'ro',
+ lazy => 1,
+ builder => '_BuildIt',
+ );
+
has 'size' =>
( is => 'rw',
isa => 'Int',
$self->ObjectCount( $self->ObjectCount() + 1 );
}
+ sub _BuildIt { 42 }
+
sub make_immutable
{
my $class = shift;
sub run_tests
{
- plan tests => 24;
+ plan tests => 26;
local $Test::Builder::Level = $Test::Builder::Level + 1;
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' );
+ }
}