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=6064afff23d27d6214b0178fa214d6a8e8e0ea2a;hp=8d9fd554b2a276da94415b1da9231402fe35b1c0;hb=05a12aa45fbcd22111d4f5dde2736c8361540198;hpb=06a970ab9fb60a4cac5e3f1774cf9a2914c94cc1 diff --git a/lib/Mouse/Meta/Method/Constructor.pm b/lib/Mouse/Meta/Method/Constructor.pm index 8d9fd55..6064aff 100644 --- a/lib/Mouse/Meta/Method/Constructor.pm +++ b/lib/Mouse/Meta/Method/Constructor.pm @@ -1,5 +1,10 @@ package Mouse::Meta::Method::Constructor; -use Mouse::Util; # enables strict and warnings +use Mouse::Util qw(:meta); # enables strict and warnings + +sub _inline_slot{ + my(undef, $self_var, $attr_name) = @_; + return sprintf '%s->{q{%s}}', $self_var, $attr_name; +} sub _generate_constructor { my ($class, $metaclass, $args) = @_; @@ -42,7 +47,7 @@ sub _generate_constructor { } sub _generate_processattrs { - my ($class, $metaclass, $attrs) = @_; + my ($method_class, $metaclass, $attrs) = @_; my @res; my $has_triggers; @@ -55,9 +60,10 @@ sub _generate_processattrs { my $init_arg = $attr->init_arg; my $type_constraint = $attr->type_constraint; + my $is_weak_ref = $attr->is_weak_ref; my $need_coercion; - my $instance_slot = "\$instance->{q{$key}}"; + my $instance_slot = $method_class->_inline_slot('$instance', $key); my $attr_var = "\$attrs[$index]"; my $constraint_var; @@ -71,9 +77,9 @@ sub _generate_processattrs { my $post_process = ''; if(defined $type_constraint){ $post_process .= "\$checks[$index]->($instance_slot)"; - $post_process .= " or $attr_var->verify_type_constraint_error(q{$key}, $instance_slot, $constraint_var);\n"; + $post_process .= " or $attr_var->_throw_type_constraint_error($instance_slot, $constraint_var);\n"; } - if($attr->is_weak_ref){ + if($is_weak_ref){ $post_process .= "Scalar::Util::weaken($instance_slot) if ref $instance_slot;\n"; } @@ -121,6 +127,9 @@ sub _generate_processattrs { } $code .= "$instance_slot = $value;\n"; + if($is_weak_ref){ + $code .= "Scalar::Util::weaken($instance_slot);\n"; + } } } elsif ($attr->is_required) { @@ -172,10 +181,7 @@ sub _generate_BUILDALL { my @code; for my $class ($metaclass->linearized_isa) { - no strict 'refs'; - no warnings 'once'; - - if (*{ $class . '::BUILD' }{CODE}) { + if (Mouse::Util::get_code_ref($class, 'BUILD')) { unshift @code, qq{${class}::BUILD(\$instance, \$args);}; } } @@ -191,7 +197,7 @@ Mouse::Meta::Method::Constructor - A Mouse method generator for constructors =head1 VERSION -This document describes Mouse version 0.38 +This document describes Mouse version 0.50_01 =head1 SEE ALSO