From: Matt S Trout Date: Mon, 25 Mar 2013 20:51:21 +0000 (+0000) Subject: slightly more complicated resolver X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=c789b081041933962a6ac370269b4a361d686a68;p=scpubgit%2FObject-Builder.git slightly more complicated resolver --- diff --git a/lib/Object/Builder.pm b/lib/Object/Builder.pm index 96ac635..44e78b3 100644 --- a/lib/Object/Builder.pm +++ b/lib/Object/Builder.pm @@ -42,6 +42,13 @@ has _final_class => (is => 'lazy', clearer => 1); sub _build__final_class { my ($self) = @_; + + # This path will only be taken if class => undef was intentionally passed + # to our constructor; this allows for a subref constructor which of course + # doesn't necessarily need a class at all. + + return unless defined($self->class); + my $class = use_module($self->class); if (my @roles = $self->_role_list) { require Moo::Role; @@ -90,11 +97,14 @@ sub _resolve { # [ $x ] -> $x # [ $inv, 'x', 'y' ] -> $inv->x->y - # [ $inv, [ 'x', 'y' ], 'z' ] -> $inv->x('y')->z + # [ $inv, [ 'x', [ 'y' ] ], 'z' ] -> $inv->x('y')->z + # [ $inv, [ 'x', [ $other, 'y' ] ], 'z' ] -> $inv->x($other->y)->z + + no warnings 'once'; # $a return reduce { my ($meth, @arg) = (ref($b) eq 'ARRAY' ? @$b : $b); - $a->$meth(@arg); + $a->$meth(map $self->_resolve($_), @arg); } @$to_resolve; } @@ -113,8 +123,8 @@ sub fresh_object { sub BUILD { my ($self, $args) = @_; unless ( - $args->{object} or $args->{class} - or ($self->can('_build_class') ne __PACKAGE__->can('_build_class') + $args->{object} or exists $args->{class} + or ($self->can('_build_class') ne __PACKAGE__->can('_build_class')) ) { die "No static object passed, and no class supplied or defaulted"; }