Revision history for Perl extension Moose
+ * Moose::Meta::Method::Constructor
+ -builder related bug in inlined constructor. (groditi)
+
* Moose::Meta::Method::Accessor
- genereate unnecessary calls to predicates and refactor
code generation for runtime speed (groditi)
* Moose::Util::TypeConstraints
- fix ClassName constraint to introspect symbol table
+ * t/
+ - New tests for builder bug. Upon instantiation, if an
+ attribute had a builder, no value and was not lazy the
+ builder default was not getting run, oops. (groditi)
+
0.29 Tues. Nov. 13, 2007
* Moose::Meta::Attribute
- Fix error message on missing builder method (groditi)
use Carp 'confess';
use Scalar::Util 'blessed', 'weaken', 'looks_like_number';
-our $VERSION = '0.02';
+our $VERSION = '0.03';
our $AUTHORITY = 'cpan:STEVAN';
use base 'Moose::Meta::Method';
'|| confess "Attribute (' . $attr->name . ') is required";');
}
- if ($attr->has_default && !($is_moose && $attr->is_lazy)) {
+ if (($attr->has_default || $attr->has_builder) && !($is_moose && $attr->is_lazy)) {
push @source => 'if (exists $params{\'' . $attr->init_arg . '\'}) {';
push @source => "} else {";
- my $default = $self->_generate_default_value($attr, $index);
-
+ my $default;
+ if( $attr->has_default ){
+ $default = $self->_generate_default_value($attr, $index);
+ } else {
+ my $builder = $attr->builder;
+ $default = '$instance->' . $builder;
+ }
push @source => ('my $val = ' . $default . ';');
push @source => $self->_generate_type_constraint_check(
$attr,
use strict;
use warnings;
-use Test::More tests => 14;
+use Test::More tests => 16;
use Test::Exception;
BEGIN {
#there is a TC present.
has 'foos' => (is => 'ro', lazy_build => 1);
has 'bars' => (isa => 'Str', is => 'ro', lazy_build => 1);
- sub _build_foos{ "many foos" }
- sub _build_bars{ "many bars" }
+ has 'bazes' => (isa => 'Str', is => 'ro', builder => '_build_bazes');
+ sub _build_foos { "many foos" }
+ sub _build_bars { "many bars" }
+ sub _build_bazes { "many bazes" }
}
{
my $meta = Foo->meta;
lives_ok{ Foo->new } "lazy_build works";
- is(Foo->new->foos, 'many foos' , "correct value for 'foos'");
- is(Foo->new->bars, 'many bars' , "correct value for 'bars'");
+ is(Foo->new->foos, 'many foos' , "correct value for 'foos' before inlining constructor");
+ is(Foo->new->bars, 'many bars' , "correct value for 'bars' before inlining constructor");
+ is(Foo->new->bazes, 'many bazes' , "correct value for 'bazes' before inlining constructor");
lives_ok{ $meta->make_immutable } "Foo is imutable";
dies_ok{ $meta->add_role($foo_role) } "Add Role is locked";
lives_ok{ Foo->new } "Inlined constructor works with lazy_build";
- is(Foo->new->foos, 'many foos' , "correct value for 'foos'");
- is(Foo->new->bars, 'many bars' , "correct value for 'bars'");
+ is(Foo->new->foos, 'many foos' , "correct value for 'foos' after inlining constructor");
+ is(Foo->new->bars, 'many bars' , "correct value for 'bars' after inlining constructor");
+ is(Foo->new->bazes, 'many bazes' , "correct value for 'bazes' after inlining constructor");
lives_ok{ $meta->make_mutable } "Foo is mutable";
lives_ok{ $meta->add_role($foo_role) } "Add Role is unlocked";