restructure this method a bit for readability
Jesse Luehrs [Sun, 24 Apr 2011 20:32:01 +0000 (15:32 -0500)]
lib/Moose/Meta/Method/Accessor.pm

index f736f25..661c454 100644 (file)
@@ -35,28 +35,33 @@ sub _compile_code {
 sub _eval_environment {
     my $self = shift;
 
-    my $attr                = $self->associated_attribute;
-    my $type_constraint_obj = $attr->type_constraint;
-
-    return {
-        '$trigger'             => \($attr->trigger),
-        '$default'             => \($attr->default),
-        '$meta'                => \$self,
-        '$type_constraint_obj' => \$type_constraint_obj,
-        ($type_constraint_obj && !$type_constraint_obj->can_be_inlined
-            ? ('$type_constraint'
-                => \($type_constraint_obj->_compiled_type_constraint))
-            : ()),
-        (
-            $type_constraint_obj
-            ? %{ $type_constraint_obj->inline_environment }
-            : ()
-        ),
-        # XXX ugh
-        ($attr->has_initializer
-            ? ('$attr' => \$attr)
-            : ()),
-    };
+    my $env = { };
+
+    my $attr = $self->associated_attribute;
+
+    $env->{'$trigger'} = \($attr->trigger)
+        if $attr->has_trigger;
+    $env->{'$default'} = \($attr->default)
+        if $attr->has_default;
+
+    if ($attr->has_type_constraint) {
+        my $tc_obj = $attr->type_constraint;
+
+        # is this going to be an issue? it's currently used for coercions
+        # and the tc message, is there a way to inline those too?
+        $env->{'$type_constraint_obj'} = \$tc_obj;
+        $env->{'$type_constraint'}     = \($tc_obj->_compiled_type_constraint)
+            unless $tc_obj->can_be_inlined;
+
+        $env = { %$env, %{ $tc_obj->inline_environment } };
+    }
+
+    # XXX ugh, fix these
+    $env->{'$attr'} = \$attr
+        if $attr->has_initializer;
+    $env->{'$meta'} = \$self;
+
+    return $env;
 }
 
 sub _instance_is_inlinable {