If you enable the TRACE_VARS
option on the template context then you can use the variables
method to get a hash of all the values accessed.
This code shows a brief example
use strict;
use warnings;
use Template::Context;
use Data::Dump;
my $template = '[% person.name %] <[% person.email %]>';
my $context = Template::Context->new(TRACE_VARS => 1);
my $compiled = $context->template(\$template) or die $context->error;
my $variables = $compiled->variables;
dd $variables;
output
{ person => { email => {}, name => {} } }