From: Matt S Trout Date: Sat, 24 Mar 2012 19:25:43 +0000 (+0000) Subject: Fix a bug where coercions weren't called on lazy default/builder returns X-Git-Tag: v1.000000~8 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FRole-Tiny.git;a=commitdiff_plain;h=160c2c2c5c944d61ada3e252d2e621f9074ebd9f Fix a bug where coercions weren't called on lazy default/builder returns --- diff --git a/Changes b/Changes index c8aa52f..f6e66fb 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,4 @@ + - Fix a bug where coercions weren't called on lazy default/builder returns - Switch Moo::Utils to using Module::Runtime, and add the 5.8 %INC leakage fix into Role::Tiny's _load_module to provide partial parity - Update incompatibilities with Moose documentation diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index 4a8ecd3..410b6a3 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -178,8 +178,15 @@ sub generate_get_default { sub _generate_use_default { my ($self, $me, $name, $spec, $test) = @_; + my $get_value = $self->_generate_get_default($me, $name, $spec); + if ($spec->{coerce}) { + $get_value = $self->_generate_coerce( + $name, $me, $get_value, + $spec->{coerce} + ) + } $self->_generate_simple_set( - $me, $name, $spec, $self->_generate_get_default($me, $name, $spec) + $me, $name, $spec, $get_value ).' unless '.$test; }