Text::...bugging(3pm)
β¨ NAME β¨
okay so this is Text::Xslate::Manual::Debugging, aka the manual page Text::...bugging(3pm) from the User Contributed Perl Documentation corner of the world π β it's literally an entire doc about debugging techniques for Xslate templates. yes bestie, debugging. we love her.
π¦ DESCRIPTION π¦
this doc spills all the tea on techniques for debugging templates. buckle up π
πΈ Setting "verbose => 2" πΈ
first move, bestie: try verbose => 2. do it. this option turns on full warnings, which is giving especially the warnings that are all about undef π
π File names and line numbers π
Xslate messages already come with file names, line numbers, and β if possible β the source code lines that seem to be the problem. so she's serving receipts, periodt.
you can also grab the file name and the line number inside your templates with the __FILE__ and __LINE__ tokens, just like as in Perl. iconic, right?
and if you want your registered functions to report files and lines, then Text::Xslate->current_file and Text::Xslate->current_line in callbacks are literally the same thing as __FILE__ and __LINE__ in templates. respectively. iykyk β¨
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 you want via the function option, no cap, but Xslate also ships a builtin dump filter just for dumping template values π
<: $value | dump # Dump $value with Data::Dumper :>
π Detection of missing variables (or typos or variable names) π
Xslate herself has a warning system for use of uninitialized values, but sometimes, ngl, it's just not enough π
so if you want to fill in some string β like, say, FILL ME β for missing variables, you can use the hash_with_default() utility. for example:
use Text::Xslate::Util qw(hash_with_default);
$tx->render($name, hash_with_default(\%vars, sub { "FILL ME '@_' " }) );
β οΈ heads up bestie: note that this is really slow because it is a tied-hash wrapper. it's giving convenient but it's giving expensive π
π Customization of error messages π
you can customize error handlers with warn_handler and die_handler. and inside those handlers you can call the Text::Xslate->print() method so you can add your own custom messages to the output buffer, which makes debugging so much easier π«Ά
#!perl -w
use strict;
use Text::Xslate;
my %vpath = (
hello => 'Hello, <: $lang :> world!' . "\n",
);
my $tx = Text::Xslate->new(
path => \%vpath,
verbose => 2,
warn_handler => sub { Text::Xslate->print('[[', @_, ']]') },
);
print $tx->render('hello', { });
# => Hello, [[use nil to print at ...]] world!
π SEE ALSO π
Text::XslateText::Xslate::Manual
and that's the whole vibe check, bestie π
this was perl v5.42.3, dated 2026-08-22, from your girl Text::...bugging(3pm) β go forth and debug slayfully β¨π¦π
π¦ where this page comes from
- ubuntu stonking: libtext-xslate-perl 3.5.9-2build2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms