XAO::DO::Web::Math - calculate and output a value
<%Math formula='{x}+{y}' value.x='2' value.y='3'%>
Given a formula and some values calculates the result and displays it optionally formatting according to the given format:
<%Math formula='{x}+{y}' value.x='2' value.y='3'%> -- output '5' <%Math formula='1/{x}' value.x='3' format='%.3'%> -- output '0.333' <%Math formula='1 / ({a} - {b})' value.a='7' value.b='7' default='-'%> -- output '-'
Formulas should not be received from untrusted sources. They are 'eval'ed to calculate the result. Some care is taken to avoid illegal formulas, but there are no guarantees.
When an operation cannot be performed (division by zero for instance) the result is 'default' value or empty if not set. Illegal arguments, such as non-numeric, produce the same result.
If a 'path' or 'template' is given then the result is shown in that template with the following parameters:
FORMULA => formula with substituted values, as calculated RESULT => calculation result ERROR => error message if calculation could not be performed ERRCODE => more concise error code (FORMULA, VALUE, FUNCTION, CALCULATE)
Some mathematical functions are also supported: min(), max(), sum(), abs(), and sqrt(). The first three work on any number of arguments.
Nothing.
Copyright (c) 2012 Andrew Maltsev
<am@ejelta.com> -- http://ejelta.com/xao/
Recommended reading: XAO::Web, XAO::DO::Web::Page.
To install XAO::Web, copy and paste the appropriate command in to your terminal.
cpanm
cpanm XAO::Web
CPAN shell
perl -MCPAN -e shell install XAO::Web
For more information on module installation, please visit the detailed CPAN module installation guide.