File Coverage

blib/lib/Bolts/Injector/Store/Array.pm
Criterion Covered Total %
statement 8 8 100.0
branch 2 2 100.0
condition n/a
subroutine 2 2 100.0
pod 1 1 100.0
total 13 13 100.0


line stmt bran cond sub pod time code
1             package Bolts::Injector::Store::Array;
2             $Bolts::Injector::Store::Array::VERSION = '0.142930';
3             # ABSTRACT: Inject dependencies into array artifacts
4              
5 4     4   2543 use Moose;
  4         6  
  4         22  
6              
7             with 'Bolts::Injector';
8              
9              
10             has position => (
11             is => 'ro',
12             isa => 'Int',
13             predicate => 'has_position',
14             );
15              
16              
17             sub post_inject_value {
18 20     20 1 28 my ($self, $loc, $value, $array) = @_;
19 20 100       611 if ($self->has_position) {
20 4         102 $array->[ $self->position ] = $value;
21             }
22             else {
23 16         23 push @{ $array }, $value;
  16         67  
24             }
25             }
26              
27             __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.142930
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