From: Vyacheslav Matyukhin Date: Wed, 6 Jun 2012 20:15:41 +0000 (+0400) Subject: refactoring nested ifs X-Git-Tag: v0.091010~9 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=9832b4c84862ea35e44e10b809b70619421e8e7c;p=gitmo%2FMoo.git refactoring nested ifs --- diff --git a/lib/Method/Generate/Accessor.pm b/lib/Method/Generate/Accessor.pm index e203179..87f70eb 100644 --- a/lib/Method/Generate/Accessor.pm +++ b/lib/Method/Generate/Accessor.pm @@ -46,17 +46,15 @@ sub generate_method { if (exists $spec->{default}) { my $default = $spec->{default}; require Scalar::Util; - if (not ref $default) { + unless ( + ref $default + and ( + Scalar::Util::reftype $default eq 'CODE' + or Scalar::Util::blessed $default and $default->can('(&{}') + ) + ) { die "Invalid default $default"; } - elsif (Scalar::Util::reftype $default ne 'CODE') { - if (Scalar::Util::blessed $default) { - die "Invalid default $default" unless $default->can('(&{}'); - } - else { - die "Invalid default $default"; - } - } } my %methods;