some changes to work the next Moose, making constructor inlining work
[gitmo/MooseX-Singleton.git] / lib / MooseX / Singleton / Meta / Method / Constructor.pm
index 4c866e9..e95e318 100644 (file)
@@ -4,7 +4,7 @@ use Moose;
 
 extends 'Moose::Meta::Method::Constructor';
 
-sub intialize_body {
+sub initialize_body {
     my $self = shift;
     # TODO:
     # the %options should also include a both
@@ -22,14 +22,15 @@ sub intialize_body {
     $source .= "\n" . 'return $class->Moose::Object::new(@_)';
     $source .= "\n" . '    if $class ne \'' . $self->associated_metaclass->name . '\';';
 
-    $source .= "\n" . 'my %params = (scalar @_ == 1) ? %{$_[0]} : @_;';
+    $source .= "\n" . 'my $params = ' . $self->_generate_BUILDARGS('$class', '@_');
 
-    $source .= "\n" . 'my $instance = ' . $self->meta_instance->inline_create_instance('$class');
+    $source .= ";\n" . 'my $instance = ' . $self->meta_instance->inline_create_instance('$class');
 
     $source .= ";\n" . (join ";\n" => map {
         $self->_generate_slot_initializer($_)
     } 0 .. (@{$self->attributes} - 1));
 
+    $source .= ";\n" . $self->_generate_triggers();
     $source .= ";\n" . $self->_generate_BUILDALL();
 
     $source .= ";\n" . 'return ${$existing} = $instance';
@@ -38,6 +39,8 @@ sub intialize_body {
 
     my $code;
     {
+        my $meta = $self;
+
         # NOTE:
         # create the nessecary lexicals
         # to be picked up in the eval
@@ -61,9 +64,16 @@ sub intialize_body {
         } @type_constraints;
 
         $code = eval $source;
-        confess "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@" if $@;
+        $self->throw_error(
+            "Could not eval the constructor :\n\n$source\n\nbecause :\n\n$@",
+            error => $@, data => $source )
+            if $@;
     }
-    $self->{'&!body'} = $code;
+    $self->{'body'} = $code;
+}
+
+sub _expected_constructor_class {
+    return 'MooseX::Singleton::Object';
 }
 
 no Moose;