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

App::ZofCMS::Plugin::Base - base class for App::ZofCMS plugins

SYNOPSIS

    package App::ZofCMS::Plugin::Example;

    use strict;
    use warnings;
    use base 'App::ZofCMS::Plugin::Base';

    sub _key { 'plug_example' }
    sub _defaults {
        qw/foo bar baz beer/
    }
    sub _do {
        my ( $self, $conf, $t, $q, $config ) = @_;
    }

DESCRIPTION

The module is a base class for App::ZofCMS plugins. I'll safely assume that you've already read the docs for App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template

The base class (currently) is only for plugins who take their "config" as a single first-level key in either Main Config File or ZofCMS Template. That key's value must be a hashref or a subref that returns a hashref or undef.

SUBS TO OVERRIDE

_key

    sub _key { 'plug_example' }

The _key needs to return a scalar contain the name of first level key in ZofCMS template or Main Config file. Study the source code of this module to find out what it's used for if it's still unclear. The value of that key can be either a hashref or a subref that returns a hashref or undef. If the value is a subref, its return value will be assigned to the key and its @_ will contain (in that order): $t, $q, $conf where $t is ZofCMS Template hashref, $q is hashref of query parameters and $conf is App::ZofCMS::Config object.

_defaults

    sub _defaults { qw/foo bar baz beer/ }

The _defaults sub needs to return a list of default arguments in a key/value pairs. By default it returns an empty list.

_do

    sub _do {
        my ( $self, $conf, $template, $query, $config ) = @_;
    }

The _do sub is where you'd do all of your processing. The @_ will contain $self, $conf, $template, $query and $config (in that order) where $self is your plugin's object, $conf is the plugin's configuration hashref (what the user would specify in ZofCMS Template or Main Config File, the key of which is returned by _key() sub), the $template is the hashref of ZofCMS template that is being processed, the $query is a query parameters hashref where keys are names of the params and values are their values. Finally, the $config is App::ZofCMS::Config object.

MOAR!

Feel free to email me the requests for extra functionality for this base class.

DOCUMENTATION FOR PLUGINS

Below is a "template" documentation. If you're going to use it, make sure to read through the entire thing as some things may not apply to your plugin; I've added those bits as they are very common in the plugins that I write, some of them (but not all) I marked with word [EDIT]

    =head1 DESCRIPTION

    The module is a plugin for L<App::ZofCMS> that provides means to [EDIT].

    This documentation assumes you've read L<App::ZofCMS>, L<App::ZofCMS::Config> and L<App::ZofCMS::Template>

    =head1 FIRST-LEVEL ZofCMS TEMPLATE AND MAIN CONFIG FILE KEYS

    =head2 C<plugins>

        plugins => [
            { [EDIT] => 2000 },
        ],

    B<Mandatory>. You need to include the plugin in the list of plugins to execute.

    =head2 C<[EDIT]>

        [EDIT] => {
        },

        # or
        [EDIT] => sub {
            my ( $t, $q, $config ) = @_;
        },

    B<Mandatory>. Takes either a hashref or a subref as a value. If subref is specified,
    its return value will be assigned to C<[EDIT]> as if it was already there. If sub returns
    an C<undef>, then plugin will stop further processing. The C<@_> of the subref will
    contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and
    L<App::ZofCMS::Config> object. [EDIT]. Possible keys/values for the hashref
    are as follows:

    =head3 C<cell>

        [EDIT] => {
            cell => 't',
        },

    B<Optional>. Specifies ZofCMS Template first-level key where to [EDIT]. Must be
    pointing to either a hashref or an C<undef> (see C<key> below). B<Defaults to:> C<t>

    =head3 C<key>

        [EDIT] => {
            key => '[EDIT]',
        },

    B<Optional>. Specifies ZofCMS Template second-level key where to [EDIT]. This key will
    be inside C<cell> (see above)>. B<Defaults to:> C<[EDIT]>

AUTHOR

'Zoffix, <'zoffix at cpan.org'> (http://zoffix.com/, http://haslayout.net/, http://zofdesign.com/)

BUGS

Please report any bugs or feature requests to bug-app-zofcms-plugin-base at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-Base. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

    perldoc App::ZofCMS::Plugin::Base

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2008 'Zoffix, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.