| 1 | package Lingua::Ogmios::NLPWrappers::Template; | ||
| 2 | |||
| 3 | |||
| 4 | our $VERSION='0.1'; | ||
| 5 | |||
| 6 | |||
| 7 | use Lingua::Ogmios::NLPWrappers::Wrapper; | ||
| 8 | |||
| 9 | use strict; | ||
| 10 | use warnings; | ||
| 11 | |||
| 12 | our @ISA = qw(Lingua::Ogmios::NLPWrappers::Wrapper); | ||
| 13 | |||
| 14 | sub new { | ||
| 15 | my ($class, $config, $tmpfile_prefix, $logfile, $position, $no_standard_output) = @_; | ||
| 16 | |||
| 17 | my $lang; | ||
| 18 | my $lang2; | ||
| 19 | |||
| 20 | warn "[LOG] Creating a wrapper of the Template\n"; | ||
| 21 | |||
| 22 | my $Template = $class->SUPER::new($config, $tmpfile_prefix, $logfile, $position, $no_standard_output); | ||
| 23 | |||
| 24 | if (defined $Template->_config->configuration->{'CONFIG'}) { | ||
| 25 | foreach $lang (keys %{$Template->_config->configuration->{'CONFIG'}}) { | ||
| 26 | if ($lang =~ /language=([\w]+)/io) { | ||
| 27 | $lang2 = $1; | ||
| 28 | |||
| 29 | $Template->_setOption($lang2, "MODE", "mode", "eval"); | ||
| 30 | # if (defined $Template->_config->configuration->{'CONFIG'}->{$lang}->{"OPTION"}) { | ||
| 31 | # $Template->{'parameter'}->{$lang2} = $Template->_config->configuration->{'CONFIG'}->{$lang}->{"OPTION"}; | ||
| 32 | # } else { | ||
| 33 | # $Template->{'parameter'}->{"FR"} = "?.!"; | ||
| 34 | # $Template->{'parameter'}->{"EN"} = "?.!"; | ||
| 35 | # warn "*** OPTION is not set ***\n"; | ||
| 36 | # } | ||
| 37 | # } else { | ||
| 38 | # $Template->{'parameter'}->{"FR"} = "?.!"; | ||
| 39 | # $Template->{'parameter'}->{"EN"} = "?.!"; | ||
| 40 | # warn "*** OPTION is not set ***\n"; | ||
| 41 | } | ||
| 42 | } | ||
| 43 | # } else { | ||
| 44 | # $Template->{'parameter'}->{"FR"} = "?.!"; | ||
| 45 | # $Template->{'parameter'}->{"EN"} = "?.!"; | ||
| 46 | } | ||
| 47 | |||
| 48 | |||
| 49 | $Template->_input_filename($tmpfile_prefix . ".Template.in"); | ||
| 50 | $Template->_output_filename($tmpfile_prefix . ".Template.out"); | ||
| 51 | |||
| 52 | return($Template); | ||
| 53 | |||
| 54 | } | ||
| 55 | |||
| 56 | sub _processTemplate { | ||
| 57 | my ($self, $lang) = @_; | ||
| 58 | |||
| 59 | warn "[LOG] Template\n"; | ||
| 60 | |||
| 61 | $lang = $self->_documentSet->[0]->getAnnotations->getLanguage; | ||
| 62 | |||
| 63 | return($self->_exec_command($self->_defineCommandLine($self->_config->commands($lang)->{Template_CMD} . " < " . $self->_input_filename . ">" . $self->_output_filename))); | ||
| 64 | |||
| 65 | warn "[LOG]\n"; | ||
| 66 | } | ||
| 67 | |||
| 68 | sub _inputTemplate { | ||
| 69 | my ($self) = @_; | ||
| 70 | |||
| 71 | warn "[LOG] making Template input\n"; | ||
| 72 | |||
| 73 | warn "[LOG] done\n"; | ||
| 74 | } | ||
| 75 | |||
| 76 | |||
| 77 | sub _outputTemplate { | ||
| 78 | my ($self) = @_; | ||
| 79 | |||
| 80 | warn "[LOG] . Parsing " . $self->_output_filename . "\n"; | ||
| 81 | |||
| 82 | warn "[LOG] done\n"; | ||
| 83 | } | ||
| 84 | |||
| 85 | sub run { | ||
| 86 | my ($self, $documentSet) = @_; | ||
| 87 | |||
| 88 | # Set variables according the the configuration | ||
| 89 | |||
| 90 | $self->_documentSet($documentSet); | ||
| 91 | |||
| 92 | warn "[LOG] " . $self->_config->comments . " ... \n"; | ||
| 93 | |||
| 94 | $self->_inputTemplate; | ||
| 95 | |||
| 96 | my $command_line = $self->_processTemplate; | ||
| 97 | |||
| 98 | # if ($self->_position eq "last") { | ||
| 99 | # # TODO | ||
| 100 | if (($self->_position eq "last") && ($self->_no_standard_output)) { | ||
| 101 | warn "print no standard output\n"; | ||
| 102 | } else { | ||
| 103 | $self->_outputTemplate; | ||
| 104 | } | ||
| 105 | # $self->_outputParsing; | ||
| 106 | |||
| 107 | |||
| 108 | # Put log information | ||
| 109 | |||
| 110 | my $information = { 'software_name' => $self->_config->name, | ||
| 111 | 'comments' => $self->_config->comments, | ||
| 112 | 'command_line' => $command_line, | ||
| 113 | 'list_modified_level' => [''], | ||
| 114 | }; | ||
| 115 | $self->_log($information); | ||
| 116 | |||
| 117 | |||
| 118 | # die "You call the 'rum' method of the wrapper class base\n | ||
| 119 | # You should define a 'run' method for your wrapper\n"; | ||
| 120 | warn "[LOG] done\n"; | ||
| 121 | } | ||
| 122 | |||
| 123 | 1; | ||
| 124 | |||
| 125 | __END__ |