File Coverage

blib/lib/Set/Associate/NewKey/RandomPick.pm
Criterion Covered Total %
statement 15 16 93.7
branch n/a
condition n/a
subroutine 6 7 85.7
pod 2 2 100.0
total 23 25 92.0


line stmt bran cond sub pod time code
1 4     4   1094 use 5.006;
  4         12  
2 4     4   24 use strict;
  4         6  
  4         142  
3 4     4   19 use warnings;
  4         6  
  4         351  
4              
5             package Set::Associate::NewKey::RandomPick;
6              
7             # ABSTRACT: Associate a key by randomly picking from a pool
8              
9             our $VERSION = '0.004001';
10              
11             our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY
12              
13 4     4   654 use Moose qw( with );
  4         378605  
  4         29  
14              
15             with 'Set::Associate::Role::NewKey' => { can_get_assoc => 1, };
16              
17             __PACKAGE__->meta->make_immutable;
18              
19 4     4   19537 no Moose;
  4         8  
  4         19  
20              
21              
22              
23              
24              
25              
26              
27 0     0 1 0 sub name { 'random_pick' }
28              
29              
30              
31              
32              
33              
34              
35              
36              
37              
38              
39             sub get_assoc {
40 14     14 1 437 return $_[1]->_items_cache_get( int( rand( $_[1]->_items_cache_count ) ) );
41             }
42              
43             1;
44              
45             __END__
46              
47             =pod
48              
49             =encoding UTF-8
50              
51             =head1 NAME
52              
53             Set::Associate::NewKey::RandomPick - Associate a key by randomly picking from a pool
54              
55             =head1 VERSION
56              
57             version 0.004001
58              
59             =head1 METHODS
60              
61             =head2 name
62              
63             The name of this key assignment method ( C<random_pick> )
64              
65             =head2 get_assoc
66              
67             Returns a value non-destructively at random from C<$set_assoc>'s pool.
68              
69             C<$new_key> is ignored with this method.
70              
71             my $value = $object->get_assoc( $set_assoc, $new_key );
72              
73             =head1 AUTHOR
74              
75             Kent Fredric <kentnl@cpan.org>
76              
77             =head1 COPYRIGHT AND LICENSE
78              
79             This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
80              
81             This is free software; you can redistribute it and/or modify it under
82             the same terms as the Perl 5 programming language system itself.
83              
84             =cut