X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FMethod%2FConstructor.pm;h=ba7b28be16f2a29cdf5ce7af23e8b3b1b0b7fdd6;hb=7756897fd756804423cafb8f8806443b768269f0;hp=4b5e0994c93ba11f85712b81fd79324bab8d0c86;hpb=9df6f0cd390fd74f63dc8985bf9e9c765c941ae9;p=gitmo%2FMouse.git diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 4b5e099..ba7b28b 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -7,7 +7,7 @@ sub generate_constructor_method_inline { my @attrs = $meta->compute_all_applicable_attributes; my $buildall = $class->_generate_BUILDALL($meta); - my $buildargs = $class->_generate_BUILDARGS(); + my $buildargs = $class->_generate_BUILDARGS($meta); my $processattrs = $class->_generate_processattrs($meta, \@attrs); my $code = <<"..."; @@ -42,28 +42,32 @@ sub _generate_processattrs { $code .= "if (exists \$args->{'$from'}) {\n"; if ($attr->should_coerce && $attr->type_constraint) { - $code .= "my \$value = Mouse::TypeRegistry->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{find_type_constraint}, \$attrs[$index]->{type_constraint}, \$args->{'$from'});"; + $code .= "my \$value = Mouse::TypeRegistry->typecast_constraints('".$attr->associated_class->name."', \$attrs[$index]->{find_type_constraint}, \$attrs[$index]->{type_constraint}, \$args->{'$from'});\n"; } else { - $code .= "my \$value = \$args->{'$from'};"; + $code .= "my \$value = \$args->{'$from'};\n"; } if ($attr->has_type_constraint) { - $code .= "{local \$_ = \$value; unless (\$attrs[$index]->{find_type_constraint}->(\$_)) {"; - $code .= "\$attrs[$index]->verify_type_constraint_error('$key', \$_, \$attrs[$index]->type_constraint)}}"; + $code .= "{ + local \$_ = \$value; + unless (\$attrs[$index]->{find_type_constraint}->(\$_)) { + \$attrs[$index]->verify_type_constraint_error('$key', \$_, \$attrs[$index]->type_constraint) + } + }"; } - $code .= "\$instance->{'$key'} = \$value;"; + $code .= "\$instance->{'$key'} = \$value;\n"; if ($attr->is_weak_ref) { - $code .= "Scalar::Util::weaken( \$instance->{'$key'} ) if ref( \$value );"; + $code .= "Scalar::Util::weaken( \$instance->{'$key'} ) if ref( \$value );\n"; } if ($attr->has_trigger) { - $code .= "\$attrs[$index]->{trigger}->( \$instance, \$value, \$attrs[$index] );"; + $code .= "\$attrs[$index]->{trigger}->( \$instance, \$value, \$attrs[$index] );\n"; } - $code .= "} else {"; + $code .= "\n} else {\n"; } if ($attr->has_default || $attr->has_builder) { @@ -94,29 +98,33 @@ sub _generate_processattrs { } if ($attr->should_coerce) { - $code .= ");"; + $code .= ");\n"; } else { - $code .= ";"; + $code .= ";\n"; } if ($attr->has_type_constraint) { - $code .= "{local \$_ = \$value; unless (\$attrs[$index]->{find_type_constraint}->(\$_)) {"; - $code .= "\$attrs[$index]->verify_type_constraint_error('$key', \$_, \$attrs[$index]->type_constraint)}}"; + $code .= "{ + local \$_ = \$value; + unless (\$attrs[$index]->{find_type_constraint}->(\$_)) { + \$attrs[$index]->verify_type_constraint_error('$key', \$_, \$attrs[$index]->type_constraint) + } + }"; } - $code .= "\$instance->{'$key'} = \$value;"; + $code .= "\$instance->{'$key'} = \$value;\n"; if ($attr->is_weak_ref) { - $code .= "Scalar::Util::weaken( \$instance->{'$key'} ) if ref( \$value );"; + $code .= "Scalar::Util::weaken( \$instance->{'$key'} ) if ref( \$value );\n"; } } } elsif ($attr->is_required) { - $code .= qq{Carp::confess("Attribute ($key) is required");}; + $code .= "Carp::confess('Attribute ($key) is required');"; } - $code .= "}" if defined $attr->init_arg; + $code .= "}\n" if defined $attr->init_arg; push @res, $code; } @@ -125,7 +133,14 @@ sub _generate_processattrs { } sub _generate_BUILDARGS { - <<'...'; + my $self = shift; + my $meta = shift; + + if ($meta->name->can('BUILDARGS') != Mouse::Object->can('BUILDARGS')) { + return '$class->BUILDARGS(@_)'; + } + + return <<'...'; do { if ( scalar @_ == 1 ) { if ( defined $_[0] ) {