Template::Sandbox::NumberFunctions - Basic number functions library for Template::Sandbox.
use Template::Sandbox::NumberFunctions qw/:all/; # or: use Template::Sandbox::NumberFunctions; my $template = Template::Sandbox->new( library => [ Template::Sandbox::NumberFunctions => qw/ucfirst uc lc/ ], );
Library of basic string manipulation functions for easy import into a Template::Sandbox template.
int( number )
Rounds number down to the first integer of lower value as per Perl's int().
number
int()
round( number )
Rounds number to the nearest integer using mathematical rounding, that being 0.5 and greater being rounded up and everyhing below 0.5 being rounded down.
abs( number )
Return the absolute value of number as per Perl's abs() function.
abs()
numeric( number )
Reformat number for pretty display by adding thousands commas. Note that this does not respect locale.
currency( number )
Reformat number for pretty display by adding thousands commas and displaying to two decimal places. Note that this does not respect locale.
accountant_currency( number )
Reformat number for pretty display by adding thousands commas and displaying to two decimal places, additionally negative numbers will be displayed in round brackets rather than with a leading minus-sign. Note that this does not respect locale.
decimal( number, places )
Reformat number for display to places decimal places.
places
exp( number )
log( number )
pow( number, exponent )
sqrt( number )
Wrappers to corresponding Perl power functions (or ** operator for pow().)
pow()
rand( number | array )
Returns either a random number from 0 to number - 1, or if passed an array will return a random element from that array.
0
number - 1
srand( number )
Wrapper to srand() Perl function.
srand()
min( a, b )
max( a, b )
Returns the min or max value from a or b accordingly.
a
b
Exports all defined template functions in this library.
Exports exp, log, pow and sqrt.
exp
log
pow
sqrt
Exports numeric, currency, accountant_currency and decimal.
numeric
currency
accountant_currency
decimal
There's not really a great many functions in here, the module could be regarded as largely superfluous since you could easily recreate it yourself if you needed it. However it provides a useful example of how to write your own library of template functions.
The pretty display functions don't respect locale and aren't going to do what you want if you're expecting "." as your thousands seperator and "," as your decimal marker.
Template::Sandbox, Template::Sandbox::Library
You can find documentation for this module with the perldoc command.
perldoc Template::Sandbox::NumberFunctions
You can also look for information at:
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Template-Sandbox
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Template-Sandbox
CPAN Ratings
http://cpanratings.perl.org/d/Template-Sandbox
Search CPAN
http://search.cpan.org/dist/Template-Sandbox
Original author: Sam Graham <libtemplate-sandbox-perl BLAHBLAH illusori.co.uk>
Last author: $Author: illusori $
Copyright 2005-2010 Sam Graham, all rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
To install Template::Sandbox, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Template::Sandbox
CPAN shell
perl -MCPAN -e shell install Template::Sandbox
For more information on module installation, please visit the detailed CPAN module installation guide.