File Coverage

blib/lib/KSx/IndexManager/Plugin/Partition.pm
Criterion Covered Total %
statement 15 30 50.0
branch 0 6 0.0
condition 0 4 0.0
subroutine 5 9 55.5
pod 2 2 100.0
total 22 51 43.1


line stmt bran cond sub pod time code
1 1     1   1166 use strict;
  1         2  
  1         35  
2 1     1   6 use warnings;
  1         2  
  1         41  
3              
4             package KSx::IndexManager::Plugin::Partition;
5              
6 1     1   5 use base qw(KSx::IndexManager::Plugin);
  1         1  
  1         91  
7             __PACKAGE__->mk_group_accessors(simple => qw(key value));
8              
9 1     1   7 use File::Spec;
  1         3  
  1         41  
10 1     1   992 use Carp::Clan qw(^KSx::IndexManager);
  1         2177  
  1         11  
11              
12             sub _value {
13 0     0     my ($plugin, $arg) = @_;
14 0 0         defined $arg->{$plugin->key} or
15             croak "missing partition key: " . $plugin->key;
16 0           return $arg->{$plugin->key};
17             }
18              
19             sub _value_method {
20 0     0     my ($plugin, $arg) = @_;
21 0 0         my $meth = $arg->can($plugin->key) or
22             croak "$arg is missing partition method: " . $plugin->key;
23 0           return $arg->$meth;
24             }
25              
26             sub new {
27 0     0 1   my ($class, $arg) = @_;
28 0 0         if ($arg->{method}) {
29 0           $arg->{key} = delete $arg->{method};
30 0   0       $arg->{value} ||= \&_value_method;
31             } else {
32 0   0       $arg->{value} ||= \&_value;
33             }
34 0           my $self = shift->SUPER::new(@_);
35 0           return $self;
36             }
37              
38             sub alter_path {
39 0     0 1   my ($plugin, $self, $path_ref) = @_;
40 0           $$path_ref = File::Spec->catdir(
41             $$path_ref,
42             $plugin->value->($plugin, $self->context),
43             );
44             }
45              
46             1;
47             __END__