X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FMoo%2FObject.pm;h=70daca43c49907cd93e18c9f01b55c99fb2a512b;hb=a17be455d30de29a1979c1bececb5419ca3a672a;hp=f62bc351e5aea46193100edc3a82c5ee8e81a712;hpb=1eba910c9cdaf6560b50f9ac5d6033bde4e84c94;p=gitmo%2FMoo.git diff --git a/lib/Moo/Object.pm b/lib/Moo/Object.pm index f62bc35..70daca4 100644 --- a/lib/Moo/Object.pm +++ b/lib/Moo/Object.pm @@ -18,6 +18,25 @@ sub new { }; } +sub BUILDARGS { + my $class = shift; + if ( scalar @_ == 1 ) { + unless ( defined $_[0] && ref $_[0] eq 'HASH' ) { + die "Single parameters to new() must be a HASH ref" + ." data => ". $_[0]; + } + return { %{ $_[0] } }; + } + elsif ( @_ % 2 ) { + warn "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 {@_}; + } +} + sub BUILDALL { my $self = shift; $self->${\(($BUILD_MAKER ||= do {