Parse::Template::Base -
Nothing exported by default
This module requires these other modules and libraries:
Data::Hub::Courier Parse::Padding Parse::Template::Arguments Error::Logical Error::Programatic Perl::Module Data::Hub::Util Parse::Template::ArgumentStack Algorithm::KeyGen
This example:
# Simple replacement use Parse::Template::Standard; my $t = 'Hello [#name]'; my $p = new Parse::Template::Standard(); my $o = $p->compile_text(\$t, {name => 'World'}); return $$o;
will return:
Hello World
# Variable expansion use Parse::Template::Standard; my $t = 'Hello [#name]'; my $p = new Parse::Template::Standard(); my $o = $p->compile_text(\$t, {name => '[#next]', next => 'World'}); return $$o;
# Nested elements use Parse::Template::Standard; my $t = 'Hello [#data/name]'; my $p = new Parse::Template::Standard(); my $o = $p->compile_text(\$t, {data => {name => 'World'}}); return $$o;
# Dynamic expansion use Parse::Template::Standard; my $t = 'Hello [#[#name]]'; my $p = new Parse::Template::Standard(); my $o = $p->compile_text(\$t, {name => 'next', next => 'World'}); return $$o;
options:
-begin => $begin_str # Begins match (default '[#') -end => $end_str # Ends match (default ']') -close => $close_str # Closes a block (default 'end') -directive => $directive_str # Identifies a directive (default ':') -out => \$output # Where output is written
where:
$name directive name $idx 0 for begin, 1 for end
Calls to use must match calls to un-use within the same context
This routine does the work of processing the variable spec with consideration of the `x ? y : z`, `&&` and `||` operations. For instance:
a a || b t ? a : b t ? f || a : b && c f ? f || c : b && a
See also: `src/test/perl/t-eval-fields.pl`
See also: "get_value"
$addr is passed by-reference because we will update it when applying local path information.
$addr
All directives nested SHOULD be either inline (they do not slurp) or blocks (they have an end directive).
All nested directives MUST also have their own end directive. This is not currently the case, so we do our best. Take this scenario:
[#:set foo] This is a block [#:end set]
Which is just fine. However, this is difficult:
[#:set foo] [#:set bar = 'Bar'] This is a block [#:end set]
Because we don't know that the nested `:set` directive is inline. So, we ask for the `$to_eof` parameter. If this is true, then we will return the normal end position, that is -1 when nested occurences are not paired up. Otherwise we will return the end position of the *last* corresponding end directive. This is the best we can do without more information, and passing or garnering that information is considered too expensive an operation at this level.
Provisions have been made only considering the `:set` and `:into` directives. -Ryan 11/2012
Similar in spirit to "substr_pos" except this routine uses regular expressions to ensure a nexted '[#abcd' does not count as a nested '[#ab' and this routine does not track all sub-indexes.
This routine recognizes $begin_marker and $end_marker as a balanced pair.
$begin_marker
$end_marker
Example 1:
$begin_marker = [# $end_marker = ] a [#b [#c] [#d]] e ^ ^ returns [[2, 15]]
Example 2:
$begin_marker = [#if $end_marker = [#end if] [#if true]do something[#end if] ^ ^ returns [[0, 22]]
use Parse::Template::Base; my $p = new Parse::Template::Base; my $text = '<<>>'; my @pos = $p->substr_pos(\$text, '<', '>', 0); join ',', map {join '-', @$_} @pos;
0-3,1-2
where %args can be any combination of:
%args
text => \$text, # Template text path => $path, # Template path name => $name, # Template name out => \$out, # Where to write the result scope => $scope, # Stack index limit (invokation is being deferred) regions => \@regions, # Known regions (\$text is being re-used) esc => $chars # Escape chars in resolved values
returns:
[\@match1, \@match2, ...] where each C<\@match> is: [ $beg, # Begin index $end, # End index $nested, # Has nested regions (1|undef) ]
See _create_context for %args
If $to_eof is a true value and an end directive is not found, _slurp will read to the end of the template text.
$to_eof
_slurp
If $to_eol is not defined, it is true, which means the newlines after the closing tag will be consumed.
$to_eol
Returns an array of widths: ($w1, $w2)
$w1 = Number of preceeding whitespace characters $w2 = Number of trailing whitespace characters
Returns an (0, 0) if non-whitespace characters are immediately found in the preceeding or trailing regions.
We will look up to 80 characters in front of the current position.
Ryan Gies <ryangies@cpan.org>
Copyright (C) 2014-2016 by Ryan Gies. All rights reserved. Copyright (C) 2006-2013 by Livesite Networks, LLC. All rights reserved. Copyright (C) 2000-2005 by Ryan Gies. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. * Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. * The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. To the best of our knowledge, no patented algorithms have been used. However, we do not have the resources to carry out a patent search, and therefore cannot give any guarantee of the above statement.
To install Data::Hub, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Data::Hub
CPAN shell
perl -MCPAN -e shell install Data::Hub
For more information on module installation, please visit the detailed CPAN module installation guide.