From: Dave Rolsky Date: Mon, 1 Sep 2008 21:09:07 +0000 (+0000) Subject: Split out calling an attribute's builder into its own private method. X-Git-Tag: 0.57~34 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8fe20aab9c589f5d2d6d48eaac2c4807fc4304bc;p=gitmo%2FMoose.git Split out calling an attribute's builder into its own private method. A) This is a nice refactor. B) It makes subclassing easier, and I need it for MX::ClassAttribute. --- diff --git a/lib/Moose/Meta/Attribute.pm b/lib/Moose/Meta/Attribute.pm index 93939f4..d7347d0 100644 --- a/lib/Moose/Meta/Attribute.pm +++ b/lib/Moose/Meta/Attribute.pm @@ -376,13 +376,8 @@ sub initialize_instance_slot { $value_is_set = 1; } elsif ($self->has_builder) { - if (my $builder = $instance->can($self->builder)){ - $val = $instance->$builder; - $value_is_set = 1; - } - else { - confess(blessed($instance)." does not support builder method '".$self->builder."' for attribute '" . $self->name . "'"); - } + $val = $self->_call_builder($instance); + $value_is_set = 1; } } @@ -405,6 +400,22 @@ sub initialize_instance_slot { if ref $val && $self->is_weak_ref; } +sub _call_builder { + my ( $self, $instance ) = @_; + + my $builder = $self->builder(); + + return $instance->$builder() + if $instance->can( $self->builder ); + + confess( blessed($instance) + . " does not support builder method '" + . $self->builder + . "' for attribute '" + . $self->name + . "'" ); +} + ## Slot management # FIXME: @@ -493,18 +504,8 @@ sub get_value { if ($self->has_default) { $value = $self->default($instance); } elsif ( $self->has_builder ) { - if (my $builder = $instance->can($self->builder)){ - $value = $instance->$builder; - } - else { - confess(blessed($instance) - . " does not support builder method '" - . $self->builder - . "' for attribute '" - . $self->name - . "'"); - } - } + $value = $self->_call_builder($instance); + } if ($self->has_type_constraint) { my $type_constraint = $self->type_constraint; $value = $type_constraint->coerce($value)