Custom Scanner Tagset

use Template::TT3::Scanner;

my $scanner = Template::TT3::Scanner->new(
    tagset => {
        bold => {
            type    => 'replace',
            start   => '[b]',
            end     => '[/b]',
            replace => sub {
                my ($self, $text) = @_;
                return "<b>$text</b>";
            }
        },
        italic => {
            # ...
        },
        # ...
    }
);
Thus Spake Andy:

We can use the Template::TT3::Scanner module. Instead of using the default TT3 tagset (i.e. the inline, outline, comment and control tags) we tell it to use our own custom tagset. Here we define a bold tag (each tag should be given a unique name). This is a simple replace tag which looks for a tag starting [b] and ending in [/b]. It calls the replace subroutine passing a reference to the tag object (a Template::TT3::Tag::Replace object) and the text scanned. The subroutine simply returns the text embedded in new HTML tags (but of course, it could do anything you like). We then do the same for an italic tag, and any others we might need.