File Coverage

blib/lib/BioX/Workflow/Plugin/FileExists.pm
Criterion Covered Total %
statement 14 14 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 19 19 100.0


line stmt bran cond sub pod time code
1             package BioX::Workflow::Plugin::FileExists;
2              
3 1     1   12811 use strict;
  1         1  
  1         21  
4              
5 1     1   15 use 5.008_005;
  1         2  
6             our $VERSION = '0.12';
7              
8 1     1   527 use Data::Dumper;
  1         6149  
  1         48  
9 1     1   425 use Data::Pairs;
  1         1565  
  1         34  
10              
11 1     1   474 use Moose::Role;
  1         316326  
  1         4  
12              
13             before 'write_process' => sub{
14             my $self = shift;
15              
16             print "# In before write process!\n";
17             my $process = $self->process;
18             chomp($process);
19              
20             my @input = $self->local_attr->get_values('INPUT') if $self->local_attr->exists('INPUT');
21             my @output = $self->local_attr->get_values('OUTPUT') if $self->local_attr->exists('OUTPUT');
22              
23             my($input, $output) = ($input[0], $output[0]);
24              
25             my $tprocess = "";
26             if($input){
27             $tprocess .=<<EOF;
28             [ -f "$input" ] || \\{ >&2 echo "INPUT: $input not found" ; exit 256; \\} && \\
29             [ -s "$input" ] || \\{ >&2 echo "INPUT: $input is empty"; \\} && \\
30             touch $input || \\{>&2 echo "INPUT: $input could not be touched. Please check your file permissions!"; exit 1; \\} && \\
31             EOF
32             if($output){
33             $tprocess .=<<EOF;
34             touch $output || \\{>&2 echo "OUTPUT: $output could not be touched. Please check your file permissions!"; exit 1;\\} && \\
35             EOF
36             }
37             $tprocess .= $process;
38             $process = $tprocess;
39             }
40             if($output){
41             $process = $process." && \\\n";
42             $tprocess =<<EOF;
43             [ -f "$output" ] || \\{>&2 echo "OUTPUT $output not found" ; \\} && \\
44             [ -s "$output" ] || \\{>&2 echo "OUTPUT $output is empty"; \\}
45             EOF
46             $process .= $tprocess;
47             }
48             $self->process($process);
49              
50             };
51              
52             1;
53             __END__
54              
55             =encoding utf-8
56              
57             =head1 NAME
58              
59             BioX::Workflow::Plugin::FileExists - a plugin to BioX::Workflow
60              
61             =head1 SYNOPSIS
62              
63             biox-workflow.pl --plugins FileExists
64              
65             =head1 DESCRIPTION
66              
67             BioX::Workflow::Plugin::FileExists is a plugin of BioX::Workflow that first checks that your local INPUT exists.
68             If it doesn't exist it will exit with 256.
69             If INPUT is empty it will give a warning.
70             If OUTPUT is empty or doesn't exist it will give a warning.
71              
72              
73             =head1 AUTHOR
74              
75             Jillian Rowe E<lt>jillian.e.rowe@gmail.comE<gt>
76              
77             =head1 COPYRIGHT
78              
79             Copyright 2016- Jillian Rowe
80              
81             =head1 LICENSE
82              
83             This library is free software; you can redistribute it and/or modify
84             it under the same terms as Perl itself.
85              
86             =head1 SEE ALSO
87              
88             =cut