Bolts::Artifact - Tools for resolving an artifact value
version 0.143171
use Bolts; my $meta = Bolts::Bag->start_bag; my $artifact = Bolts::Artifact->new( meta_locator => $meta, name => 'key', blueprint => [ 'blueprint', 'factory', { class => 'MyApp::Thing', } ], scope => [ 'scope', 'singleton' ], infer => 'acquisition', parameters => { foo => [ 'blueprint', 'given', { isa => 'Str', } ], bar => value 42, }, );
This is the primary implementation of Bolts::Role::Artifact with all the features described in Bolts, including blueprint, scope, inferrence, injection, etc.
Bolts::Role::Artifact
Bolts::Role::Initializer
If provided with a references to the meta-locator for the bag to which the artifact is going to be attached, the "blueprint", "scope", and "injectors" attributes may be given as initializers rather than as objects.
Required. This sets the name of the artifact that is being created. This is passed through as part of scope resolution (Bolts::Scope) and blueprint construction (Bolts::Blueprint).
Required. This sets the Bolts::Blueprint used to construct the artifact.
Instead of passing the blueprint object in directly, you can provide an initializer in an array reference, similar to what you would pass to acquire to get the blueprint from the meta-locator, e.g.:
acquire
blueprint => bolts_init('blueprint', 'acquire', { path => [ 'foo' ], }),
If so, you must provide an "init_locator".
Required. This sets the Bolts::Scope used to manage the object's lifecycle.
Instead of passing the scope object in directly, you can provide an initializer in an array reference, similar to what you would pass to acquire to get the scope from the meta-locator, e.g.:
scope => bolts_init('scope', 'singleton'),
If so, you must provide a "init_locator".
This is a setting that tells the artifact what kind of inferrence to perform when inferring injectors from the blueprint. This may e set to one of the following:
Default. When this is set, no inferrence is performed. The injectors will be defined according to "dependencies" only.
This tells the artifact to infer the injection using the parameters passed to the call to "acquire" in Bolts::Role::Locator. When the object is acquired and resolved, the caller will need to pass through any options needed for building the object.
This tells the artifact to infer the injection using automatically acquired artifacts. The acquisition will happen from the bag containing the artifact with paths matching the name of the parameter.
Caution: The way this work is likely to be customizeable in the future and the default behavior may differ.
This is an internal setting, which has a reader method named is_inference_done and a writer named inference_is_done. Do not use the writer directly unless you know what you are doing. You cannot set this attribute during construction.
is_inference_done
inference_is_done
Normally, this is a true value after the automatic inference of injectors has been completed and false before.
This is an array of Bolts::Injectors, which are used to inject values into or after the construction process. Anything set here will take precedent over inferrence.
Instead of passing the array of injector objects in directly, you can provide an array of initializers, each as an array reference, similar to what you would pass to acquire for each to get each injector from the meta-locator, e.g.:
injector => [ bolts_init('injector', 'parameter_name', { key => 'foo', blueprint => bolts_init('blueprint', 'literal', { value => 42, }), }), ]
This is used to control the role the artifact constructed must impement. Usually, this is not set directly, but set by the bag instead as an additional control on bag contents.
This is used to control the type of the constructed artifact. Usually, this is not set directly, but set by the bag instead as an additional control on bag contents.
This performs the inference of "injectors" based upon the "infer" setting. This is called automatically when the artifact is resolved.
This is a helper for setting "does" and "isa". The bag that contains the artifact normally calls this to enforce type constriants on the artifact.
This is called during the resolution phase of Bolts::Role::Locator to either retrieve the object from the "scope" or construct a new object according to the "blueprint".
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.