bump version to 0.75_01
[gitmo/Moose.git] / lib / Moose / Meta / Method / Constructor.pm
index 77bc32b..4474207 100644 (file)
@@ -4,13 +4,13 @@ package Moose::Meta::Method::Constructor;
 use strict;
 use warnings;
 
-use Scalar::Util 'blessed', 'weaken', 'looks_like_number';
+use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
 
-our $VERSION   = '0.72';
+our $VERSION   = '0.75_01';
 our $AUTHORITY = 'cpan:STEVAN';
 
 use base 'Moose::Meta::Method',
-         'Class::MOP::Method::Generated';
+         'Class::MOP::Method::Constructor';
 
 sub new {
     my $class   = shift;
@@ -25,16 +25,12 @@ sub new {
         || $class->throw_error("You must supply the package_name and name parameters $Class::MOP::Method::UPGRADE_ERROR_TEXT");
 
     my $self = bless {
-        # from our superclass
         'body'          => undef, 
         'package_name'  => $options{package_name},
         'name'          => $options{name},
-        # specific to this subclass
         'options'       => $options{options},
-        'meta_instance' => $meta->get_meta_instance,
-        'attributes'    => [ $meta->compute_all_applicable_attributes ],
-        # ...
         'associated_metaclass' => $meta,
+        '_expected_method_class' => $options{_expected_method_class} || 'Moose::Object',
     } => $class;
 
     # we don't want this creating
@@ -42,98 +38,19 @@ sub new {
     # needed
     weaken($self->{'associated_metaclass'});
 
-    $self->initialize_body;
+    $self->_initialize_body;
 
     return $self;
 }
 
-sub can_be_inlined {
-    my $self      = shift;
-    my $metaclass = $self->associated_metaclass;
-
-    my $expected_class = $self->_expected_constructor_class;
-
-    # If any of our parents have been made immutable, we are okay to
-    # inline our own new method. The assumption is that an inlined new
-    # method provided by a parent does not actually get used by
-    # children anyway.
-    for my $meta (
-        grep { $_->is_immutable }
-        map  { ( ref $metaclass )->initialize($_) }
-        grep { $_ ne $expected_class }
-        $metaclass->linearized_isa
-        ) {
-        my $transformer = $meta->get_immutable_transformer;
-
-        # This is actually a false positive if we're in a subclass of
-        # this class, _and_ the expected class is not overridden (but
-        # should be), and the real expected class is actually
-        # immutable itself (see Fey::Object::Table for an example of
-        # how this can happen). I'm not sure how to actually handle
-        # that case, since it's effectively a bug in the subclass (for
-        # not overriding _expected_constructor_class).
-        return 1 if $transformer->inlined_constructor;
-    }
-
-    if ( my $constructor = $metaclass->find_method_by_name( $self->name ) ) {
-        my $class = $self->associated_metaclass->name;
-
-        if ( $constructor->body != $expected_class->can('new') ) {
-            my $warning
-                = "Not inlining a constructor for $class since it is not"
-                . " inheriting the default $expected_class constructor\n"
-                . "If you are certain you don't need to inline your"
-                . " constructor, specify inline_constructor => 0 in your"
-                . " call to $class->meta->make_immutable\n";
-
-            $warning .= " (constructor has method modifiers which would be lost if it were inlined)\n"
-                if $constructor->isa('Class::MOP::Method::Wrapped');
-
-            warn $warning;
-
-            return 0;
-        }
-        else {
-            return 1;
-        }
-    }
-
-    # This would be a rather weird case where we have no constructor
-    # in the inheritance chain.
-    return 1;
-}
-
 # This is here so can_be_inlined can be inherited by MooseX modules.
 sub _expected_constructor_class {
     return 'Moose::Object';
 }
 
-## accessors
-
-sub meta_instance { (shift)->{'meta_instance'} }
-sub attributes    { (shift)->{'attributes'}    }
-
 ## method
 
-sub _generate_params {
-  my ($self, $var, $class_var) = @_;
-  "my $var = " . $self->_generate_BUILDARGS($class_var, '@_') . ";\n";
-}
-
-sub _generate_instance {
-  my ($self, $var, $class_var) = @_;
-  "my $var = " . $self->meta_instance->inline_create_instance($class_var) 
-               . ";\n";
-}
-
-sub _generate_slot_initializers {
-    my ($self) = @_;
-    return (join ";\n" => map {
-        $self->_generate_slot_initializer($_)
-    } 0 .. (@{$self->attributes} - 1)) . ";\n";
-}
-
-sub initialize_body {
+sub _initialize_body {
     my $self = shift;
     # TODO:
     # the %options should also include a both
@@ -169,7 +86,7 @@ sub initialize_body {
     # because the inlined code is using the index of the attributes
     # to determine where to find the type constraint
 
-    my $attrs = $self->attributes;
+    my $attrs = $self->_attributes;
 
     my @type_constraints = map {
         $_->can('type_constraint') ? $_->type_constraint : undef
@@ -192,6 +109,24 @@ sub initialize_body {
     $self->{'body'} = $code;
 }
 
+sub _generate_params {
+    my ( $self, $var, $class_var ) = @_;
+    "my $var = " . $self->_generate_BUILDARGS( $class_var, '@_' ) . ";\n";
+}
+
+sub _generate_instance {
+    my ( $self, $var, $class_var ) = @_;
+    "my $var = "
+        . $self->_meta_instance->inline_create_instance($class_var) . ";\n";
+}
+
+sub _generate_slot_initializers {
+    my ($self) = @_;
+    return (join ";\n" => map {
+        $self->_generate_slot_initializer($_)
+    } 0 .. (@{$self->_attributes} - 1)) . ";\n";
+}
+
 sub _generate_BUILDARGS {
     my ( $self, $class, $args ) = @_;
 
@@ -222,8 +157,8 @@ sub _generate_BUILDALL {
 sub _generate_triggers {
     my $self = shift;
     my @trigger_calls;
-    foreach my $i ( 0 .. $#{ $self->attributes } ) {
-        my $attr = $self->attributes->[$i];
+    foreach my $i ( 0 .. $#{ $self->_attributes } ) {
+        my $attr = $self->_attributes->[$i];
 
         next unless $attr->can('has_trigger') && $attr->has_trigger;
 
@@ -239,13 +174,12 @@ sub _generate_triggers {
             . $i
             . ']->trigger->('
             . '$instance, '
-            . $self->meta_instance->inline_get_slot_value(
+            . $self->_meta_instance->inline_get_slot_value(
                   '$instance',
                   $attr->name,
               )
             . ', '
-            . '$attrs->['
-            . $i . ']' . ');' . "\n}";
+            . ');' . "\n}";
     }
 
     return join ";\n" => @trigger_calls;
@@ -255,7 +189,7 @@ sub _generate_slot_initializer {
     my $self  = shift;
     my $index = shift;
 
-    my $attr = $self->attributes->[$index];
+    my $attr = $self->_attributes->[$index];
 
     my @source = ('## ' . $attr->name);
 
@@ -334,7 +268,7 @@ sub _generate_slot_assignment {
     }
     else {
         $source = (
-            $self->meta_instance->inline_set_slot_value(
+            $self->_meta_instance->inline_set_slot_value(
                 '$instance',
                 $attr->name,
                 $value
@@ -347,7 +281,7 @@ sub _generate_slot_assignment {
     if ($is_moose && $attr->is_weak_ref) {
         $source .= (
             "\n" .
-            $self->meta_instance->inline_weaken_slot_value(
+            $self->_meta_instance->inline_weaken_slot_value(
                 '$instance',
                 $attr->name
             ) .
@@ -431,6 +365,11 @@ provides additional Moose-specific functionality
 To understand this class, you should read the the
 L<Class::MOP::Class::Constructor> documentation as well.
 
+=head1 INHERITANCE
+
+C<Moose::Meta::Method::Constructor> is a subclass of
+L<Moose::Meta::Method> I<and> L<Class::MOP::Method::Constructor>.
+
 =head1 METHODS
 
 =over 4