lib/BioX/Workflow/Command/run/Rules/Directives/Interpolate/Jinja.pm untested

filter: Statementstmt 0.0% 0 / 67 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 14 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 98 CC 4 SCAR 18.3
CC
4
Cov
0%
interpol_directive
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 6.2
1 use strict;
2 use warnings;
3 package BioX::Workflow::Command::run::Rules::Directives::Interpolate::Jinja;
4  
5 use Moose::Role;
6 use namespace::autoclean;
7  
8 use IPC::Cmd qw[can_run run];
9 use Try::Tiny;
10 use Safe;
11 use Storable qw(dclone);
12 use File::Spec;
13 use Memoize;
14 use File::Basename;
15 use File::Temp qw/tempfile/;
16 use File::Slurp;
17  
18 my $TEMPLATE_ERROR = 0;
19  
20 has 'sample_var' => (
21 is => 'rw',
22 isa => 'Str',
23 lazy => 1,
24 default => '{{ sample }}',
25 );
26  
27 has 'delimiter' => (
28 is => 'rw',
29 isa => 'Str',
30 lazy => 1,
31 default => '{'
32 );
33  
34 sub interpol_directive {
35 my $self = shift;
36 my $source = shift;
37 my $text = '';
38  
39 $TEMPLATE_ERROR = 0;
40 if (exists $self->interpol_directive_cache->{$source} && $source !~ m/{/) {
41 return $self->interpol_directive_cache->{$source};
42 }
43  
44 ## If the source string does not have a '{', its just text
45 if ($source !~ m/{/) {
46 $self->interpol_directive_cache->{$source} = $source;
47 return $source;
48 }
49  
50 my ($tfh, $tfilename) = tempfile();
51 my ($jfh, $jfilename) = tempfile();
52  
53 my $json = $self->serialize_to_json($jfilename);
54 write_file($tfilename, $source);
55 #
56 my $cmd = 'biosails-biox-render.py -j ' . $jfilename . ' -t ' . $tfilename;
57 my ($success, $error_message, $full_buf, $stdout_buf, $stderr_buf) =
58 run(command => $cmd, verbose => 0);
59 ##TODO Add condition statements for success/not success
60 map {chomp $_;
61 $_} @{$stdout_buf};
62  
63 my $data = join('', @{$stdout_buf});
64  
65 ##If its the same and it has a $sign, its probably a perl expression
66 if ($data eq $source && $data =~ m/\$/){
67 return $self->interpol_text_template($source);
68 }
69 return join('', @{$stdout_buf});
70 }
71  
72 1;