| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package Bread::Board::ConstructorInjection; | 
| 2 |  |  |  |  |  |  | our $AUTHORITY = 'cpan:STEVAN'; | 
| 3 |  |  |  |  |  |  | # ABSTRACT: service instantiating objects via a constructor | 
| 4 |  |  |  |  |  |  | $Bread::Board::ConstructorInjection::VERSION = '0.37'; | 
| 5 | 60 |  |  | 60 |  | 633992 | use Moose; | 
|  | 60 |  |  |  |  | 1440522 |  | 
|  | 60 |  |  |  |  | 529 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 | 60 |  |  | 60 |  | 409297 | use Try::Tiny; | 
|  | 60 |  |  |  |  | 154 |  | 
|  | 60 |  |  |  |  | 4195 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 | 60 |  |  | 60 |  | 3012 | use Bread::Board::Types; | 
|  | 60 |  |  |  |  | 154 |  | 
|  | 60 |  |  |  |  | 7039 |  | 
| 10 |  |  |  |  |  |  |  | 
| 11 |  |  |  |  |  |  | with 'Bread::Board::Service::WithConstructor', | 
| 12 |  |  |  |  |  |  | 'Bread::Board::Service::WithParameters', | 
| 13 |  |  |  |  |  |  | 'Bread::Board::Service::WithDependencies'; | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | has '+class' => (required => 1); | 
| 16 |  |  |  |  |  |  |  | 
| 17 |  |  |  |  |  |  | sub get { | 
| 18 |  |  |  |  |  |  | my $self = shift; | 
| 19 |  |  |  |  |  |  |  | 
| 20 |  |  |  |  |  |  | my $constructor = $self->constructor_name; | 
| 21 |  |  |  |  |  |  | $self->class->$constructor( %{ $self->params } ); | 
| 22 |  |  |  |  |  |  | } | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | __PACKAGE__->meta->make_immutable; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 60 |  |  | 60 |  | 483 | no Moose; 1; | 
|  | 60 |  |  |  |  | 151 |  | 
|  | 60 |  |  |  |  | 751 |  | 
| 27 |  |  |  |  |  |  |  | 
| 28 |  |  |  |  |  |  | __END__ | 
| 29 |  |  |  |  |  |  |  | 
| 30 |  |  |  |  |  |  | =pod | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | =encoding UTF-8 | 
| 33 |  |  |  |  |  |  |  | 
| 34 |  |  |  |  |  |  | =head1 NAME | 
| 35 |  |  |  |  |  |  |  | 
| 36 |  |  |  |  |  |  | Bread::Board::ConstructorInjection - service instantiating objects via a constructor | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | =head1 VERSION | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | version 0.37 | 
| 41 |  |  |  |  |  |  |  | 
| 42 |  |  |  |  |  |  | =head1 DESCRIPTION | 
| 43 |  |  |  |  |  |  |  | 
| 44 |  |  |  |  |  |  | This L<service|Bread::Board::Service> class instantiates objects by | 
| 45 |  |  |  |  |  |  | calling the constructor on a class. | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | This class consumes L<Bread::Board::Service::WithClass>, | 
| 48 |  |  |  |  |  |  | L<Bread::Board::Service::WithParameters>, | 
| 49 |  |  |  |  |  |  | L<Bread::Board::Service::WithDependencies>. | 
| 50 |  |  |  |  |  |  |  | 
| 51 |  |  |  |  |  |  | =head1 ATTRIBUTES | 
| 52 |  |  |  |  |  |  |  | 
| 53 |  |  |  |  |  |  | =head2 C<class> | 
| 54 |  |  |  |  |  |  |  | 
| 55 |  |  |  |  |  |  | Attribute provided by L<Bread::Board::Service::WithClass>. This | 
| 56 |  |  |  |  |  |  | service makes it a required attribute: you can't call a constructor if | 
| 57 |  |  |  |  |  |  | you don't have a class. | 
| 58 |  |  |  |  |  |  |  | 
| 59 |  |  |  |  |  |  | =head2 C<constructor_name> | 
| 60 |  |  |  |  |  |  |  | 
| 61 |  |  |  |  |  |  | Optional string, indicates the name of the class method to invoke to | 
| 62 |  |  |  |  |  |  | construct the object. If not provided, defaults to the constructor | 
| 63 |  |  |  |  |  |  | name obtained via L<Class::MOP::Class>, or C<new> if introspection | 
| 64 |  |  |  |  |  |  | does not work. | 
| 65 |  |  |  |  |  |  |  | 
| 66 |  |  |  |  |  |  | =head1 METHODS | 
| 67 |  |  |  |  |  |  |  | 
| 68 |  |  |  |  |  |  | =head2 C<get> | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | Calls the constructor (as indicated by L</constructor_name>) on the | 
| 71 |  |  |  |  |  |  | L</class>, passing all the L<service | 
| 72 |  |  |  |  |  |  | parameters|Bread::Board::Service/params> as a B<hash>. Returns | 
| 73 |  |  |  |  |  |  | whatever the constructor returned (hopefully a correctly-constructed | 
| 74 |  |  |  |  |  |  | object of the right class). | 
| 75 |  |  |  |  |  |  |  | 
| 76 |  |  |  |  |  |  | =head1 AUTHOR | 
| 77 |  |  |  |  |  |  |  | 
| 78 |  |  |  |  |  |  | Stevan Little <stevan@iinteractive.com> | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | =head1 BUGS | 
| 81 |  |  |  |  |  |  |  | 
| 82 |  |  |  |  |  |  | Please report any bugs or feature requests on the bugtracker website | 
| 83 |  |  |  |  |  |  | https://github.com/stevan/BreadBoard/issues | 
| 84 |  |  |  |  |  |  |  | 
| 85 |  |  |  |  |  |  | When submitting a bug or request, please include a test-file or a | 
| 86 |  |  |  |  |  |  | patch to an existing test-file that illustrates the bug or desired | 
| 87 |  |  |  |  |  |  | feature. | 
| 88 |  |  |  |  |  |  |  | 
| 89 |  |  |  |  |  |  | =head1 COPYRIGHT AND LICENSE | 
| 90 |  |  |  |  |  |  |  | 
| 91 |  |  |  |  |  |  | This software is copyright (c) 2019, 2017, 2016, 2015, 2014, 2013, 2011, 2009 by Infinity Interactive. | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | This is free software; you can redistribute it and/or modify it under | 
| 94 |  |  |  |  |  |  | the same terms as the Perl 5 programming language system itself. | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | =cut |