| 1 | package Bolts::Injector::Store::Array; | ||||||||||
| 2 | 4 | $Bolts::Injector::Store::Array::VERSION = '0.143170'; | |||||||||
| 3 | # ABSTRACT: Inject dependencies into array artifacts | ||||||||||
| 4 | |||||||||||
| 5 | 4 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 4 | with 'Bolts::Injector'; | |||||||||
| 8 | |||||||||||
| 9 | |||||||||||
| 10 | 4 | has position => ( | |||||||||
| 11 | is => 'ro', | ||||||||||
| 12 | isa => 'Int', | ||||||||||
| 13 | predicate => 'has_position', | ||||||||||
| 14 | ); | ||||||||||
| 15 | |||||||||||
| 16 | |||||||||||
| 17 | sub post_inject_value { | ||||||||||
| 18 | 48 | ▶ | my ($self, $loc, $value, $array) = @_; | ||||||||
|
Subroutine
post_inject_value: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 19 | 48 | ▶ | if ($self->has_position) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 20 | 4 | $array->[ $self->position ] = $value; | |||||||||
| 21 | } | ||||||||||
| 22 | else { | ||||||||||
| 23 | 44 | push @{ $array }, $value; | |||||||||
| 24 | } | ||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 4 | __PACKAGE__->meta->make_immutable; | |||||||||
| 28 | |||||||||||
| 29 | __END__ | ||||||||||
| 30 | |||||||||||
| 31 | =pod | ||||||||||
| 32 | |||||||||||
| 33 | =encoding UTF-8 | ||||||||||
| 34 | |||||||||||
| 35 | =head1 NAME | ||||||||||
| 36 | |||||||||||
| 37 | Bolts::Injector::Store::Array - Inject dependencies into array artifacts | ||||||||||
| 38 | |||||||||||
| 39 | =head1 VERSION | ||||||||||
| 40 | |||||||||||
| 41 | version 0.143170 | ||||||||||
| 42 | |||||||||||
| 43 | =head1 SYNOPSIS | ||||||||||
| 44 | |||||||||||
| 45 | artifact thing1 => ( | ||||||||||
| 46 | builder => sub { [] }, | ||||||||||
| 47 | indexes => [ | ||||||||||
| 48 | 0 => value 'first', | ||||||||||
| 49 | 2 => value 'third', | ||||||||||
| 50 | 9 => value 'tenth', | ||||||||||
| 51 | ], | ||||||||||
| 52 | ); | ||||||||||
| 53 | |||||||||||
| 54 | my $counter = 0; | ||||||||||
| 55 | artifact thing2 => ( | ||||||||||
| 56 | builder => sub { [ 'foo', 'bar' ] }, | ||||||||||
| 57 | push => [ value 'baz', builder { ++$counter } ], | ||||||||||
| 58 | ); | ||||||||||
| 59 | |||||||||||
| 60 | =head1 DESCRIPTION | ||||||||||
| 61 | |||||||||||
| 62 | Inject values into an array during resolution by index or just push. | ||||||||||
| 63 | |||||||||||
| 64 | =head1 ROLES | ||||||||||
| 65 | |||||||||||
| 66 | =over | ||||||||||
| 67 | |||||||||||
| 68 | =item * | ||||||||||
| 69 | |||||||||||
| 70 | L<Bolts::Injector> | ||||||||||
| 71 | |||||||||||
| 72 | =back | ||||||||||
| 73 | |||||||||||
| 74 | =head1 ATTRIBUTES | ||||||||||
| 75 | |||||||||||
| 76 | =head2 position | ||||||||||
| 77 | |||||||||||
| 78 | If this attribute is set to a number, then the injection will happen at that index. If it is not set, this injector performs a push instead. | ||||||||||
| 79 | |||||||||||
| 80 | =head1 METHODS | ||||||||||
| 81 | |||||||||||
| 82 | =head2 post_inject_value | ||||||||||
| 83 | |||||||||||
| 84 | Performs the injection of values into an array by index or push. | ||||||||||
| 85 | |||||||||||
| 86 | =head1 AUTHOR | ||||||||||
| 87 | |||||||||||
| 88 | Andrew Sterling Hanenkamp <hanenkamp@cpan.org> | ||||||||||
| 89 | |||||||||||
| 90 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 91 | |||||||||||
| 92 | This software is copyright (c) 2014 by Qubling Software LLC. | ||||||||||
| 93 | |||||||||||
| 94 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 95 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 96 | |||||||||||
| 97 | =cut | ||||||||||