lib/Set/Associate/RefillItems.pm

filter: Statementstmt 100% 34 / 34 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 97.9% 48 / 49 CC 3 SCAR 3.1
CC
3
Cov
97%
linear
2.0
shuffle
2.0
BEGIN
1.0
CRAP 1.4
« lib/Set/Associate.pm ↑ Summary lib/Set/Associate/NewKey/LinearWrap.pm »
1 11 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 11 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 11 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Set::Associate::RefillItems;
6  
7 # ABSTRACT: Pool re-population methods
8  
9 11 our $VERSION = '0.004000';
10  
11 11 our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12  
13 11 ▶use Moose qw( has with );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 11 ▶use MooseX::AttributeShortcuts;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 11 ▶use Set::Associate::Utils qw( _warn_nonmethod );
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18  
19  
20  
21  
22  
23  
24  
25  
26 11 has name => (
27 isa => Str =>,
28 is => rwp =>,
29 required => 1,
30 );
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44 11 has code => (
45 isa => CodeRef =>,
46 is => rwp =>,
47 required => 1,
48 traits => ['Code'],
49 handles => {
50 get_all => execute_method =>,
51 },
52 );
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66 11 has items => (
67 isa => ArrayRef =>,
68 is => rwp =>,
69 predicate => has_items =>,
70 );
71  
72 11 with 'Set::Associate::Role::RefillItems' => { can_get_all => 1, };
73  
74 11 __PACKAGE__->meta->make_immutable;
75  
76 11 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99 sub linear {
100 4 ▶ shift @_ unless _warn_nonmethod( $_[0], __PACKAGE__, 'linear' );
Subroutine linear: called CC=2 SCAR=7.1
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless _warn_nonmethod($_[0], __PACKAGE__, "linear") 4 0 4
101 4 require Set::Associate::RefillItems::Linear;
102 4 return Set::Associate::RefillItems::Linear->new(@_);
103 }
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127 sub shuffle {
128 2 ▶ shift @_ unless _warn_nonmethod( $_[0], __PACKAGE__, 'shuffle' );
Subroutine shuffle: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
unless _warn_nonmethod($_[0], __PACKAGE__, "shuffle") 1 1 2
129 2 require Set::Associate::RefillItems::Shuffle;
130 2 return Set::Associate::RefillItems::Shuffle->new(@_);
131 }
132  
133 11 1;
134  
135 __END__
136  
137 =pod
138  
139 =encoding UTF-8
140  
141 =head1 NAME
142  
143 Set::Associate::RefillItems - Pool re-population methods
144  
145 =head1 VERSION
146  
147 version 0.004000
148  
149 =head1 DESCRIPTION
150  
151 This class implements a generalized interface for creating objects which populate pools.
152  
153 What you're mostly interested in are L</CLASS METHODS>, which are shorthand (somewhat) for loading and constructing
154 many of the C<Set::Associate::RefillItems::*> family.
155  
156 However, if your code needs to design its own version on the fly, this interface should work:
157  
158 my $populator = Set::Associate::RefillItems->new(
159 name => 'foo',
160 items => [ .... ],
161 code => sub {
162 my ( $self, $sa ) = @_;
163 ....
164 },
165 );
166 my $sa = Set::Associate->new(
167 on_item_empty => $populator ,
168 ...
169 );
170  
171 =head1 CONSTRUCTOR ARGUMENTS
172  
173 =head2 name
174  
175 required Str
176  
177 =head2 code
178  
179 required CodeRef
180  
181 =head2 items
182  
183 required ArrayRef
184  
185 =head1 CLASS METHODS
186  
187 =head2 linear
188  
189 Populate from C<items> each time.
190  
191 See L<< C<Set::Associate::B<RefillItems::Linear>>|Set::Associate::RefillItems::Linear >> for details.
192  
193 my $sa = Set::Associate->new(
194 ...
195 on_items_empty => Set::Associate::RefillItems->linear( items => [ ... ])
196 );
197  
198 or ...
199  
200 use Set::Associate::RefillItems::Linear;
201 my $sa = Set::Associate->new(
202 ...
203 on_items_empty => Set::Associate::RefillItems::Linear->new( items => [ ... ])
204 );
205  
206 =head2 shuffle
207  
208 Populate with a shuffled version of C<items>
209  
210 See L<< C<Set::Associate::B<RefillItems::Shuffle>>|Set::Associate::RefillItems::Shuffle >> for details.
211  
212 my $sa = Set::Associate->new(
213 ...
214 on_items_empty => Set::Associate::RefillItems->shuffle( items => [ ... ]);
215 );
216  
217 or ...
218  
219 use Set::Associate::RefillItems::Shuffle;
220 my $sa = Set::Associate->new(
221 ...
222 on_items_empty => Set::Associate::RefillItems::Shuffle->new( items => [ ... ])
223 );
224  
225 =head1 ATTRIBUTES
226  
227 =head2 name
228  
229 =head2 code
230  
231 =head2 items
232  
233 =head1 ATTRIBUTE HANDLES
234  
235 =head2 get_all
236  
237 Invokes C<Trait:Code/execute_method> on L</code>
238  
239 =head2 has_items
240  
241 Predicate method for L</items>
242  
243 =head1 AUTHOR
244  
245 Kent Fredric <kentnl@cpan.org>
246  
247 =head1 COPYRIGHT AND LICENSE
248  
249 This software is copyright (c) 2015 by Kent Fredric <kentfredric@gmail.com>.
250  
251 This is free software; you can redistribute it and/or modify it under
252 the same terms as the Perl 5 programming language system itself.
253  
254 =cut
« lib/Set/Associate.pm ↑ Summary lib/Set/Associate/NewKey/LinearWrap.pm »