Add explicit check for odd number of args to new and give a useful warning
[gitmo/Moose.git] / lib / Moose / Object.pm
index b8f02c9..1896b06 100644 (file)
@@ -4,6 +4,7 @@ package Moose::Object;
 use strict;
 use warnings;
 
+use Carp ();
 use Devel::GlobalDestruction ();
 use MRO::Compat ();
 use Scalar::Util ();
@@ -35,6 +36,12 @@ sub BUILDARGS {
         }
         return { %{ $_[0] } };
     }
+    elsif ( @_ % 2 ) {
+        Carp::carp(
+            "The new() method for $class expects a hash reference or a key/value list."
+                . " You passed an odd number of arguments" );
+        return { @_, undef };
+    }
     else {
         return {@_};
     }