App-Templer
view release on metacpan or search on metacpan
lib/Templer/Plugin/Factory.pm view on Meta::CPAN
}
}
}
=head2 register_formatter
This method should be called by all formatting plugins to register
themselves. The two arguments are the name of the input-format,
and the class-name which may be instantiated to process that kind
of input.
L<Templer::Plugin::Textile> and L<Templer::Plugin::Markdown> are
example classes.
=cut
sub register_formatter
{
my ( $self, $name, $obj ) = (@_);
die "No name" unless ($name);
$name = lc($name);
$self->{ 'formatters' }{ $name } = $obj;
}
=head2 register_filter
This method should be called by all template filter plugins to register
themselves. The two arguments are the name of the template-filter,
and the class-name which may be instantiated to process that kind
of input.
L<Templer::Plugin::Dollar> and L<Templer::Plugin::Strict> are
example classes.
=cut
sub register_filter
{
my ( $self, $name, $obj ) = (@_);
die "No name" unless ($name);
$name = lc($name);
$self->{ 'filters' }{ $name } = $obj;
}
=head2 register_plugin
This method should be called by all variable-expanding plugins to register
themselves. The expected argument is the class-name which may be instantiated
to expand variables.
L<Templer::Plugin::ShellCommand>, L<Templer::Plugin::FileGlob>, and
L<Templer::Plugin::FileContents> are examples of such plugins.
NOTE: The plugin is instantiated immediately, and kept alive for the duration
of a templer-run.
=cut
sub register_plugin
{
my ( $self, $obj ) = (@_);
push( @{ $self->{ 'plugins' } }, $obj->new() );
}
=head2 expand_variables
Expand variables via all loaded plugins.
=cut
sub expand_variables
{
my ( $self, $site, $page, $data ) = (@_);
my $out;
foreach my $plugin ( @{ $self->{ 'plugins' } } )
{
if ( UNIVERSAL::can( $plugin, "expand_variables" ) )
{
my %in = %$data;
$out = $plugin->expand_variables( $site, $page, \%in );
$data = \%$out;
}
}
return ($data);
}
=head2 cleanup
For each loaded plugin invoke the "cleanup" method, if it exists.
This can be useful if you wish a plugin to generate a site-map, or similar.
=cut
sub cleanup
{
my ($self) = (@_);
foreach my $plugin ( @{ $self->{ 'plugins' } } )
{
if ( UNIVERSAL::can( $plugin, "cleanup" ) )
{
$plugin->cleanup();
}
}
}
( run in 1.902 second using v1.01-cache-2.11-cpan-df04353d9ac )