Fetching contributors…
Cannot retrieve contributors at this time
58 lines (38 sloc) 1.47 KB
package Bread::Board::ConstructorInjection;
# ABSTRACT: service instantiating objects via a constructor
use Moose;
use Try::Tiny;
use Bread::Board::Types;
with 'Bread::Board::Service::WithConstructor',
has '+class' => (required => 1);
sub get {
my $self = shift;
my $constructor = $self->constructor_name;
$self->class->$constructor( %{ $self->params } );
no Moose; 1;
This L<service|Bread::Board::Service> class instantiates objects by
calling the constructor on a class.
This class consumes L<Bread::Board::Service::WithClass>,
=attr C<class>
Attribute provided by L<Bread::Board::Service::WithClass>. This
service makes it a required attribute: you can't call a constructor if
you don't have a class.
=attr C<constructor_name>
Optional string, indicates the name of the class method to invoke to
construct the object. If not provided, defaults to the constructor
name obtained via L<Class::MOP::Class>, or C<new> if introspection
does not work.
=method C<get>
Calls the constructor (as indicated by L</constructor_name>) on the
L</class>, passing all the L<service
parameters|Bread::Board::Service/params> as a B<hash>. Returns
whatever the constructor returned (hopefully a correctly-constructed
object of the right class).