}
sub set_value {
- my ($self, $instance, $value) = @_;
+ my ($self, $instance, @args) = @_;
+ my $value = $args[0];
my $attr_name = $self->name;
- if ($self->is_required) {
- defined($value)
- || confess "Attribute ($attr_name) is required, so cannot be set to undef";
+ if ($self->is_required and not @args) {
+ confess "Attribute ($attr_name) is required";
}
if ($self->has_type_constraint) {
my $attr_name = $attr->name;
return '' unless $attr->is_required;
- return qq{defined(\$_[1]) || confess "Attribute ($attr_name) is required, so cannot be set to undef";}
+ return qq{(\@_ >= 2) || confess "Attribute ($attr_name) is required, so cannot be set to undef";} # defined $_[1] is not good enough
}
sub _inline_check_lazy {
use strict;
use warnings;
-use Test::More tests => 29;
+use Test::More tests => 30;
use Test::Exception;
use Scalar::Util 'isweak';
is($foo->get_foo_required(), 100, '... got the correct set value');
dies_ok {
+ $foo->set_foo_required();
+ } '... set_foo_required died successfully with no value';
+
+ lives_ok {
$foo->set_foo_required(undef);
- } '... set_foo_required died successfully';
+ } '... set_foo_required did accept undef';
ok(!isweak($foo->{foo_required}), '... it is not a weak reference');
use strict;
use warnings;
-use Test::More tests => 57;
+use Test::More tests => 58;
use Test::Exception;
use Scalar::Util 'isweak';
} '... foo_required wrote successfully';
is($foo->foo_required(), 100, '... got the correct set value');
- dies_ok {
+ lives_ok {
$foo->foo_required(undef);
- } '... foo_required died successfully';
+ } '... foo_required did not die with undef';
+
+ is($foo->foo_required, undef, "value is undef");
ok(!isweak($foo->{foo_required}), '... it is not a weak reference');