From: 大沢 和宏 Date: Fri, 5 Dec 2008 13:42:20 +0000 (+0000) Subject: optimaized default values in constructor X-Git-Tag: 0.19~136^2~26 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=713a2a052a1918450652b3ef5093eeb6640c9e7b;p=gitmo%2FMouse.git optimaized default values in constructor --- diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index c386e3d..2867d71 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -77,15 +77,20 @@ sub _generate_processattrs { if ($attr->should_coerce) { push @code, "\$attrs[$index]->coerce_constraint("; } - if ($attr->has_builder) { push @code, "\$instance->$builder"; } elsif (ref($default) eq 'CODE') { push @code, "\$attrs[$index]->default()->()"; } + elsif (!defined($default)) { + push @code, 'undef'; + } + elsif ($default =~ /^\-?[0-9]+(?:\.[0-9]+)$/) { + push @code, $default; + } else { - push @code, "\$attrs[$index]->default()"; + push @code, "'$default'"; } if ($attr->should_coerce) { @@ -119,8 +124,14 @@ sub _generate_processattrs { { if (exists(\$args->{'$from'})) { $set_value; +... + if ($make_default_value) { + $code .= <<"..."; } else { $make_default_value; +... + } + $code .= <<"..."; } } ...