X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoose%2FMeta%2FMethod%2FConstructor.pm;h=9d8fc18204fa7d5e236abad958d054a738acb736;hb=a62dcd43575e3069a70277082c7be85fb71322bf;hp=5337cd6e3958c2ff513fc652a2f58aa945137f41;hpb=e1737edc1aeb23724d9da1fec93ed82e900d8e00;p=gitmo%2FMoose.git diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 5337cd6..9d8fc18 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -6,7 +6,7 @@ use warnings; use Scalar::Util 'blessed', 'weaken', 'looks_like_number'; -our $VERSION = '0.62_02'; +our $VERSION = '0.71_01'; our $AUTHORITY = 'cpan:STEVAN'; use base 'Moose::Meta::Method', @@ -117,7 +117,7 @@ sub associated_metaclass { (shift)->{'associated_metaclass'} } # this was changed in 0.41, but broke MooseX::Singleton, so try to catch # any other code using the original broken spelling -sub intialize_body { Moose->throw_error("Please correct the spelling of 'intialize_body' to 'initialize_body'") } +sub intialize_body { $_[0]->throw_error("Please correct the spelling of 'intialize_body' to 'initialize_body'") } sub initialize_body { my $self = shift; @@ -142,42 +142,42 @@ sub initialize_body { $self->_generate_slot_initializer($_) } 0 .. (@{$self->attributes} - 1)); - $source .= ";\n" . $self->_generate_triggers(); + $source .= ";\n" . $self->_generate_triggers(); $source .= ";\n" . $self->_generate_BUILDALL(); $source .= ";\n" . 'return $instance'; $source .= ";\n" . '}'; warn $source if $self->options->{debug}; - my $code; - { - my $meta = $self; # FIXME for _inline_throw_error... - - # NOTE: - # create the nessecary lexicals - # to be picked up in the eval - my $attrs = $self->attributes; - - # We need to check if the attribute ->can('type_constraint') - # since we may be trying to immutabilize a Moose meta class, - # which in turn has attributes which are Class::MOP::Attribute - # objects, rather than Moose::Meta::Attribute. And - # Class::MOP::Attribute attributes have no type constraints. - # However we need to make sure we leave an undef value there - # because the inlined code is using the index of the attributes - # to determine where to find the type constraint - - my @type_constraints = map { - $_->can('type_constraint') ? $_->type_constraint : undef - } @$attrs; - - my @type_constraint_bodies = map { - defined $_ ? $_->_compiled_type_constraint : undef; - } @type_constraints; - - $code = eval $source; - $self->throw_error("Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source ) if $@; - } + # We need to check if the attribute ->can('type_constraint') + # since we may be trying to immutabilize a Moose meta class, + # which in turn has attributes which are Class::MOP::Attribute + # objects, rather than Moose::Meta::Attribute. And + # Class::MOP::Attribute attributes have no type constraints. + # However we need to make sure we leave an undef value there + # because the inlined code is using the index of the attributes + # to determine where to find the type constraint + + my $attrs = $self->attributes; + + my @type_constraints = map { + $_->can('type_constraint') ? $_->type_constraint : undef + } @$attrs; + + my @type_constraint_bodies = map { + defined $_ ? $_->_compiled_type_constraint : undef; + } @type_constraints; + + my $code = $self->_compile_code( + code => $source, + environment => { + '$meta' => \$self, + '$attrs' => \$attrs, + '@type_constraints' => \@type_constraints, + '@type_constraint_bodies' => \@type_constraint_bodies, + }, + ) or $self->throw_error("Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@", error => $@, data => $source ); + $self->{'body'} = $code; } @@ -190,7 +190,7 @@ sub _generate_BUILDARGS { return join("\n", 'do {', $self->_inline_throw_error('"Single parameters to new() must be a HASH ref"', 'data => $_[0]'), - ' if scalar @_ == 1 && defined $_[0] && ref($_[0]) ne q{HASH};', + ' if scalar @_ == 1 && !( defined $_[0] && ref $_[0] eq q{HASH} );', '(scalar @_ == 1) ? {%{$_[0]}} : {@_};', '}', ); @@ -221,7 +221,7 @@ sub _generate_triggers { . '$instance, ' . $self->meta_instance->inline_get_slot_value( '$instance', - ("'" . $attr->name . "'") + $attr->name, ) . ', ' . '$attrs->[' . $i . ']' @@ -319,7 +319,7 @@ sub _generate_slot_assignment { $source = ( $self->meta_instance->inline_set_slot_value( '$instance', - ("'" . $attr->name . "'"), + $attr->name, $value ) . ';' ); @@ -332,7 +332,7 @@ sub _generate_slot_assignment { "\n" . $self->meta_instance->inline_weaken_slot_value( '$instance', - ("'" . $attr->name . "'") + $attr->name ) . ' if ref ' . $value . ';' ); @@ -409,7 +409,7 @@ Moose::Meta::Method::Constructor - Method Meta Object for constructors =head1 DESCRIPTION This is a subclass of L which handles -constructing an approprate Constructor methods. This is primarily +constructing an appropriate Constructor methods. This is primarily used in the making of immutable metaclasses, otherwise it is not particularly useful. @@ -419,6 +419,8 @@ not particularly useful. =item B +=item B + =item B =item B @@ -429,8 +431,6 @@ not particularly useful. =item B -=item B - =back =head1 AUTHORS @@ -439,7 +439,7 @@ Stevan Little Estevan@iinteractive.comE =head1 COPYRIGHT AND LICENSE -Copyright 2006-2008 by Infinity Interactive, Inc. +Copyright 2006-2009 by Infinity Interactive, Inc. L