File Coverage

blib/lib/Ref/Store/Feature/KeyTyped.pm
Criterion Covered Total %
statement 41 43 95.3
branch 3 6 50.0
condition 1 3 33.3
subroutine 10 10 100.0
pod 0 1 0.0
total 55 63 87.3


line stmt bran cond sub pod time code
1             package Ref::Store::Feature::KeyTyped;
2 2     2   14 use strict;
  2         4  
  2         50  
3 2     2   8 use warnings;
  2         4  
  2         55  
4             our $AUTOLOAD;
5 2     2   9 use Log::Fu;
  2         3  
  2         13  
6 2     2   88 use Carp qw(confess);
  2         3  
  2         63  
7 2     2   9 use Data::Dumper;
  2         4  
  2         53  
8 2     2   8 use Ref::Store::Common;
  2         4  
  2         288  
9              
10             $SIG{__DIE__} = \&confess;
11             BEGIN {
12 2     2   8 foreach my $fname (qw(
13             store
14             fetch
15             purgeby
16             unlink
17             lexists
18             )) {
19 10         21 my $wrapname = $fname . "_kt";
20             {
21 2     2   12 no strict 'refs';
  2         4  
  2         255  
  10         12  
22 10         159 *{$wrapname} = sub {
23 6     6   127 my @args = @_;
24 6         14 my $self = $args[0];
25 6         14 my ($ktarg) = splice(@args, 2, 1);
26 6         28 my $pfix = $self->get_kt_prefix($ktarg, "$fname: Can't find prefix ($ktarg)!");
27 6         12 my $orig = $args[1];
28 6 50       15 die "Must have defined key!" unless defined $orig;
29 6 50       15 if(!ref $orig) {
30 6         15 $orig = $pfix . HR_PREFIX_DELIM . $orig;
31 6         10 $args[1] = $orig;
32             } else {
33 0         0 log_warn("Using keytypes with object key has no effect");
34             }
35 6         11 shift @args;
36 6         28 return $self->$fname(@args);
37 10         40 };
38             }
39             }
40             }
41              
42             sub get_kt_prefix {
43 6     6 0 14 my ($self,$kt,$do_die) = @_;
44 6         16 my $ret = $self->keytypes->{$kt};
45 6 50 33     19 if((!$ret) && $do_die) {
46 0         0 die $do_die;
47             }
48 6         14 return $ret;
49             }
50             1;