use Template::TT3::Type::Source; my $source = Template::TT3::Text::Source->new( "Hello [% name or 'World' %]" );
A source object is a text object. It's a reference to a text string. You can match against it like this
if ($$source =~ / \G (\W+) /) { ... }
You can query the current position, line number and column number.
$source->position; $source->line; $source->column;
The following methods are defined in addition to those inherited from the Template::TT3::Type::Text base class.
** TODO **
Returns the line and column numbers of the current regex match position.
Returns a reference to a hash array containing information about the current match position.
text The source text position The current position line The current line column The current column extract Text extract around current position.
The hash array contains an extract
item containing an extract of the
current line around the regex match position.
If the line is sufficiently short (less than $LINE_LENGTH which defaults to 72 characters) then it will be returned intact. If longer, then an extra of the line will be shown.
Returns a string describing the current regex match position, complete with a text extract.
at line 36 column 17: This is the source template [%* oops! %] ^
Returns the next $length
characters following the current global
regular expression matching point (\G
). See
perlre
for further
information on what that is and how it's used.
If $length
is unspecified then it returns all remaining text.
[% text = Text('Foo Bar Baz'); text.match(/\(w+)\s/g).0; # Foo text.lookahead; # Bar Baz text.match(/\(w+)\s/g).0; # Bar text.lookahead; # Baz %]
This method allows you to peek ahead from the current regex match position to see what will be matched next. It is primarily used for debugging.
Returns the output of
lookahead(16)
with all newlines converted to
the literal string '\n
'.
Andy Wardley http://wardley.org/