The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Bolts::Inference - This is the interface for inferring injectors from a blueprint

VERSION

version 0.143171

SYNOPSIS

    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]";
        }
    }

DESCRIPTION

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.

REQUIRED METHODS

infer

    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:

key

This is the name to give the parameter for injection.

inject_via

This is the full path to the injector to qcquire, found within the meta locator, usually Bolts::Meta::Locator, usually under the "injector" key.

isa

This is the type constraint the injected value must adhere to.

does

This is the role type the injected value must adhere to.

required

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.

AUTHOR

Andrew Sterling Hanenkamp <hanenkamp@cpan.org>

COPYRIGHT AND LICENSE

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.