The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Form::Tiny::Plugin - base class for Form::Tiny plugins

SYNOPSIS

        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', ...],
                };
        }

DESCRIPTION

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:

        Form::Tiny::Plugin::MyPlugin->($caller, $context);

Where:

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::.

Your plugin package must inherit from Form::Tiny::Plugin and must reintroduce the plugin method (without calling SUPER::plugin).