From: Matt S Trout Date: Sat, 12 May 2012 00:29:38 +0000 (+0000) Subject: a bit more configurability X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=21dba240771bcb3fbac36708da4910553bd3d4ce;p=scpubgit%2FObject-Builder.git a bit more configurability --- diff --git a/lib/Object/Builder.pm b/lib/Object/Builder.pm index 2f27771..2cbe0e0 100644 --- a/lib/Object/Builder.pm +++ b/lib/Object/Builder.pm @@ -8,16 +8,20 @@ our $VERSION = '0.000001'; # 0.0.1 $VERSION = eval $VERSION; has class => ( - is => 'rw', required => 1, + is => 'rw', lazy => 1, builder => 1, trigger => sub { shift->_clear_final_class }, ); +sub _build_class { die "No default class set" } + has roles => ( - is => 'rw', builder => 1, + is => 'rw', lazy => 1, builder => 1, trigger => sub { shift->_clear_final_class }, clearer => 'reset_roles', ); +after reset_roles => sub { shift->_clear_final_class }; + sub _build_roles { [] } has _final_class => (is => 'lazy', clearer => 1); @@ -43,6 +47,8 @@ has arguments => ( clearer => 'reset_arguments', ); +after reset_arguments => sub { shift->_clear_final_arguments }; + sub _build_arguments { {} } has argument_filter => ( @@ -69,6 +75,16 @@ sub _build_object { $self->_final_class->${\$self->constructor}($self->_final_arguments); } +sub BUILD { + my ($self, $args) = @_; + unless ( + $args->{object} or $args->{class} + or ($self->can('_build_class') ne __PACKAGE__->can('_build_class') + ) { + die "No static object passed, and no class supplied or defaulted"; + } +} + 1; =head1 NAME