NAME

Text::MustacheTemplate::Lexer - Simple mustache template lexer

SYNOPSIS

use Text::MustacheTemplate::Lexer;

# change delimiters
# local $Text::MustacheTemplate::Lexer::OPEN_DELIMITER = '<%';
# local $Text::MustacheTemplate::Lexer::CLOSE_DELIMITER = '%>';

my @tokens = Text::MustacheTemplate::Lexer->tokenize('* {{variable}}');

DESCRIPTION

Text::MustacheTemplate::Lexer is a simple lexer for Mustache template.

This is low-level interface for Text::MustacheTemplate. The APIs may be change without notice.

METHODS

tokenize($source)

Converts the given source template string into tokens. Returns an array of token tuple.

Each token is an array reference in the form [$token_type, $position, $data, ...] where:

  • $token_type - One of the token type constants (see "TOKENS")

  • $position - Position in the source string where the token begins

  • $data - Token-specific data (raw text, tag content, etc.)

Special tokens may contain additional elements in the array.

TOKENS

TOKEN_RAW_TEXT

Represents raw text content in the template. Format: [TOKEN_RAW_TEXT, $position, $text]

TOKEN_PADDING

Represents whitespace in the template. Format: [TOKEN_PADDING, $position, $whitespace]

TOKEN_TAG

Represents a mustache tag ({{tag}}). Format: [TOKEN_TAG, $position, $type, $content] or [TOKEN_TAG, $position, $content]

The $type parameter is present for special tags and indicates the tag type (such as '{' for triple mustache, '#' for section start, etc.)

TOKEN_DELIMITER

Represents a delimiter change. Format: [TOKEN_DELIMITER, $position, $raw_content, $open_delimiter, $close_delimiter]

LICENSE

Copyright (C) karupanerura.

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

AUTHOR

karupanerura <karupa@cpan.org>