bump version to 1.25
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor.pm
index b471dc9..6f1f710 100644 (file)
@@ -4,7 +4,7 @@ package Moose::Meta::Method::Accessor;
 use strict;
 use warnings;
 
-our $VERSION   = '1.10';
+our $VERSION   = '1.25';
 $VERSION = eval $VERSION;
 our $AUTHORITY = 'cpan:STEVAN';
 
@@ -19,20 +19,8 @@ sub _error_thrower {
 sub _eval_code {
     my ( $self, $source ) = @_;
 
-    # NOTE:
-    # set up the environment
-    my $attr = $self->associated_attribute;
-    my $type_constraint_obj = $attr->type_constraint;
-    my $environment = {
-        '$attr' => \$attr,
-        '$meta' => \$self,
-        '$type_constraint_obj' => \$type_constraint_obj,
-        '$type_constraint' => \($type_constraint_obj
-                                   ? $type_constraint_obj->_compiled_type_constraint
-                                   : undef),
-    };
+    my $environment = $self->_eval_environment;
 
-    #warn "code for " . $attr->name . " =>\n" . $source . "\n";
     my ( $code, $e ) = $self->_compile_code( environment => $environment, code => $source );
 
     $self->throw_error(
@@ -43,9 +31,26 @@ sub _eval_code {
     return $code;
 }
 
+sub _eval_environment {
+    my $self = shift;
+
+    my $attr                = $self->associated_attribute;
+    my $type_constraint_obj = $attr->type_constraint;
+
+    return {
+        '$attr'                => \$attr,
+        '$meta'                => \$self,
+        '$type_constraint_obj' => \$type_constraint_obj,
+        '$type_constraint'     => \(
+              $type_constraint_obj
+            ? $type_constraint_obj->_compiled_type_constraint
+            : undef
+        ),
+    };
+}
+
 sub _generate_accessor_method_inline {
     my $self        = $_[0];
-    my $attr        = $self->associated_attribute;
     my $inv         = '$_[0]';
     my $value_name  = $self->_value_needs_copy ? '$val' : '$_[1]';
 
@@ -68,9 +73,7 @@ sub _generate_accessor_method_inline {
 
 sub _generate_writer_method_inline {
     my $self        = $_[0];
-    my $attr        = $self->associated_attribute;
     my $inv         = '$_[0]';
-    my $slot_access = $self->_inline_get($inv);
     my $value_name  = $self->_value_needs_copy ? '$val' : '$_[1]';
 
     $self->_eval_code('sub { '
@@ -88,7 +91,6 @@ sub _generate_writer_method_inline {
 
 sub _generate_reader_method_inline {
     my $self        = $_[0];
-    my $attr        = $self->associated_attribute;
     my $inv         = '$_[0]';
     my $slot_access = $self->_inline_get($inv);
 
@@ -204,7 +206,7 @@ sub _inline_check_lazy {
                          ';'. "\n    }";
             }
             $code .= $self->_inline_check_coercion('$default') . "\n";
-            $code .= $self->_inline_check_constraint('$default') . "\n";
+            $code .= $self->_inline_check_constraint('$default', 'lazy') . "\n";
             $code .= '    ' . $self->_inline_init_slot($attr, $instance, '$default') . "\n";
         }
         else {
@@ -241,15 +243,9 @@ sub _inline_init_slot {
 }
 
 sub _inline_store {
-    my ($self, $instance, $value) = @_;
-    my $attr = $self->associated_attribute;
+    my ( $self, $instance, $value ) = @_;
 
-    my $mi = $attr->associated_class->get_meta_instance;
-
-    my $code = $mi->inline_set_slot_value($instance, $attr->slots, $value)    . ";";
-    $code   .= $mi->inline_weaken_slot_value($instance, $attr->slots, $value) . ";"
-        if $attr->is_weak_ref;
-    return $code;
+    return $self->associated_attribute->inline_set( $instance, $value );
 }
 
 sub _inline_get_old_value_for_trigger {
@@ -258,12 +254,9 @@ sub _inline_get_old_value_for_trigger {
     my $attr = $self->associated_attribute;
     return '' unless $attr->has_trigger;
 
-    my $mi = $attr->associated_class->get_meta_instance;
-    my $pred = $mi->inline_is_slot_initialized($instance, $attr->name);
-
     return
           'my @old = '
-        . $pred . q{ ? }
+        . $self->_inline_has($instance) . q{ ? }
         . $self->_inline_get($instance) . q{ : ()} . ";\n";
 }
 
@@ -276,29 +269,14 @@ sub _inline_trigger {
 
 sub _inline_get {
     my ($self, $instance) = @_;
-    my $attr = $self->associated_attribute;
 
-    my $mi = $attr->associated_class->get_meta_instance;
-
-    return $mi->inline_get_slot_value($instance, $attr->slots);
-}
-
-sub _inline_access {
-    my ($self, $instance) = @_;
-    my $attr = $self->associated_attribute;
-
-    my $mi = $attr->associated_class->get_meta_instance;
-
-    return $mi->inline_slot_access($instance, $attr->slots);
+    return $self->associated_attribute->inline_get($instance);
 }
 
 sub _inline_has {
     my ($self, $instance) = @_;
-    my $attr = $self->associated_attribute;
-
-    my $mi = $attr->associated_class->get_meta_instance;
 
-    return $mi->inline_is_slot_initialized($instance, $attr->slots);
+    return $self->associated_attribute->inline_has($instance);
 }
 
 sub _inline_auto_deref {