Bolts::Inference - This is the interface for inferring injectors from a blueprint
version 0.143171
package MyApp::Inference::Frobnicator; use Moose; with 'Bolts::Inference'; sub infer { my ($self, $blueprint) = @_; return unless $blueprint->ia('MyApp::Blueprint::Frobnicator'); my $type = $blueprint->type_of_thingamajig; my @parameters; if ($type eq 'foo') { push @parameters, { key => 'foo', inject_via => [ 'injector, 'setter' ], }; push @parameters, { key => 'bar', inject_via => [ 'injector', 'parameter_name' ], }; } elsif ($type eq 'bar') { push @parameters, { key => 'bar', inject_via => [ 'injector', 'setter' ], }; push @parameters, { key => 'foo', inject_via => [ 'injector', 'parameter_name' ], }; } else { die "cannot infer from type [$type]"; } }
Defines the interface for Bolts inferrers. An inferrer is an object that is able to examine a blueprint and from that blueprint determine what parameters, settings, etc. the artifact constructed by the blueprint needs or may accept.
my @parameters = $inferrer->infer($blueprint);
Given a blueprint, this must return a list of parameter descriptions, which are returned as a hash. Each element may contain the following keys:
This is the name to give the parameter for injection.
This is the full path to the injector to qcquire, found within the meta locator, usually Bolts::Meta::Locator, usually under the "injector" key.
This is the type constraint the injected value must adhere to.
This is the role type the injected value must adhere to.
This stats whether or not the parameter is required to complete the blueprint or not.
Notice that the blueprint is not determined by the inferer. This is handled by Bolts::Artifact instead, via the "infer" in Bolts::Artifact setting on the artifact in question.
Andrew Sterling Hanenkamp <hanenkamp@cpan.org>
This software is copyright (c) 2014 by Qubling Software LLC.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Bolts, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Bolts
CPAN shell
perl -MCPAN -e shell install Bolts
For more information on module installation, please visit the detailed CPAN module installation guide.