| 1 | use 5.006; | ||
| 2 | use strict; | ||
| 3 | use warnings; | ||
| 4 | |||
| 5 | package Set::Associate::RefillItems::Shuffle; | ||
| 6 | |||
| 7 | # ABSTRACT: a refill method that replenishes the cache with a shuffled list | ||
| 8 | |||
| 9 | our $VERSION = '0.004000'; | ||
| 10 | |||
| 11 | our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY | ||
| 12 | |||
| 13 | use Moose qw( with has ); | ||
| 14 | |||
| 15 | with 'Set::Associate::Role::RefillItems' => { can_get_all => 1, }; | ||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | |||
| 20 | |||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | has items => ( isa => 'ArrayRef', is => 'rw', required => 1 ); | ||
| 26 | |||
| 27 | __PACKAGE__->meta->make_immutable; | ||
| 28 | |||
| 29 | no Moose; | ||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | |||
| 36 | |||
| 37 | sub name { 'shuffle' } | ||
| 38 | |||
| 39 | use List::Util qw( shuffle ); | ||
| 40 | |||
| 41 | |||
| 42 | |||
| 43 | |||
| 44 | |||
| 45 | |||
| 46 | |||
| 47 | sub get_all { return shuffle( @{ $_[0]->items } ) } | ||
| 48 | |||
| 49 | 1; | ||
| 50 | |||
| 51 | __END__ | ||
| 52 | |||
| 53 | =pod | ||
| 54 | |||
| 55 | =encoding UTF-8 | ||
| 56 | |||
| 57 | =head1 NAME | ||
| 58 | |||
| 59 | Set::Associate::RefillItems::Shuffle - a refill method that replenishes the cache with a shuffled list | ||
| 60 | |||
| 61 | =head1 VERSION | ||
| 62 | |||
| 63 | version 0.004000 | ||
| 64 | |||
| 65 | =head1 CONSTRUCTOR ARGUMENTS | ||
| 66 | |||
| 67 | =head2 items | ||
| 68 | |||
| 69 | required ArrayRef | ||
| 70 | |||
| 71 | =head1 METHODS | ||
| 72 | |||
| 73 | =head2 name | ||
| 74 | |||
| 75 | The name of this refill method ( C<shuffle> ) | ||
| 76 | |||
| 77 | =head2 get_all | ||
| 78 | |||
| 79 | Get a new copy of C<items> in shuffled form. | ||
| 80 | |||
| 81 | =head1 ATTRIBUTES | ||
| 82 | |||
| 83 | =head2 items | ||
| 84 | |||
| 85 | =head1 AUTHOR | ||
| 86 | |||
| 87 | Kent Fredric <kentnl@cpan.org> | ||
| 88 | |||
| 89 | =head1 COPYRIGHT AND LICENSE | ||
| 90 | |||
| 91 | This software is copyright (c) 2015 by Kent Fredric <kentfredric@gmail.com>. | ||
| 92 | |||
| 93 | This is free software; you can redistribute it and/or modify it under | ||
| 94 | the same terms as the Perl 5 programming language system itself. | ||
| 95 | |||
| 96 | =cut |