From: Yuval Kogman Date: Sun, 27 Jan 2008 00:20:14 +0000 (+0000) Subject: die in Attribute::_process_options if the attr is required but there is no way to... X-Git-Tag: 0_37~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9edba990401a61d4319cfcf02205186e1713071d;p=gitmo%2FMoose.git die in Attribute::_process_options if the attr is required but there is no way to set it during construction (init_arg, builder or default) --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 39036f4..0d5b2a0 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -195,10 +195,14 @@ sub _process_options { } if (exists $options->{lazy} && $options->{lazy}) { - (exists $options->{default} || exists $options->{builder} ) + (exists $options->{default} || defined $options->{builder} ) || confess "You cannot have lazy attribute without specifying a default value for it"; } + if ( $options->{required} && !( ( !exists $options->{init_arg} || defined $options->{init_arg} ) || exists $options->{default} || defined $options->{builder} ) ) { + confess "You cannot have a required attribute without a default, builder, or an init_arg"; + } + } sub initialize_instance_slot {