The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Text::Xslate::Manual::Debugging - Debugging techniques for Xslate templates

DESCRIPTION

This document describes techniques for debugging templates.

File names and line numbers

Xslate messages include file names, line numbers, and, if possible, source code lines which seems problems.

You can also access the file name and the line number in templates by __FILE__ and __LINE__ tokens just like as Perl.

If you want reports files and lines from your registered functions, Text::Xslate->current_file and Text::Xslate->current_line in callbacks are the same as __FILE__ and __LINE__ in templates respectively.

    sub my_sqrt {
        my($n) = @_;

        if($n < 1) {
            # return a message instead of warnings
            return sprintf "!!! Can't take sqrt of $n at %s line %d !!!",
                Text::Xslate->current_file, Text::Xslate->current_line;
        }
        return sqrt($n);
    }

    my $tx = Text::Xslate->new(
        function => { sqrt => \&my_sqrt },
    );

To dump values

You can use any dumping modules via the function option, but Xslate has a builtin dump filter to dump template values.

    <: $value | dump # Dump $value with Data::Dumper :>

SEE ALSO

Text::Xslate

Text::Xslate::Manual