Template-Multipass
view release on metacpan or search on metacpan
lib/Template/Multipass.pm view on Meta::CPAN
# this config is captured and then localized.
# no guarantee as to which parts in TT respect a change of config, but it works for most values (e.g. START_TAG, END_TAG)
$self->{_multipass}{captured_config} = $config;
# this is where meta config overrides are stored
my $opts = $config->{MULTIPASS};
$self->{_multipass}{config} = $opts;
$self->{_multipass}{vars} = $opts->{VARS} || {};
my $overlay = {
$self->default_meta_options,
%$opts,
};
delete $overlay->{VARS};
$self->{_multipass}{config_overlay} = $overlay;
$self->SUPER::_init( $config, @args );
Data::Visitor::Callback->new(
ignore_return_values => 1,
'Template::Base' => "visit_ref",
'Template::Provider' => sub { $_ = Template::Multipass::Provider->new( provider => $_, template => $self, config => $config ) },
)->visit( $self );
return $self;
lib/Template/Multipass.pm view on Meta::CPAN
my ( $self, $provider, $method, @args ) = @_;
# ignore all other providers in the recursion
local $self->context->{LOAD_TEMPLATES} = [ $provider ];
local $self->context->{PREFIX_MAP} = {};
# process( ...., { meta_opts => { blah } } ) causes { blah } to be given to the inner process used on the meta template
my $opts = $self->{_multipass}{captured_process_opts}{meta_opts} || {};
# calculate the configuration and variables for the meta pass
my $overlay = $self->{_multipass}{config_overlay}; # constructed at _init
local @{ $self->{_multipass}{captured_config} }{ keys %$overlay } = values %$overlay; # START_TAG, END_TAG etc
my $vars = $self->{_multipass}{merged_meta_vars}; # merged by process at the top of the call chain
local $@;
# dispatch the original method on the provider, getting the original result
my ( $doc, $error ) = $provider->$method( @args ); # method is _fetch or _load, or in the case of scalar refs a coderef prepared by the wrapper provider
my $out;
# reconfigure WRAPPER, PRE_PROCES, PROCESS etc for the meta pass by
lib/Template/Multipass.pm view on Meta::CPAN
demonstrated in the L</SYNOPSIS>.
Template::Multipass will first process the template with only the meta
variables, and cache the result. Then it will process the file again with all
of the variables. Subsequent runs will not have to recompute the meta var run
unless the variables have been changed.
=head1 CONFIGURATION
The configuration values inside C<MULTIPASS> in the top level config will be
overlayed on top of the normal config during meta template processing. This
works for values such as C<START_TAG> and C<END_TAG> (which default to C<{%>
and C<%}>), and may work for other values.
Additionallly the C<MULTIPASS> hash can take a C<VARS> hash to be used as the
meta vars in all runs.
This var hash can be further added by passing them as an option to process:
$t->process( $template, $vars, $output, { meta_vars => { ... more vars ... } } );
( run in 1.027 second using v1.01-cache-2.11-cpan-49f99fa48dc )