BEGIN { use Template::Context; no strict; no warnings; my $sub = *{$Template::Context::{include}}{CODE}; *Template::Context::include = sub { _wrapper( $sub, @_ ); }; $sub = *{$Template::Context::{process}}{CODE}; *Template::Context::process = sub { _wrapper( $sub, @_ ); }; } sub _wrapper { my $sub = shift; my $tmpl; if ( ! ref $_[1] ) { # [% INCLUDE ... %] $tmpl = $_[1]; } else { # $template->process(...) $tmpl = $_[1]->{name}; } my $data = $sub->(@_); $data = "\n$data\n"; return $data; }