File Coverage

blib/lib/Search/GIN/Keys/Expand.pm
Criterion Covered Total %
statement 34 34 100.0
branch 3 4 75.0
condition 1 3 33.3
subroutine 11 11 100.0
pod 0 6 0.0
total 49 58 84.4


line stmt bran cond sub pod time code
1 4     4   1814 use strict;
  4         6  
  4         136  
2 4     4   15 use warnings;
  4         4  
  4         178  
3             package Search::GIN::Keys::Expand;
4             our $VERSION = '0.10';
5 4     4   15 use Moose::Role;
  4         6  
  4         25  
6 4     4   15547 use Carp qw(croak);
  4         8  
  4         254  
7 4     4   18 use namespace::autoclean;
  4         58  
  4         22  
8              
9             sub expand_keys {
10 23     23 0 30 my ( $self, @keys ) = @_;
11 23         31 return map { $self->expand_key($_) } @keys;
  24         42  
12             }
13              
14             sub expand_key {
15 82     82 0 94 my ( $self, $value, %args ) = @_;
16              
17 82 100       163 return $self->expand_key_string($value) if not ref $value;
18              
19 39         67 my $method = "expand_keys_" . lc ref($value);
20              
21 39 50 33     228 croak("Don't know how to expand $value in key") if $method =~ /::/ or not $self->can($method);
22              
23 39         72 return $self->$method($value);
24             }
25              
26             sub expand_key_prepend {
27 33     33 0 41 my ( $self, $prefix, @keys ) = @_;
28 33         42 return map { [ $prefix, @$_ ] } @keys;
  42         137  
29             }
30              
31             sub expand_key_string {
32 43     43 0 44 my ( $self, $str ) = @_;
33 43         100 return [ $str ];
34             }
35              
36             sub expand_keys_array {
37 18     18 0 18 my ( $self, $array ) = @_;
38 18         32 return map { $self->expand_key($_) } @$array;
  25         35  
39             }
40              
41             sub expand_keys_hash {
42 21     21 0 21 my ( $self, $hash ) = @_;
43              
44 33         63 return map {
45 21         50 $self->expand_key_prepend(
46             $_,
47             $self->expand_key($hash->{$_})
48             );
49             } keys %$hash;
50             }
51              
52             1;