| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package BioX::Workflow::Command::run::Rules::Directives::Interpolate; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 1 |  |  | 1 |  | 287318 | use Moose::Role; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 21 |  | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 1 |  |  | 1 |  | 10228 | use Text::Template; | 
|  | 1 |  |  |  |  | 4296 |  | 
|  | 1 |  |  |  |  | 77 |  | 
| 6 | 1 |  |  | 1 |  | 12 | use Try::Tiny; | 
|  | 1 |  |  |  |  | 3 |  | 
|  | 1 |  |  |  |  | 103 |  | 
| 7 | 1 |  |  | 1 |  | 545 | use Safe; | 
|  | 1 |  |  |  |  | 23150 |  | 
|  | 1 |  |  |  |  | 74 |  | 
| 8 | 1 |  |  | 1 |  | 11 | use Storable qw(dclone); | 
|  | 1 |  |  |  |  | 8 |  | 
|  | 1 |  |  |  |  | 98 |  | 
| 9 | 1 |  |  | 1 |  | 10 | use File::Spec; | 
|  | 1 |  |  |  |  | 4 |  | 
|  | 1 |  |  |  |  | 38 |  | 
| 10 | 1 |  |  | 1 |  | 603 | use Memoize; | 
|  | 1 |  |  |  |  | 3155 |  | 
|  | 1 |  |  |  |  | 632 |  | 
| 11 |  |  |  |  |  |  |  | 
| 12 |  |  |  |  |  |  | our $c = new Safe; | 
| 13 |  |  |  |  |  |  | ##Template | 
| 14 |  |  |  |  |  |  |  | 
| 15 |  |  |  |  |  |  | has 'interpol_directive_cache' => ( | 
| 16 |  |  |  |  |  |  | is      => 'rw', | 
| 17 |  |  |  |  |  |  | isa     => 'HashRef', | 
| 18 |  |  |  |  |  |  | default => sub { {} }, | 
| 19 |  |  |  |  |  |  | ); | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  | has 'errors' => ( | 
| 22 |  |  |  |  |  |  | is      => 'rw', | 
| 23 |  |  |  |  |  |  | isa     => 'Bool', | 
| 24 |  |  |  |  |  |  | default => 0, | 
| 25 |  |  |  |  |  |  | ); | 
| 26 |  |  |  |  |  |  |  | 
| 27 |  |  |  |  |  |  | has 'before_meta' => ( | 
| 28 |  |  |  |  |  |  | traits    => ['String'], | 
| 29 |  |  |  |  |  |  | is        => 'rw', | 
| 30 |  |  |  |  |  |  | isa       => 'Str', | 
| 31 |  |  |  |  |  |  | default   => q{}, | 
| 32 |  |  |  |  |  |  | predicate => 'has_before_meta', | 
| 33 |  |  |  |  |  |  | required  => 0, | 
| 34 |  |  |  |  |  |  | handles   => { | 
| 35 |  |  |  |  |  |  | add_before_meta     => 'append', | 
| 36 |  |  |  |  |  |  | replace_before_meta => 'replace', | 
| 37 |  |  |  |  |  |  | }, | 
| 38 |  |  |  |  |  |  | ); | 
| 39 |  |  |  |  |  |  |  | 
| 40 |  |  |  |  |  |  | sub interpol_directive { | 
| 41 | 0 |  |  | 0 | 0 |  | my $self   = shift; | 
| 42 | 0 |  |  |  |  |  | my $source = shift; | 
| 43 | 0 |  |  |  |  |  | my $text   = ''; | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | #The $ is not always at the beginning | 
| 46 | 0 | 0 | 0 |  |  |  | if ( exists $self->interpol_directive_cache->{$source} && $source !~ m/{/ ) | 
| 47 |  |  |  |  |  |  | { | 
| 48 | 0 |  |  |  |  |  | return $self->interpol_directive_cache->{$source}; | 
| 49 |  |  |  |  |  |  | } | 
| 50 |  |  |  |  |  |  |  | 
| 51 | 0 | 0 |  |  |  |  | if ( $source !~ m/{/ ) { | 
| 52 | 0 |  |  |  |  |  | $self->interpol_directive_cache->{$source} = $source; | 
| 53 | 0 |  |  |  |  |  | return $source; | 
| 54 |  |  |  |  |  |  | } | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 0 |  |  |  |  |  | my $template = Text::Template->new( | 
| 57 |  |  |  |  |  |  | TYPE   => 'STRING', | 
| 58 |  |  |  |  |  |  | SOURCE => $source, | 
| 59 |  |  |  |  |  |  | SAFE   => $c, | 
| 60 |  |  |  |  |  |  | ); | 
| 61 |  |  |  |  |  |  |  | 
| 62 | 0 |  |  |  |  |  | my $fill_in = { self => \$self }; | 
| 63 |  |  |  |  |  |  |  | 
| 64 |  |  |  |  |  |  | #TODO reference keys by value instead of $self-> | 
| 65 |  |  |  |  |  |  | # my @keys = keys %{$self}; | 
| 66 |  |  |  |  |  |  | # $fill_in->{INPUT} = $self->INPUT; | 
| 67 | 0 | 0 |  |  |  |  | $fill_in->{sample} = $self->sample if $self->has_sample; | 
| 68 |  |  |  |  |  |  |  | 
| 69 | 0 |  |  |  |  |  | $text = $template->fill_in( HASH => $fill_in, BROKEN => \&my_broken ); | 
| 70 |  |  |  |  |  |  |  | 
| 71 | 0 |  |  |  |  |  | $self->interpol_directive_cache->{$source} = $text; | 
| 72 | 0 |  |  |  |  |  | return $text; | 
| 73 |  |  |  |  |  |  | } | 
| 74 |  |  |  |  |  |  |  | 
| 75 |  |  |  |  |  |  | memoize('my_broken'); | 
| 76 |  |  |  |  |  |  |  | 
| 77 |  |  |  |  |  |  | sub my_broken { | 
| 78 |  |  |  |  |  |  | my %args    = @_; | 
| 79 |  |  |  |  |  |  | my $err_ref = $args{arg}; | 
| 80 |  |  |  |  |  |  | my $text    = $args{text}; | 
| 81 |  |  |  |  |  |  | my $error   = $args{error}; | 
| 82 |  |  |  |  |  |  | $error =~ s/via package.*//g; | 
| 83 |  |  |  |  |  |  | chomp($error); | 
| 84 |  |  |  |  |  |  | if ( $error =~ m/Can't locate object method/ ) { | 
| 85 |  |  |  |  |  |  | $error .= "\n# Did you declare $text?"; | 
| 86 |  |  |  |  |  |  | } | 
| 87 |  |  |  |  |  |  |  | 
| 88 |  |  |  |  |  |  | return <<EOF; | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | ################################################### | 
| 91 |  |  |  |  |  |  | # The following errors were encountered: | 
| 92 |  |  |  |  |  |  | # $text | 
| 93 |  |  |  |  |  |  | # $error | 
| 94 |  |  |  |  |  |  | ################################################### | 
| 95 |  |  |  |  |  |  | EOF | 
| 96 |  |  |  |  |  |  | } | 
| 97 |  |  |  |  |  |  |  | 
| 98 |  |  |  |  |  |  |  | 
| 99 |  |  |  |  |  |  | 1; |