X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=lib%2FMouse%2FMeta%2FMethod%2FConstructor.pm;h=433fc46381766cdbab6241e3f8b1997d55a677fd;hp=2de3802411b28c164cb08fa7522b405f0ace87f5;hb=95e0838c698351915133884105fcf5f43cc85a55;hpb=c12edd9ac9343d9853e4b9ca9f2254336e468ffc diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 2de3802..433fc46 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -39,17 +39,17 @@ sub _generate_processattrs { my $part1 = do { my @code; if ($attr->should_coerce) { - push @code, "\$args->{\$from} = \$attr->coerce_constraint( \$args->{\$from} );"; + push @code, "\$args->{'$from'} = \$attr->coerce_constraint( \$args->{'$from'} );"; } if ($attr->has_type_constraint) { - push @code, "\$attr->verify_type_constraint( \$args->{\$from} );"; + push @code, "\$attr->verify_type_constraint( \$args->{'$from'} );"; } - push @code, "\$instance->{\$key} = \$args->{\$from};"; + push @code, "\$instance->{'$key'} = \$args->{'$from'};"; if ($attr->is_weak_ref) { - push @code, "weaken( \$instance->{\$key} ) if ref( \$instance->{\$key} );"; + push @code, "weaken( \$instance->{'$key'} ) if ref( \$instance->{'$key'} );"; } if ( $attr->has_trigger ) { - push @code, "\$attr->trigger->( \$instance, \$args->{\$from}, \$attr );"; + push @code, "\$attr->trigger->( \$instance, \$args->{'$from'}, \$attr );"; } join "\n", @code; }; @@ -72,16 +72,16 @@ sub _generate_processattrs { if ($attr->has_type_constraint) { push @code, "\$attr->verify_type_constraint(\$value);"; } - push @code, "\$instance->{\$key} = \$value;"; + push @code, "\$instance->{'$key'} = \$value;"; if ($attr->is_weak_ref) { - push @code, "weaken( \$instance->{\$key} ) if ref( \$instance->{\$key} );"; + push @code, "weaken( \$instance->{'$key'} ) if ref( \$instance->{'$key'} );"; } } join "\n", @code; } else { if ( $attr->is_required ) { - q{Carp::confess("Attribute (} . $attr->name . q{) is required");}; + qq{Carp::confess("Attribute ($key) is required");}; } else { "" } @@ -90,9 +90,7 @@ sub _generate_processattrs { my $code = <<"..."; { my \$attr = \$attrs[$index]; - my \$from = '$from'; - my \$key = '$key'; - if (defined(\$from) && exists(\$args->{\$from})) { + if (exists(\$args->{'$from'})) { $part1; } else { $part2;