1 package Object::Builder;
3 use Module::Runtime qw(use_module);
6 our $VERSION = '0.000001'; # 0.0.1
8 $VERSION = eval $VERSION;
11 is => 'rw', required => 1,
12 trigger => sub { shift->_clear_final_class },
16 is => 'rw', builder => 1,
17 trigger => sub { shift->_clear_final_class },
18 clearer => 'reset_roles',
21 sub _build_roles { [] }
23 has _final_class => (is => 'lazy', clearer => 1);
25 sub _build__final_class {
27 my $class = use_module($self->class);
28 if (my @roles = @{$self->roles}) {
30 return Moo::Role->create_class_with_roles($class, @roles);
36 after _clear_final_class => sub { shift->clear_object };
38 has constructor => (is => 'ro', default => sub { 'new' });
41 is => 'rw', builder => 1,
42 trigger => sub { shift->_clear_final_arguments },
43 clearer => 'reset_arguments',
46 sub _build_arguments { {} }
48 has argument_filter => (
49 is => 'rw', builder => 1,
50 trigger => sub { shift->_clear_final_arguments },
51 clearer => 'reset_argument_filter',
54 sub _build_argument_filter { sub { shift } }
56 has _final_arguments => (is => 'lazy', clearer => 1);
58 after _clear_final_arguments => sub { shift->_clear_object };
60 sub _build__final_arguments {
62 $self->argument_filter->($self->arguments);
65 has object => (is => 'lazy', clearer => 1);
69 $self->_final_class->${\$self->constructor}($self->_final_arguments);
76 Object::Builder - An object for building other objects.
84 mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
88 None yet - maybe this software is perfect! (ahahahahahahahahaha)
92 Copyright (c) 2012 the Object::Builder L</AUTHOR> and L</CONTRIBUTORS>
97 This library is free software and may be distributed under the same terms