Perl: Alternatives to template toolkit

后端 未结 5 946
梦毁少年i
梦毁少年i 2021-01-30 18:25

I have been using template toolkit for extending an existing domain specific language(verilog) for over 3 years now. While overall I am happy with it, the major irritant is that

5条回答
  •  轮回少年
    2021-01-30 19:15

    Mojolicious comes with its own templating system Mojo::Template. Its lightweight and can be used even outside of the mojolicious system. Here is an example from the docs:

    use Mojo::Template;
      my $mt = Mojo::Template->new;
    
      # Simple
      my $output = $mt->render(<<'EOF');
      % use Time::Piece;
      
      
        Simple
        % my $now = localtime;
        Time: <%= $now->hms %>
      
      EOF
      say $output;
    

    and another

      # More advanced
      my $output = $mt->render(<<'EOF', 23, 'foo bar');
      % my ($number, $text) = @_;
      %= 5 * 5
      
      
        More advanced
        
          test 123
          foo <% my $i = $number + 2; %>
          % for (1 .. 23) {
          * some text <%= $i++ %>
          % }
        
      
      EOF
      say $output;
    

提交回复
热议问题