X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FObject%2FBuilder.pm;fp=lib%2FObject%2FBuilder.pm;h=44e78b3dae88f4662ded19a1561f5100698702a5;hb=c789b081041933962a6ac370269b4a361d686a68;hp=96ac63576cce4490aa1b82fd877d97c28d835c9d;hpb=322a6ab39f4b0d0aa40bc2dd8be1b25b58496702;p=scpubgit%2FObject-Builder.git 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"; }