Text::Xslate::Manual::Debugging - Debugging techniques for Xslate templates
This document describes techniques for debugging templates.
Xslate reports file names and line numbers, but you can access them via __FILE__ and __LINE__ tokens just like as Perl.
__FILE__
__LINE__
If you want reports files and lines from your functions, Text::Xslate->current_file and Text::Xslate->current_line in callbacks are the same as __FILE__ and __LINE__ in templates respectively.
Text::Xslate->current_file
Text::Xslate->current_line
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 }, );
You can use any dumping modules via the function option, but Xslate has a builtin dump filter to dump template values.
function
dump
<: $value | dump # Dump $value with Data::Dumper :>
Text::Xslate
Text::Xslate::Manual
To install Text::Xslate, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::Xslate
CPAN shell
perl -MCPAN -e shell install Text::Xslate
For more information on module installation, please visit the detailed CPAN module installation guide.