A templating system that allow only minimal interaction with the outside world would become boring pretty quickly—most of the interesting stuff is going to be outside our templates, not inside. This chapter covers the Template Toolkit plugin system, designed to make interfacing with the outside world as simple as possible.
In the Template Toolkit, a plugin provides extra functionality that is otherwise not possible using only the core language. Many plugins create template-facing interfaces between external resources, such as a database or mail server, while some plugins provide tidy interfaces for complex formatting operations. Plugins allow developers to add functionality without having to modify or override core Template Toolkit components.
To a large extent, plugins are what give the Template Toolkit its power and flexibility: if the basic toolkit lacks the functionality you desire, it is very straightforward to add the functionality by creating plugins. External modules, designed without the Template Toolkit in mind, can be subverted for use within templates with just a little glue code. At the same time, however, a plugin can be used to enforce privacy within a module, and to make methods inaccessible, ensuring that the modules get used only as anticipated.
Unlike filters, which exist primarily to postprocess text, a plugin is unlimited in scope. The most popular use for plugins is to integrate other Perl modules—many, if not most, of the thousands of modules ...