File Coverage

blib/lib/Data/RuledCluster/Strategy/Key.pm
Criterion Covered Total %
statement 19 20 95.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 25 28 89.2


line stmt bran cond sub pod time code
1             package Data::RuledCluster::Strategy::Key;
2 3     3   2472 use strict;
  3         7  
  3         126  
3 3     3   15 use warnings;
  3         5  
  3         88  
4 3     3   1503 use parent 'Data::RuledCluster::Strategy';
  3         607  
  3         14  
5 3     3   150 use Data::Util qw(is_number neat);
  3         5  
  3         492  
6              
7             sub resolve {
8 8     8 0 14 my ( $class, $resolver, $node_or_cluster, $args ) = @_;
9              
10 8         41 my @keys = $class->keys_from_args($args);
11 8         15 my $key = shift @keys;
12              
13 8 50       35 unless ( is_number($key) ) {
14 0         0 Carp::croak(
15             sprintf('args has not key field or no number value (key: %s)', neat($key))
16             );
17             }
18              
19 8         28 my @nodes = $resolver->clusters($node_or_cluster);
20 8         21 my $resolved_node = $nodes[ $key % scalar @nodes ];
21              
22 8         28 return ($resolved_node, @keys);
23             }
24              
25             1;
26