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

NAME

Bolts::Util - Utilities helpful for use with Bolts

VERSION

version 0.143171

SYNOPSIS

    use Bolts::Util qw( bolts_init locator_for meta_locator_for );

    my $loc   = locator_for($bag);
    my $thing = $loc->acquire('path', 'to', 'thing');

    my $metaloc = meta_locator_for($bag);
    my $blueprint = $metaloc->acquire('blueprint', 'factory', {
        class  => 'MyApp::Thing',
        method => 'fetch',
    });

    # See Bolts::Role::Initializer for a better synopsis
    my $obj = MyApp::Thing->new(
        foo => bolts_init('path', 'to', 'foo'),
    );

DESCRIPTION

This provides some helpful utility methods for use with Bolts.

EXPORTED FUNCTIONS

artifact

    my %artifact = %{ artifact($bag, $name, %definition) };

    # For example:
    my %artifact = %{ artifact($bag, thing => ( class => 'MyApp::Thing' ) ) };

This contains the internal implementation for building Bolt::Artifact objects used by the sugar methods in Bolts and Bolts::Role. See the documentation there for more details on how to call it.

The $bag must be the metaclass or reference to which the artifact is being attached. The $name is the name to give the artifact and teh %definition is the remainder of the definition.

This function returns a hash with a single key, which is the name of the artifact. The value on that key is an object that implements Bolts::Role::Artifact.

locator_for

    my $loc = locator_for($bag);

Given a bag, it will return a Bolts::Role::Locator for acquiring artifacts from it. If the bag provides it's own locator, the bag will be returned. If it doesn't (e.g., if it's a hash or an array or just some other object that doesn't have a locator built-in), then a new locator will be built to locate within the bag and returned on the first call. Subsequent calls using the same reference will return the same locator object.

meta_locator_for

    my $metaloc = meta_locator_for($bag);

Attempts to find the meta locator for the bag. It returns a Bolts::Role::Locator that is able to return artifacts used to manage a collection of bolts bags and artifacts. If the bag itself does not have such a locator associated with it, one is constructed using the "$Bolts::GLOBAL_FALLBACK_META_LOCATOR" in Bolts class, which is Bolts::Meta::Locator by default. After the first call, the object created the first time for each reference will be reused.

bolts_init

    my $init = bolts_init(@path, \%params);

This is shorthand for:

    my $init = Bolts::Meta::Initializer->new(@path, \%params);

This returns an initializer object that may be used with Bolts::Role::Initializer to automatically initialize attributes from a built-in locator.

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.