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,
}
Mandatory. Takes a hashref as a value. 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, undef
s 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.
AUTHOR
'Zoffix, <'zoffix at cpan.org'>
(http://haslayout.net/, http://zoffix.com/, http://zofdesign.com/)
BUGS
Please report any bugs or feature requests to bug-app-zofcms-plugin-googlecalculator at rt.cpan.org
, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-ZofCMS-Plugin-GoogleCalculator. 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::GoogleCalculator
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=App-ZofCMS-Plugin-GoogleCalculator
AnnoCPAN: Annotated CPAN documentation
CPAN Ratings
http://cpanratings.perl.org/d/App-ZofCMS-Plugin-GoogleCalculator
Search CPAN
http://search.cpan.org/dist/App-ZofCMS-Plugin-GoogleCalculator/
COPYRIGHT & LICENSE
Copyright 2009 'Zoffix, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.