From: Alex J. G. BurzyƄski Date: Fri, 29 Jul 2011 11:22:28 +0000 (+0100) Subject: call BUILDARGS if defined X-Git-Tag: v0.009011~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=eae70e33b9265a0fdfa1ebda85dd68314e057783;p=gitmo%2FMoo.git call BUILDARGS if defined --- diff --git a/lib/Method/Generate/Constructor.pm b/lib/Method/Generate/Constructor.pm index 23d9c03..43be542 100644 --- a/lib/Method/Generate/Constructor.pm +++ b/lib/Method/Generate/Constructor.pm @@ -44,7 +44,11 @@ sub generate_method { local $self->{captures} = {}; my $body = ' my $class = shift;'."\n"; $body .= $self->_handle_subconstructor($into, $name); - $body .= $self->_generate_args; + if ($into->can('BUILDARGS') ) { + $body .= $self->_generate_args_via_buildargs; + } else { + $body .= $self->_generate_args; + } $body .= $self->_check_required($spec); $body .= ' my $new = '.$self->construction_string.";\n"; $body .= $self->_assign_new($spec); @@ -79,11 +83,16 @@ sub _cap_call { $code; } -sub _generate_args { +sub _generate_args_via_buildargs { my ($self) = @_; q{ my $args = $class->BUILDARGS(@_);}."\n"; } +sub _generate_args { + my ($self) = @_; + q{ my $args = ref($_[0]) eq 'HASH' ? $_[0] : { @_ };}."\n"; +} + sub _assign_new { my ($self, $spec) = @_; my (@init, @slots, %test);