BioX-Workflow-Command
view release on metacpan or search on metacpan
lib/BioX/Workflow/Command/run/Rules/Directives/Interpolate/Text.pm view on Meta::CPAN
package BioX::Workflow::Command::run::Rules::Directives::Interpolate::Text;
use Moose::Role;
use namespace::autoclean;
use Text::Template;
use Try::Tiny;
use Safe;
use Storable qw(dclone);
use File::Spec;
use Memoize;
use File::Basename;
our $c = new Safe;
my $TEMPLATE_ERROR = 0;
has 'delimiter' => (
is => 'rw',
isa => 'Str',
default => '{',
);
has 'sample_var' => (
is => 'rw',
isa => 'Str',
lazy => 1,
default => '{$sample}',
);
sub interpol_text_template {
my $self = shift;
my $source = shift;
my $text = '';
$TEMPLATE_ERROR = 0;
## TODO Move this to before
#The $ is not always at the beginning
if (exists $self->interpol_directive_cache->{$source} && $source !~ m/{/) {
return $self->interpol_directive_cache->{$source};
}
## If the source string does not have a '{', its just text
if ($source !~ m/{/) {
$self->interpol_directive_cache->{$source} = $source;
return $source;
}
my $template = Text::Template->new(
TYPE => 'STRING',
SOURCE => $source,
SAFE => $c,
);
my $fill_in = { self => \$self };
$fill_in->{sample} = $self->sample if $self->has_sample;
my @keys = keys %{$self};
foreach my $key (@keys) {
if (ref $self->{$key}) {
$fill_in->{$key} = \$self->{$key};
}
else {
$fill_in->{$key} = $self->{$key};
}
}
$text = $template->fill_in(
( run in 0.550 second using v1.01-cache-2.11-cpan-39bf76dae61 )