File Coverage

blib/lib/BioX/Workflow/Command/run/Rules/Directives/Types/CSV.pm
Criterion Covered Total %
statement 9 23 39.1
branch 0 4 0.0
condition n/a
subroutine 3 4 75.0
pod 0 1 0.0
total 12 32 37.5


line stmt bran cond sub pod time code
1             package BioX::Workflow::Command::run::Rules::Directives::Types::CSV;
2              
3 1     1   1105 use Moose::Role;
  1         4  
  1         10  
4 1     1   6068 use namespace::autoclean;
  1         2  
  1         8  
5              
6 1     1   65 use Text::CSV::Slurp;
  1         2  
  1         219  
7              
8             with 'BioX::Workflow::Command::run::Rules::Directives::Types::Roles::File';
9              
10             after 'BUILD' => sub {
11             my $self = shift;
12              
13             $self->set_register_types(
14             'csv',
15             {
16             builder => 'create_reg_attr',
17             lookup => ['.*csv$']
18             }
19             );
20              
21             $self->set_register_process_directives( 'csv',
22             { builder => 'process_directive_csv', lookup => ['.*_csv$'] } );
23             };
24              
25             sub process_directive_csv {
26 0     0 0   my $self = shift;
27 0           my $k = shift;
28 0           my $v = shift;
29              
30 0           my $file = $self->check_file_exists( $k, $v );
31 0 0         return unless $file;
32              
33 0           my $data = Text::CSV::Slurp->load( file => $file );
34              
35 0 0         if ( exists $v->{key} ) {
36 0           my $key = $v->{key};
37 0           my %hoh = map { $_->{$key} => $_ } @{$data};
  0            
  0            
38 0           $self->$k( \%hoh );
39 0           return;
40             }
41              
42 0           $self->$k($data);
43             }
44              
45             1;