DOKK / manpages / debian 12 / sreview-common / SReview::Template.3pm.en
SReview::Template(3pm) User Contributed Perl Documentation SReview::Template(3pm)

SReview::Template - process a string or a file and apply changes to it

  use SReview::Template;
  use SReview::Talk;
  my $talk = SReview::Talk->new(...);
  my $template = SReview::Template->new(talk => $talk, vars => { foo => "bar" }, regexvars => {"@FOO@" => "foo"});
  my $processed = $template->string("The @FOO@ is <%== $foo %>, and the talk is titled <%== $talk->title %>");
  # $processed now contains "The foo is bar, and the talk is titled ..."
  # (with the actual talk title there)
  $template->file("inputfile.txt", "outputfile.txt"

"SReview::Template" is a simple wrapper around Mojo::Template. All the variables that are passed in to the "vars" parameter are passed as named variables to Mojo::Template.

In addition, some bits of SReview previously did some simple sed-like search-and-replace templating. For backwards compatibility, this module also supports such search-and-replace templating (e.g., SReview::Template::SVG has a few of those). These, however, are now deprecated; the $talk variable and Mojo::Template-style templates should be used instead.

"SReview::Template" objects support the following attributes:

An SReview::Talk object for the talk that this template is for. Required. Will be passed on to the template as the $talk variable.

Additional Mojo::Template variables to be made available to the template.

Variables to be replaced by search-and-replace.

A method to process an input file through the templating engine into an output file.

Takes to arguments: the name of the input file, followed by the name of the output file.

Is implemented in terms of the "string" method.

A function to process a string, passed as the only argument. Returns the result of the template function.

2022-12-14 perl v5.36.0