line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Data::RuledCluster::Strategy::List; |
2
|
2
|
|
|
2
|
|
1729
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
77
|
|
3
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
65
|
|
4
|
2
|
|
|
2
|
|
1753
|
use parent 'Data::RuledCluster::Strategy'; |
|
2
|
|
|
|
|
616
|
|
|
2
|
|
|
|
|
10
|
|
5
|
2
|
|
|
2
|
|
69
|
use Carp (); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
33
|
|
6
|
2
|
|
|
2
|
|
8
|
use Data::Util qw(is_hash_ref is_array_ref); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
645
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub resolve { |
9
|
27
|
|
|
27
|
0
|
48
|
my ($class, $resolver, $node_or_cluster, $args) = @_; |
10
|
|
|
|
|
|
|
|
11
|
27
|
|
|
|
|
82
|
my @keys = $class->keys_from_args($args); |
12
|
27
|
|
|
|
|
39
|
my $key = shift @keys; |
13
|
|
|
|
|
|
|
|
14
|
27
|
100
|
|
|
|
69
|
if ( not exists $args->{list_map} ) { |
15
|
15
|
50
|
33
|
|
|
87
|
if ( not exists $args->{strategy_config} && is_hash_ref( $args->{strategy_config} ) ) { |
16
|
0
|
|
|
|
|
0
|
Carp::croak('strategy_config is not exists or is not hash ref'); |
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
|
19
|
15
|
|
|
|
|
22
|
my $strategy_config = $args->{strategy_config}; |
20
|
39
|
|
|
|
|
46
|
$args->{list_map} = +{ |
21
|
|
|
|
|
|
|
map { |
22
|
42
|
|
|
|
|
78
|
my $node = $_; |
23
|
39
|
|
|
|
|
33
|
map { $_ => $node } @{ $args->{strategy_config}->{$node} } |
|
75
|
|
|
|
|
183
|
|
|
39
|
|
|
|
|
65
|
|
24
|
|
|
|
|
|
|
} |
25
|
15
|
|
|
|
|
32
|
grep { length $_ > 0 } |
26
|
|
|
|
|
|
|
keys %$strategy_config |
27
|
|
|
|
|
|
|
}; |
28
|
15
|
100
|
|
|
|
51
|
if ( exists $strategy_config->{""} ) { |
29
|
3
|
|
33
|
|
|
13
|
$args->{list_fallback} ||= $strategy_config->{""}; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
27
|
50
|
66
|
|
|
98
|
if ( !exists $args->{list_fallback} && !exists $args->{list_map}->{$key} ) { |
34
|
0
|
|
|
|
|
0
|
Carp::croak(sprintf("Not exists fallback, The key '%d' has not route", $key )); |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
27
|
|
|
|
|
25
|
my $resolved_node; |
38
|
27
|
100
|
|
|
|
53
|
if ( exists $args->{list_map}->{$key} ) { |
39
|
25
|
|
|
|
|
38
|
$resolved_node = $args->{list_map}{$key}; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
else { |
42
|
2
|
|
|
|
|
4
|
$resolved_node = $args->{list_fallback}; |
43
|
2
|
|
|
|
|
4
|
unshift( @keys, $key ); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
27
|
|
|
|
|
87
|
return ( $resolved_node, @keys ); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |
50
|
|
|
|
|
|
|
|