From: Yuval Kogman Date: Thu, 26 Jun 2008 15:26:10 +0000 (+0000) Subject: avoid uninitialized warning on ->new(nonref) X-Git-Tag: 0_55~89^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=aa7472be179ab723bb3ef9d34c2120fd6908d964;p=gitmo%2FMoose.git avoid uninitialized warning on ->new(nonref) --- diff --git a/lib/Moose/Meta/Method/Constructor.pm b/lib/Moose/Meta/Method/Constructor.pm index 6c37c14..c0ae6a9 100644 --- a/lib/Moose/Meta/Method/Constructor.pm +++ b/lib/Moose/Meta/Method/Constructor.pm @@ -128,6 +128,7 @@ sub _generate_BUILDARGS { if ( $args eq '@_' and ( !$buildargs or $buildargs->body == \&Moose::Object::BUILDARGS ) ) { return join("\n", 'do {', + 'no warnings "uninitialized";', 'confess "Single parameters to new() must be a HASH ref"', ' if scalar @_ == 1 && defined $_[0] && ref($_[0]) ne q{HASH};', '(scalar @_ == 1) ? {%{$_[0]}} : {@_};', diff --git a/lib/Moose/Object.pm b/lib/Moose/Object.pm index 7fc09a7..15a6536 100644 --- a/lib/Moose/Object.pm +++ b/lib/Moose/Object.pm @@ -25,12 +25,13 @@ sub BUILDARGS { if (scalar @_ == 1) { if (defined $_[0]) { + no warnings 'uninitialized'; (ref($_[0]) eq 'HASH') || confess "Single parameters to new() must be a HASH ref"; return {%{$_[0]}}; + } else { + return {}; # FIXME this is compat behavior, but is it correct? } - - return {}; # FIXME this is compat behavior, but is it correct? } else { return {@_}; }