X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FMethod%2FAccessor.pm;h=9c5b746a3bf6b02e0949cc362a74e0f3831067a3;hp=d073cb58f69e99dcc61118134dcc116cb23b9f56;hb=95ecd6f132112c6763cdaf2e6bc72c39e9ab76b5;hpb=9d0686b20ef0bafe5f99c9a9c5e354ff06476f15 diff --git a/lib/Mouse/Meta/Method/Accessor.pm b/lib/Mouse/Meta/Method/Accessor.pm index d073cb5..9c5b746 100755 --- a/lib/Mouse/Meta/Method/Accessor.pm +++ b/lib/Mouse/Meta/Method/Accessor.pm @@ -88,11 +88,20 @@ sub _generate_accessor{ $value = '$default'; } + $accessor .= "if(!exists $slot){\n"; if($should_coerce){ - $value = "\$constraint->coerce($value)"; + $accessor .= "$slot = \$constraint->coerce($value)"; } - - $accessor .= "$slot = $value if !exists $slot;\n"; + elsif(defined $constraint){ + $accessor .= "my \$tmp = $value;\n"; + $accessor .= "\$compiled_type_constraint->(\$tmp)"; + $accessor .= "or \$attribute->verify_type_constraint_error(\$name, \$tmp, \$constraint);\n"; + $accessor .= "$slot = \$tmp;\n"; + } + else{ + $accessor .= "$slot = $value;\n"; + } + $accessor .= "}\n"; } if ($should_deref) {