Form::Tiny::Plugin - base class for Form::Tiny plugins
package Form::Tiny::Plugin::MyPlugin; use parent 'Form::Tiny::Plugin'; sub plugin { my ($self, $caller, $context) = @_; return { subs => { subname => sub { ... }, }, roles => ['My::Role', ...], meta_roles => ['My::Meta::Role', ...], }; }
If you wish to extend Form::Tiny, plugins system is your best bet. It allows you to specify:
subs which will be added to the namespace
roles which will be composed to the package
meta roles which will be composed to the meta object
You may specify all, any, or none of those in the resulting hashref of the plugin method. It will be called in class context:
plugin
Form::Tiny::Plugin::MyPlugin->($caller, $context);
Where:
$caller will be the package that called use Form::Tiny with your plugin
$caller
use Form::Tiny
$context will be a scalar reference to the current field context of the form
$context
The context may be referencing either Form::Tiny::FieldDefinition or Form::Tiny::FieldDefinitionBuilder (depending on whether the field was dynamic).
To use your plugin in a form, Form::Tiny must be imported like this:
use Form::Tiny plugins => [qw(MyPlugin +Full::Namespace::Plugin)];
Prepending the name with a plus sign will stop Form::Tiny from prepending the given name with Form::Tiny::Plugin::.
Form::Tiny::Plugin::
Your plugin package must inherit from Form::Tiny::Plugin and must reintroduce the plugin method (without calling SUPER::plugin).
Form::Tiny::Plugin
SUPER::plugin
To install Form::Tiny, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Form::Tiny
CPAN shell
perl -MCPAN -e shell install Form::Tiny
For more information on module installation, please visit the detailed CPAN module installation guide.