diff options
author | Chad Elliott <elliottc@objectcomputing.com> | 2019-06-28 11:01:15 -0500 |
---|---|---|
committer | Chad Elliott <elliottc@objectcomputing.com> | 2019-06-28 11:01:15 -0500 |
commit | c8e2f48e87161dac7cf8780dbcbf84b1db34ee6c (patch) | |
tree | b091f82ca635140d1d38050942ab38a417ba95c3 /modules | |
parent | 3a06d5612ae4f5c9f579acd7c85f460aed8c6c96 (diff) | |
download | MPC-c8e2f48e87161dac7cf8780dbcbf84b1db34ee6c.tar.gz |
Fri Jun 28 15:52:37 UTC 2019 Chad Elliott <elliottc@objectcomputing.com>
Diffstat (limited to 'modules')
-rw-r--r-- | modules/TemplateParser.pm | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/modules/TemplateParser.pm b/modules/TemplateParser.pm index 779b0750..33516751 100644 --- a/modules/TemplateParser.pm +++ b/modules/TemplateParser.pm @@ -93,6 +93,7 @@ my %keywords = ('if' => 0, 'set' => 0, 'is_relative' => $get_type|$doif_type|$get_combined_type, 'extension' => $get_type, + 'is_custom_input' => $get_type|$doif_type|$get_combined_type, ); my %target_type_vars = ('type_is_static' => 1, @@ -138,6 +139,7 @@ sub new { $self->{'keyname_used'} = {}; $self->{'scopes'} = {}; $self->{'aux_file'} = undef; + $self->{'custom_input_cache'} = {}; $self->{'foreach'} = {}; $self->{'foreach'}->{'count'} = -1; @@ -2015,6 +2017,60 @@ sub handle_is_relative { } +sub get_is_custom_input { + my($self, $name) = @_; + return $self->doif_is_custom_input($self->get_value_with_default($name)); +} + + +sub doif_is_custom_input { + my($self, $val) = @_; + + ## Create an array reference from the custom_types string value. + my $custom_types = $self->{'prjc'}->get_assignment('custom_types'); + my $ctypes = $self->create_array(defined $custom_types ? $custom_types : ''); + + foreach my $ctype (@$ctypes) { + ## Get the input files for each custom type. We cache it to avoid + ## generating the custom inputs for each and every call. This function + ## is usually called within a foreach context, so it will be called many + ## times per run. + my $inputs; + if (defined $self->{'custom_input_cache'}->{$ctype}) { + $inputs = $self->{'custom_input_cache'}->{$ctype}; + } + else { + $inputs = $self->{'prjc'}->get_custom_value('input_files', $ctype); + $self->{'custom_input_cache'}->{$ctype} = $inputs; + } + + ## Once we have the inputs, see if any of them match the current file + foreach my $input (@$inputs) { + ## There are various ways that the user could list files such that + ## a custom input could physically match a built-in file listing + ## but not be equal, in a string comparison sense. Resolving those + ## differences requires path traversal and that the files actually + ## exist (which isn't guaranteed at project generation time). So, + ## we do the minimal comparison using the file_sorter on the + ## ProjectCreator to handle case sensitivity automatically. + return 1 if ($self->{'prjc'}->file_sorter($input, $val)); + } + } + + ## There are either no custom types or there isn't a custom input file + ## that matches the one we're currently processing. + return undef; +} + + +sub handle_is_custom_input { + my($self, $name) = @_; + my $val = $self->get_value_with_default($name); + $self->append_current( + $self->doif_is_custom_input($val) ? '1' : '0') if (defined $val); +} + + sub get_extension { my($self, $name) = @_; my $val = $self->get_value_with_default($name); |