Zoffix Znet > App-ZofCMS > App::ZofCMS::Plugin::GoogleCalculator

Download:
App-ZofCMS-1.001004.tar.gz

Dependencies

Annotate this POD

Website

View/Report Bugs
Module Version: 1.001004   Source  

NAME ^

App::ZofCMS::Plugin::GoogleCalculator - simple plugin to interface with Google calculator

SYNOPSIS ^

In ZofCMS Template or Main Config File:

    plugins => [
        qw/GoogleCalculator/
    ],
    plug_google_calculator => {},

In HTML::Template template:

    <form action="" method="POST">
    <div>
        <label>Enter an expression: <input type="text" name="calc"></label>
        <input type="submit" value="Calculate">
    </div>
    </form>

    <tmpl_if name='plug_google_calculator_error'>
        <p class="error">Got error: <tmpl_var escape='html' name='plug_google_calculator_error'></p>
    <tmpl_else>
        <p>Result: <tmpl_var escape='html' name='plug_google_calculator'></p>
    </tmpl_if>

DESCRIPTION ^

The module is a plugin for App::ZofCMS that provides a simple interface to Google calculator (http://www.google.com/help/calculator.html). This documentation assumes you've read App::ZofCMS, App::ZofCMS::Config and App::ZofCMS::Template

FIRST-LEVEL ZofCMS TEMPLATE AND MAIN CONFIG FILE KEYS ^

plugins

    plugins => [
        qw/GoogleCalculator/
    ],

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

plug_google_calculator

    plug_google_calculator => {}, # run with all the defaults


    plug_google_calculator => {  ## below are the default values
        from_query => 1,
        q_name     => 'calc',
        expr       => undef,
    }

    plug_google_calculator => sub {  # set configuration via a subref
        my ( $t, $q, $config ) = @_;
        return {
            from_query => 1,
            q_name     => 'calc',
            expr       => undef,
        };
    }

Mandatory. Takes a hashref or a subref as a value. If subref is specified, its return value will be assigned to plug_google_calculator as if it was already there. If sub returns an undef, then plugin will stop further processing. The @_ of the subref will contain (in that order): ZofCMS Tempalate hashref, query parameters hashref and App::ZofCMS::Config object. To run with all the defaults, pass an empty hashref. Hashref's keys/values are as follows:

from_query

    plug_google_calculator => {
        from_query  => 1,
    }

Optional. Takes either true or false values. When set to a true value, the expression to calculate will be taken from query parameters and parameter's name will be derived from q_name argument (see below). When set to a false value, the expression will be taken from expr argument (see below) directly. Defaults to: 1

q_name

    plug_google_calculator => {
        q_name     => 'calc',

Optional. When from_query argument is set to a true value, specifies the name of the query parameter from which to gather the expression to calculate. Defaults to: calc

expr

    plug_google_calculator => {
        expr       => '2*2',
    }

    plug_google_calculator => {
        expr       => sub {
            my ( $t, $q, $config ) =  @_;
            return '2' . $q->{currency} ' in CAD';
        },
    }

Optional. When from_query argument is set to a false value, specifies the expression to calculate. Takes either a literal expression as a string or a subref as a value. When set to a subref, subref will be executed and its return value will be assigned to expr as if it was already there (note, undefs will cause the plugin to stop further processing). The sub's @_ will contain the following (in that order): ZofCMS Template hashref, query parameters hashref and App::ZofCMS::Config object. Defaults to: undef

PLUGIN OUTPUT ^

    <tmpl_if name='plug_google_calculator_error'>
        <p class="error">Got error: <tmpl_var escape='html' name='plug_google_calculator_error'></p>
    <tmpl_else>
        <p>Result: <tmpl_var escape='html' name='plug_google_calculator'></p>
    </tmpl_if>

plug_google_calculator

    <p>Result: <tmpl_var escape='html' name='plug_google_calculator'></p>

If result was calculated successfully, the plugin will set $t->{t}{plug_google_calculator} to the result string where $t is ZofCMS Template hashref.

plug_google_calculator_error

    <tmpl_if name='plug_google_calculator_error'>
        <p class="error">Got error: <tmpl_var escape='html' name='plug_google_calculator_error'></p>
    </tmpl_if>

If an error occured during the calculation, $t->{t}{plug_google_calculator_error} will be set to the error message where $t is ZofCMS Template hashref.

REPOSITORY ^

Fork this module on GitHub: https://github.com/zoffixznet/App-ZofCMS

BUGS ^

To report bugs or request features, please use https://github.com/zoffixznet/App-ZofCMS/issues

If you can't access GitHub, you can email your request to bug-App-ZofCMS at rt.cpan.org

AUTHOR ^

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

LICENSE ^

You can use and distribute this module under the same terms as Perl itself. See the LICENSE file included in this distribution for complete details.

syntax highlighting: