foo
[gitmo/Moose.git] / lib / Moose / Meta / Method / Accessor.pm
index 0e0987d..4b7a451 100644 (file)
@@ -122,16 +122,16 @@ sub _inline_pre_body  { '' }
 sub _inline_post_body { '' }
 
 sub _inline_check_constraint {
-        my ($self, $value) = @_;
-
-        my $attr = $self->associated_attribute;
-
-        return '' unless $attr->has_type_constraint;
-
-        # FIXME
-        # This sprintf is insanely annoying, we should
-        # fix it someday - SL
-        return sprintf <<'EOF', $value, $value, $value, $value, $value, $value, $value
+    my ($self, $value) = @_;
+    
+    my $attr = $self->associated_attribute;
+    
+    return '' unless $attr->has_type_constraint;
+    
+    # FIXME
+    # This sprintf is insanely annoying, we should
+    # fix it someday - SL
+    return sprintf <<'EOF', $value, $value, $value, $value, $value, $value, $value
 defined($type_constraint->(%s))
         || confess "Attribute (" . $attr->name . ") does not pass the type constraint ("
        . $attr->type_constraint->name . ") with "
@@ -141,16 +141,16 @@ EOF
 }
 
 sub _inline_check_coercion {
-        my $attr = (shift)->associated_attribute;
-
-        return '' unless $attr->should_coerce;
+    my $attr = (shift)->associated_attribute;
+    
+    return '' unless $attr->should_coerce;
     return '$val = $attr->type_constraint->coerce($_[1]);'
 }
 
 sub _inline_check_required {
-        my $attr = (shift)->associated_attribute;
-
-        return '' unless $attr->is_required;
+    my $attr = (shift)->associated_attribute;
+    
+    return '' unless $attr->is_required;
     return 'defined($_[1]) || confess "Attribute ($attr_name) is required, so cannot be set to undef";'
 }
 
@@ -167,10 +167,11 @@ sub _inline_check_lazy {
 
     my $code = 'unless (' . $slot_exists . ') {' . "\n";
     if ($attr->has_type_constraint) {
-        if($attr->has_default || $attr->has_builder){
-            if($attr->has_default){
+        if ($attr->has_default || $attr->has_builder) {
+            if ($attr->has_default) {
                 $code .= '    my $default = $attr->default(' . $inv . ');'."\n";
-            } elsif($attr->has_builder){
+            } 
+            elsif ($attr->has_builder) {
                 $code .= '    my $default;'."\n".
                          '    if(my $builder = '.$inv.'->can($attr->builder)){ '."\n".
                          '        $default = '.$inv.'->$builder; '. "\n    } else {\n" .
@@ -183,19 +184,22 @@ sub _inline_check_lazy {
                      '           . $attr->type_constraint->name . ") with " . (defined($default) ? (Scalar::Util::blessed($default) && overload::Overloaded($default) ? overload::StrVal($default) : $default) : "undef")' .
                      '          if defined($default);' . "\n" .
                      '        ' . $slot_access . ' = $default; ' . "\n";
-        } else {
+        } 
+        else {
             $code .= '    ' . $slot_access . " = undef; \n";
         }
 
     } else {
-        if($attr->has_default){
+        if ($attr->has_default) {
             $code .= '    '.$slot_access.' = $attr->default(' . $inv . ');'."\n";
-        } elsif($attr->has_builder){
+        } 
+        elsif ($attr->has_builder) {
             $code .= '    if(my $builder = '.$inv.'->can($attr->builder)){ '."\n".
                      '        '.$slot_access.' = '.$inv.'->$builder; '. "\n    } else {\n" .
                      '        confess(Scalar::Util::blessed('.$inv.')." does not support builder method '.
                      '\'".$attr->builder."\' for attribute \'" . $attr->name . "\'");'. "\n    }";
-        } else {
+        } 
+        else {
             $code .= '    ' . $slot_access . " = undef; \n";
         }
     }
@@ -205,51 +209,51 @@ sub _inline_check_lazy {
 
 
 sub _inline_store {
-        my ($self, $instance, $value) = @_;
-        my $attr = $self->associated_attribute;
-
-        my $mi = $attr->associated_class->get_meta_instance;
-        my $slot_name = sprintf "'%s'", $attr->slots;
-
+    my ($self, $instance, $value) = @_;
+    my $attr = $self->associated_attribute;
+    
+    my $mi = $attr->associated_class->get_meta_instance;
+    my $slot_name = sprintf "'%s'", $attr->slots;
+    
     my $code = $mi->inline_set_slot_value($instance, $slot_name, $value)    . ";";
-        $code   .= $mi->inline_weaken_slot_value($instance, $slot_name, $value) . ";"
-            if $attr->is_weak_ref;
+    $code   .= $mi->inline_weaken_slot_value($instance, $slot_name, $value) . ";"
+        if $attr->is_weak_ref;
     return $code;
 }
 
 sub _inline_trigger {
-        my ($self, $instance, $value) = @_;
-        my $attr = $self->associated_attribute;
-        return '' unless $attr->has_trigger;
-        return sprintf('$attr->trigger->(%s, %s, $attr);', $instance, $value);
+    my ($self, $instance, $value) = @_;
+    my $attr = $self->associated_attribute;
+    return '' unless $attr->has_trigger;
+    return sprintf('$attr->trigger->(%s, %s, $attr);', $instance, $value);
 }
 
 sub _inline_get {
-        my ($self, $instance) = @_;
-        my $attr = $self->associated_attribute;
-
-        my $mi = $attr->associated_class->get_meta_instance;
-        my $slot_name = sprintf "'%s'", $attr->slots;
+    my ($self, $instance) = @_;
+    my $attr = $self->associated_attribute;
+    
+    my $mi = $attr->associated_class->get_meta_instance;
+    my $slot_name = sprintf "'%s'", $attr->slots;
 
     return $mi->inline_get_slot_value($instance, $slot_name);
 }
 
 sub _inline_access {
-        my ($self, $instance) = @_;
-        my $attr = $self->associated_attribute;
-
-        my $mi = $attr->associated_class->get_meta_instance;
-        my $slot_name = sprintf "'%s'", $attr->slots;
+    my ($self, $instance) = @_;
+    my $attr = $self->associated_attribute;
+    
+    my $mi = $attr->associated_class->get_meta_instance;
+    my $slot_name = sprintf "'%s'", $attr->slots;
 
     return $mi->inline_slot_access($instance, $slot_name);
 }
 
 sub _inline_has {
-        my ($self, $instance) = @_;
-        my $attr = $self->associated_attribute;
-
-        my $mi = $attr->associated_class->get_meta_instance;
-        my $slot_name = sprintf "'%s'", $attr->slots;
+    my ($self, $instance) = @_;
+    my $attr = $self->associated_attribute;
+    
+    my $mi = $attr->associated_class->get_meta_instance;
+    my $slot_name = sprintf "'%s'", $attr->slots;
 
     return $mi->inline_is_slot_initialized($instance, $slot_name);
 }