+ - handle non-lazy default and builder when init_arg is undef
- add copyright and license info for downstream packagers
- weak ref checking for Sub::Quote to avoid bugs on refaddr reuse
- Switch composed role names to be a valid package name
if (!$spec->{lazy} and
($spec->{default} or $spec->{builder})) {
my $get_indent = ' ' x ($spec->{isa} ? 6 : 4);
+ my $get_default = $self->_generate_get_default(
+ '$new', $_, $spec
+ );
my $get_value =
- "(\n${get_indent} ${test}\n${get_indent} ? ${source}\n${get_indent} : "
- .$self->_generate_get_default(
- '$new', $_, $spec
- )
- ."\n${get_indent})";
+ defined($spec->{init_arg})
+ ? "(\n${get_indent} ${test}\n${get_indent} ? ${source}\n${get_indent} : "
+ .$get_default
+ ."\n${get_indent})"
+ : $get_default;
($spec->{isa}
? " {\n my \$value = ".$get_value.";\n "
.$self->_generate_isa_check(
my $ag = $self->accessor_generator;
NAME: foreach my $name (sort keys %$spec) {
my $attr_spec = $spec->{$name};
- next NAME unless defined(my $i = $attr_spec->{init_arg});
unless ($ag->is_simple_attribute($name, $attr_spec)) {
- $test{$name} = $i;
+ next NAME unless defined($attr_spec->{init_arg})
+ or (($attr_spec->{default} or $attr_spec->{builder})
+ and not $attr_spec->{lazy});
+ $test{$name} = $attr_spec->{init_arg};
next NAME;
}
+ next NAME unless defined(my $i = $attr_spec->{init_arg});
push @init, $i;
push @slots, $name;
}
has three => (is => 'ro', default => quote_sub q{ {} });
has four => (is => 'ro', builder => '_build_four');
sub _build_four { {} }
+ has five => (is => 'ro', init_arg => undef, default => sub { {} });
}
sub check {
check four => map Foo->new->{four}, 1..2;
+check five => map Foo->new->{five}, 1..2;
+
done_testing;