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::Xslate
  • Text::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