-
-
05 Jul 2021 21:04:56 UTC
- Distribution: Rex
- Module version: v1.13.4
- Source (raw)
- Browse (raw)
- Changes
- Homepage
- How to Contribute
- Repository
- Issues
- Testers (717 / 4 / 2)
- Kwalitee
Bus factor: 2- 49.25% Coverage
- License: apache_2_0
- Perl: v5.10.1
- Activity
24 month- Tools
- Download (342.78KB)
- MetaCPAN Explorer
- Permissions
- Subscribe to distribution
- Permalinks
- This version
- Latest version
and 118 contributors-
Jan Gehring
-
A Happy User
-
Alexander Romanenko
-
Alexandr Ciornii
-
Alex Mestiashvili
-
Ali Polatel
-
alx542
-
Anders Ossowicki
-
Andrej Zverev
-
Andrew Solomon
-
Andy Beverley
-
Arnold Bechtoldt
-
Boris Däppen
-
Brian Manning
-
Cameron Daniel
-
Chris Steigmeier
-
Christophe Wolfhugel
-
Crimson Thompson
-
Daniel Bäurer
-
Daniel Cesario
-
Daniel Dico
-
Denis Silakov
-
Dmitry Kopytov
-
Dominik Schulz
-
E. Choroba
-
Eduardo J
-
Eivin Giske Skaaren
-
elisdg
-
Elmer Quintanilla
-
Eric Johnson
-
Erik Huelsmann
-
Ferenc Erki
-
Franky Van Liedekerke
-
Fran Rodriguez
-
Gabor Szabo
-
Graham Todd
-
Harm Müller
-
Hayato Imai
-
Hiroaki Nakamura
-
Hiroki Matsuo
-
iblinder
-
Ilya Pavlov
-
James D Bearden
-
jdelgado7
-
Jean Charles Passard
-
Jean-Marie Renouard
-
Jeen Lee
-
Jens Berthold
-
Joachim Bargsten
-
John Karr
-
Jon Gentle
-
Joris DE POOTER
-
Jose Luis Martinez
-
Jose Luis Perez Diez
-
Kasim Tuman
-
Keedi Kim
-
Ken Crowell
-
Kent Fredric
-
Kirill Babikhin
-
labbeduddel
-
Leah Neukirchen
-
LeMerP
-
Mario Domgoergen
-
Max E. Aubrey
-
Mitch Broadhead
-
Nathan Abu
-
Naveed Massjouni
-
necrophcodr
-
Nicolas Leclercq
-
Nigel Gregoire
-
Nikolay A. Fetisov
-
Nils Domrose
-
okaoka
-
Oleg Hardt
-
Olivier Cherrier
-
Orange
-
Paco Esteban
-
Patrick Lauer
-
Pavel Timofeev
-
perlancar
-
Peter H. Ezetta
-
Peter Manthey
-
petersonchen
-
Pierrick DINTRAT
-
Piotr Karbowski
-
Prajithp
-
Randy Lauen
-
Renée Bäcker
-
Robert Abraham
-
Roy Storey
-
Samuele Tognini
-
Sascha Askani
-
Sascha Guenther
-
Simon Bertrang
-
Solène Rapenne
-
Stephane Benoit
-
Steve Dondley
-
Sven Dowideit
-
Tamas Molnar
-
Tianon Gravi
-
Tokuhiro Matsuno
-
Tomohiro Hosaka
-
Volker Kroll
-
Walery Wysotsky
-
Yanick Champoux
-
Yegor Korablev
-
Zane C. Bowers-Hadley
-
Сергей Романов
-
范野人
-
饶琛琳
-
Cuong Manh Le
-
David Golovan
-
Dominik Danter
-
Ilya Evseev
-
Niklas Larsson
-
Qiao Liu
-
Renato CRON
-
Peter Jankovics
- Dependencies
- AWS::Signature4
- Carp
- Cwd
- Data::Dumper
- Data::Validate::IP
- Devel::Caller
- Digest::HMAC_SHA1
- Digest::MD5
- English
- Exporter
- Fcntl
- File::Basename
- File::Spec
- File::Spec::Unix
- File::Spec::Win32
- FindBin
- HTTP::Request
- HTTP::Request::Common
- Hash::Merge
- IO::File
- IO::Select
- IO::Socket
- IO::String
- IPC::Open3
- JSON::MaybeXS
- LWP::UserAgent
- List::Util
- MIME::Base64
- Net::OpenSSH::ShellQuoter
- POSIX
- Scalar::Util
- Sort::Naturally
- Storable
- Symbol
- Term::ReadKey
- Test::Builder::Module
- Text::Glob
- Text::Wrap
- Time::HiRes
- UNIVERSAL
- URI
- URI::QueryParam
- XML::Simple
- YAML
- attributes
- base
- constant
- lib
- overload
- strict
- vars
- version
- warnings
- and possibly others
- Reverse dependencies
- CPAN Testers List
- Dependency graph
- NAME
- SYNOPSIS
- DESCRIPTION
- DIAGNOSTICS
- CONFIGURATION AND ENVIRONMENT
- EXPORTED FUNCTIONS
- DEPENDENCIES
- INCOMPATIBILITIES
- BUGS AND LIMITATIONS
NAME
Rex::Template - simple template engine
SYNOPSIS
use Rex::Template; my $template = Rex::Template->new; print $template->parse($content, \%template_vars); print $template->parse($content, @template_vars);
DESCRIPTION
This is a simple template engine for configuration files. It is included mostly for backwards compatibility, and it is recommended to use Rex::Template::NG instead (for better control of chomping new lines, and better diagnostics if things go wrong).
SYNTAX
The following syntax is recognized:
anything between
<%
and%>
markers are considered as a template directive, which is treated as Perl codeif the opening marker is followed by an equal sign (
<%=
) or a plus sign (<%+
), then the directive is replaced with the value it evaluates toif the closing marker is prefixed with a minus sign (
-%>
), then any trailing newlines are chomped for that directive
The built-in template support is intentionally kept basic and simple. For anything more sophisticated, please use your favorite template engine.
EXAMPLES
Plain text is unchanged:
my $result = $template->parse( 'one two three', {} ); # $result is 'one two three'
Variable interpolation:
my $result = template->parse( 'Hello, this is <%= $::name %>', { name => 'foo' } ); # original format my $result = template->parse( 'Hello, this is <%+ $::name %>', { name => 'foo' } ); # alternative format with + sign my $result = template->parse( 'Hello, this is <%= $name %>', { name => 'foo' } ); # local variables my $result = template->parse( 'Hello, this is <%= $name %>', name => 'foo' ); # array of variables, instead of hashref # $result is 'Hello, this is foo' for all cases above
Simple evaluation:
my $result = $template->parse( '<%= join("/", @{$elements} ) %>', elements => [qw(one two three)] ); # $result is 'one/two/three'
Embedded code blocks:
my $content = '<% if ($logged_in) { %> Logged in! <% } else { %> Logged out! <% } %>'; my $result = $template->parse( $content, logged_in => 1 ); # $result is "\nLogged in!\n"
DIAGNOSTICS
Not much, mainly due to the internal approach of the module.
If there was a problem, it prints an
INFO
level "syntax error at ...", followed by aWARN
about "It seems that there was an error processing the template because the result is empty.", and finally "Error processing template at ...".The beginning of the reported syntax error might give some clue where the error happened in the template, but that's it.
Use Rex::Template::NG instead for better diagnostics.
CONFIGURATION AND ENVIRONMENT
If
$Rex::Template::BE_LOCAL
is set to a true value, then local template variables are supported instead of only global ones ($foo
vs$::foo
). The default value is1
since Rex-0.41. It can be disabled with the no_local_template_vars feature flag.If
$Rex::Template::DO_CHOMP
is set to a true value, then any trailing new line character resulting from template directives are chomped. Defaults to0
.This module does not support any environment variables.
EXPORTED FUNCTIONS
parse($content, $variables)
Parse
$content
as a template, using$variables
hash reference to pass name-value pairs of variables to make them available for the template function.Alternatively, the variables may be passed as an array instead of a hash reference.
is_defined($variable, $default_value)
This function will check if
$variable
is defined. If yes, it will return the value of$variable
, otherwise it will return$default_value
.You can use this function inside your templates, for example:
ServerTokens <%= is_defined( $::server_tokens, 'Prod' ) %>
DEPENDENCIES
INCOMPATIBILITIES
BUGS AND LIMITATIONS
It might not be able to chomp new line characters resulting from templates in every case.
It can't report useful diagnostic messages upon errors.
Use Rex::Template::NG instead.
Module Install Instructions
To install Rex, copy and paste the appropriate command in to your terminal.
cpanm Rex
perl -MCPAN -e shell install Rex
For more information on module installation, please visit the detailed CPAN module installation guide.