NAME

Top Close Open

Template::TT3::Type::Source - object for representing template source code

SYNOPSIS

Top Close Open
use Template::TT3::Type::Source;

my $source = Template::TT3::Text::Source->new(
    "Hello [% name or 'World' %]"
);

DESCRIPTION

Top Close Open

** TODO **

QUICK NOTES

Top Close Open

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;

Methods

Top Close Open

The following methods are defined in addition to those inherited from the Template::TT3::Type::Text base class.

** TODO **

position()

Top Close Open

Returns the current regex match position in the source text.

line()

Top Close Open

Returns the line number of the current regex match position.

column()

Top Close Open

Returns the column number of the current regex match position.

line_column()

Top Close Open

Returns the line and column numbers of the current regex match position.

whereabouts()

Top Close Open

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.

location()

Top Close Open

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! %]
                                ^

lookahead($length)

Top Close Open

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
%]

debug_lookahead()

Top Close Open

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'.

AUTHOR

Top Close Open

Andy Wardley http://wardley.org/

COPYRIGHT

Top Close Open

Copyright (C) 1996-2008 Andy Wardley. All Rights Reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


http://tt3.template-toolkit.org/docs/Template/TT3/Type/Source.pm last modified 2009-12-22 11:27:29