lib/BioX/Workflow/Command/run/Rules/Directives/Interpolate/Text.pm

filter: Statementstmt 45.0% 32 / 71 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 9 / 12 Podpod 0.0% 0 / 3 totaltotal 37.2% 41 / 110 CC 11 SCAR 39.3
CC
11
Cov
35%
interpol_text_template
110.0
my_broken
6.0
interpol_directive
2.0
CRAP 51.0
« lib/BioX/Workflow/Command/run/Rules/Rules.pm ↑ Summary lib/BioX/Workflow/Command/Exceptions.pm »
1 package BioX::Workflow::Command::run::Rules::Directives::Interpolate::Text;
2  
3 1 ▶use Moose::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Text::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Safe;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Storable qw(dclone);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use Memoize;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 our $c = new Safe;
15 1 my $TEMPLATE_ERROR = 0;
16  
17 1 has 'delimiter' => (
18 is => 'rw',
19 isa => 'Str',
20 default => '{',
21 );
22  
23 1 has 'sample_var' => (
24 is => 'rw',
25 isa => 'Str',
26 lazy => 1,
27 default => '{$sample}',
28 );
29  
30 0 ▶sub interpol_text_template {
Subroutine interpol_text_template: not called CC=10 SCAR=47.0
Pod undocumented
31 0 my $self = shift;
32 0 my $source = shift;
33 0 my $text = '';
34  
35 0 $TEMPLATE_ERROR = 0;
36 ## TODO Move this to before
37 #The $ is not always at the beginning
38 0 ▶ if (exists $self->interpol_directive_cache->{$source} && $source !~ m/{/) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->interpol_directive_cache->{$source} and not $source =~ /{/) 0 0 0
Condition0%0/3
exists $self->interpol_directive_cache->{$source} and not $source =~ /{/
!ll&&!rl&&r
000
MC/DC0%0/2
exists $self->interpol_directive_cache->{$source} and not $source =~ /{/
exists $self->interpol_directive_cache->{$source} not $source =~ /{/
Truth table0%0/3
A and not(B)
A= exists $self->interpol_directive_cache->{$source}B= not $source =~ /{/
ABresult
0X0
100
111
39 0 return $self->interpol_directive_cache->{$source};
40 }
41  
42 ## If the source string does not have a '{', its just text
43 0 ▶ if ($source !~ m/{/) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($source =~ /{/) 0 0 0
44 0 $self->interpol_directive_cache->{$source} = $source;
45 0 return $source;
46 }
47  
48 0 my $template = Text::Template->new(
49 TYPE => 'STRING',
50 SOURCE => $source,
51 SAFE => $c,
52 );
53  
54 0 my $fill_in = { self => \$self };
55  
56 0 ▶ $fill_in->{sample} = $self->sample if $self->has_sample;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_sample 0 0 0
57 0 my @keys = keys %{$self};
58 0 foreach my $key (@keys) {
59 0 ▶ if (ref $self->{$key}) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{$key}) { } 0 0 0
60 0 $fill_in->{$key} = \$self->{$key};
61 }
62 else {
63 0 $fill_in->{$key} = $self->{$key};
64 }
65 }
66  
67 0 $text = $template->fill_in(
68 HASH => $fill_in,
69 BROKEN => \&my_broken,
70 PREPEND => "use File::Glob; use File::Slurp; use File::Basename;\n"
71 );
72  
73 0 ▶ if ($TEMPLATE_ERROR) {
Branch: 1 branch
BranchTrueFalseTotal
if ($TEMPLATE_ERROR) 0 0 0
74 0 $self->_ERROR(1);
75 0 ▶ if ($source =~ m/self/ && $source !~ m/\$self/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($source =~ /self/ and not $source =~ /\$self/) 0 0 0
Condition0%0/3
$source =~ /self/ and not $source =~ /\$self/
!ll&&!rl&&r
000
MC/DC0%0/2
$source =~ /self/ and not $source =~ /\$self/
$source =~ /self/ not $source =~ /\$self/
Truth table0%0/3
A and not(B)
A= $source =~ /self/B= not $source =~ /\$self/
ABresult
0X0
100
111
76 0 $text .= "######################################\nFound use of self without \$\n\n";
77 }
78 }
79 0 $self->interpol_directive_cache->{$source} = $text;
80 0 return $text;
81 }
82  
83 0 ▶sub interpol_directive {
Subroutine interpol_directive: not called CC=1 SCAR=6.9
Pod undocumented
84 0 my $self = shift;
85 0 my $source = shift;
86 0 my $text = '';
87  
88 0 return $self->interpol_text_template($source);
89 }
90  
91 # memoize('my_broken');
92  
93 0 ▶sub my_broken {
Subroutine my_broken: not called CC=2 SCAR=17.9
Pod undocumented
94 0 my %args = @_;
95 0 my $err_ref = $args{arg};
96 0 my $text = $args{text};
97 0 my $error = $args{error};
98  
99 0 $TEMPLATE_ERROR = 1;
100 0 $error =~ s/via package.*//g;
101 0 chomp($error);
102 0 ▶ if ($error =~ m/Can't locate object method/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error =~ /Can't locate object method/) 0 0 0
103 0 $error .= "\n# Did you declare $text?";
104 }
105  
106 0 return <<EOF;
107  
108 ###################################################
109 # The following errors were encountered:
110 # $text
111 # $error
112 ####################################################
113 EOF
114 }
115  
116 1 1;
« lib/BioX/Workflow/Command/run/Rules/Rules.pm ↑ Summary lib/BioX/Workflow/Command/Exceptions.pm »