@@ -1,30 +1,27 @@
package Template::Plugin::Number::Format;
# ----------------------------------------------------------------------
-# $Id: Format.pm,v 1.1 2002/07/30 12:13:40 dlc Exp dlc $
-# ----------------------------------------------------------------------
# Template::Plugin::Number::Format - Plugin/filter interface to Number::Format
-# Copyright (C) 2002 darren chamberlain <darren@cpan.org>
+# Copyright (C) 2002-2015 Darren Chamberlain <darren@cpan.org>
#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; version 2.
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-# 02111-1307 USA
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
# -------------------------------------------------------------------
use strict;
use vars qw($VERSION $DYNAMIC $AUTOLOAD);
-$VERSION = '1.02';
+$VERSION = '1.06';
$DYNAMIC = 1;
use Number::Format;
@@ -1,5 +1,7 @@
Format.pm
Makefile.PL
MANIFEST
-test.pl
+t/01.t
+README
META.yml Module meta-data (added by MakeMaker)
+META.json Module JSON meta-data (added by MakeMaker)
@@ -0,0 +1,42 @@
+{
+ "abstract" : "unknown",
+ "author" : [
+ "unknown"
+ ],
+ "dynamic_config" : 1,
+ "generated_by" : "ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.133380",
+ "license" : [
+ "unknown"
+ ],
+ "meta-spec" : {
+ "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
+ "version" : "2"
+ },
+ "name" : "Template-Plugin-Number-Format",
+ "no_index" : {
+ "directory" : [
+ "t",
+ "inc"
+ ]
+ },
+ "prereqs" : {
+ "build" : {
+ "requires" : {
+ "ExtUtils::MakeMaker" : "0"
+ }
+ },
+ "configure" : {
+ "requires" : {
+ "ExtUtils::MakeMaker" : "0"
+ }
+ },
+ "runtime" : {
+ "requires" : {
+ "Number::Format" : "0",
+ "Template" : "2.07"
+ }
+ }
+ },
+ "release_status" : "stable",
+ "version" : "1.06"
+}
@@ -1,12 +1,23 @@
-# http://module-build.sourceforge.net/META-spec.html
-#XXXXXXX This is a prototype!!! It will change in the future!!! XXXXX#
-name: Template-Plugin-Number-Format
-version: 1.02
-version_from: Format.pm
-installdirs: site
+---
+abstract: unknown
+author:
+ - unknown
+build_requires:
+ ExtUtils::MakeMaker: 0
+configure_requires:
+ ExtUtils::MakeMaker: 0
+dynamic_config: 1
+generated_by: 'ExtUtils::MakeMaker version 6.66, CPAN::Meta::Converter version 2.133380'
+license: unknown
+meta-spec:
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: 1.4
+name: Template-Plugin-Number-Format
+no_index:
+ directory:
+ - t
+ - inc
requires:
- Number::Format: 0
- Template: 2.07
-
-distribution_type: module
-generated_by: ExtUtils::MakeMaker version 6.30_01
+ Number::Format: 0
+ Template: 2.07
+version: 1.06
@@ -11,4 +11,7 @@ WriteMakefile(
clean => {
FILES => 'Template-Plugin-Number-Format-$(VERSION).tar.gz',
},
+ dist => {
+ PREOP => 'perldoc -t Format.pm > README',
+ },
);
@@ -0,0 +1,125 @@
+NAME
+ Template::Plugin::Number::Format - Plugin/filter interface to
+ Number::Format
+
+SYNOPSIS
+ [% USE Number.Format %]
+ [% num | format_number %]
+
+ABSTRACT
+ Template::Plugin::Number::Format makes the number-munging grooviness of
+ Number::Format available to your templates. It is used like a plugin,
+ but installs filters into the current context.
+
+DESCRIPTION
+ All filters created by Template::Plugin::Number::Format can be
+ configured by constructor options and options that can be passed to
+ individual filters. See "METHODS" in Number::Format for all the details.
+
+ Constructor Parameters
+ The USE line accepts the following parameters, all optional, which
+ define the default behavior for filters within the current Context:
+
+ THOUSANDS_SEP
+ character inserted between groups of 3 digits
+
+ DECIMAL_POINT
+ character separating integer and fractional parts
+
+ MON_THOUSANDS_SEP
+ like THOUSANDS_SEP, but used for format_price
+
+ MON_DECIMAL_POINT
+ like DECIMAL_POINT, but used for format_price
+
+ INT_CURR_SYMBOL
+ character(s) denoting currency (see format_price())
+
+ DECIMAL_DIGITS
+ number of digits to the right of dec point (def 2)
+
+ DECIMAL_FILL
+ boolean; whether to add zeroes to fill out decimal
+
+ NEG_FORMAT
+ format to display negative numbers (def -x)
+
+ KILO_SUFFIX
+ suffix to add when format_bytes formats kilobytes
+
+ MEGA_SUFFIX
+ suffix to add when format_bytes formats megabytes
+
+ GIGA_SUFFIX
+ suffix to add when format_bytes formats gigabytes
+
+Using Template::Plugin::Number::Format
+ When you invoke:
+
+ [% USE Number.Format(option = value) %]
+
+ the following filters are installed into the current Context:
+
+ round($precision)
+ Rounds the number to the specified precision. If "$precision" is
+ omitted, the value of the "DECIMAL_DIGITS" parameter is used
+ (default value 2).
+
+ format_number($precision, $trailing_zeros)
+ Formats a number by adding "THOUSANDS_SEP" between each set of 3
+ digits to the left of the decimal point, substituting
+ "DECIMAL_POINT" for the decimal point, and rounding to the specified
+ precision using "round()". Note that "$precision" is a maximum
+ precision specifier; trailing zeroes will only appear in the output
+ if "$trailing_zeroes" is provided, or the parameter "DECIMAL_FILL"
+ is set, with a value that is true (not zero, undef, or the empty
+ string). If "$precision" is omitted, the value of the
+ "DECIMAL_DIGITS" parameter (default value of 2) is used.
+
+ format_negative($picture)
+ Formats a negative number. Picture should be a string that contains
+ the letter "x" where the number should be inserted. For example, for
+ standard negative numbers you might use "-x", while for accounting
+ purposes you might use "(x)". If the specified number begins with a
+ - character, that will be removed before formatting, but formatting
+ will occur whether or not the number is negative.
+
+ format_picture($picture)
+ Returns a string based on "$picture" with the "#" characters
+ replaced by digits from "$number". If the length of the integer part
+ of $number is too large to fit, the "#" characters are replaced with
+ asterisks ("*") instead.
+
+ format_price($precision)
+ Returns a string containing "$number" formatted similarly to
+ "format_number()", except that the decimal portion may have trailing
+ zeroes added to make it be exactly "$precision" characters long, and
+ the currency string will be prefixed.
+
+ If the "INT_CURR_SYMBOL" attribute of the object is the empty
+ string, no currency will be added.
+
+ If "$precision" is not provided, the default of 2 will be used.
+
+ format_bytes($precision)
+ Returns a string containing "$number" formatted similarly to
+ "format_number()", except that if the number is over 1024, it will
+ be divided by 1024 and the value of KILO_SUFFIX appended to the end;
+ or if it is over 1048576 (1024*1024), it will be divided by 1048576
+ and MEGA_SUFFIX appended to the end. Negative values will result in
+ an error.
+
+ If "$precision" is not provided, the default of 2 will be used.
+
+ unformat_number
+ Converts a string as returned by "format_number()",
+ "format_price()", or "format_picture()", and returns the
+ corresponding value as a numeric scalar. Returns "undef" if the
+ number does not contain any digits.
+
+SEE ALSO
+ Template, Number::Format
+
+AUTHOR
+ darren chamberlain <darren@cpan.org>
+
@@ -0,0 +1,115 @@
+#!/usr/bin/perl
+# vim: set ft=perl:
+
+use strict;
+use POSIX qw(setlocale LC_ALL);
+use Template::Test;
+use Template::Plugin::Number::Format;
+
+$Template::Test::DEBUG = 0;
+
+my %vars = (
+ "data1" => "1234567890",
+ "data2" => "1029384756",
+ "neg" => "-30949043",
+ "dec1" => "1937849302.309498032",
+ "dec2" => "42.9",
+);
+
+setlocale(LC_ALL, "C");
+test_expect(\*DATA, undef, \%vars);
+
+__DATA__
+-- test --
+-- name round --
+[% USE Number.Format -%]
+[% dec1 | round %]
+-- expect --
+1937849302.31
+
+-- test --
+-- name format_number --
+[% USE Number.Format -%]
+[% data1 | format_number %]
+-- expect --
+1,234,567,890
+
+-- test --
+-- name format_number --
+[% USE Number.Format -%]
+[% dec2 | format_number(5) %]
+-- expect --
+42.9
+
+-- test --
+-- name format_number --
+[% USE Number.Format -%]
+[% dec2 | format_number(5, 5) %]
+-- expect --
+42.90000
+
+-- test --
+-- name format_negative --
+[% USE Number.Format -%]
+[% neg | format_negative %]
+-- expect --
+-30949043
+
+-- test --
+-- name format_negative --
+[% USE Number.Format -%]
+[% neg | format_negative("(x)") %]
+-- expect --
+(30949043)
+
+-- test --
+-- name format_negative --
+[% USE Number.Format(NEG_FORMAT = "(x)") -%]
+[% neg | format_negative %]
+-- expect --
+(30949043)
+
+-- test --
+-- name format_price --
+[% USE Number.Format -%]
+[% dec2 | format_price %]
+-- expect --
+USD 42.90
+
+-- test --
+-- name format_bytes --
+[% USE Number.Format -%]
+[% data1 | format_bytes %]
+-- expect --
+1.15G
+
+-- test --
+-- name format_bytes --
+[% USE Number.Format(GIGA_SUFFIX = 'g') -%]
+[% data1 | format_bytes %]
+-- expect --
+1.15g
+
+-- test --
+-- name unformat_number --
+[% USE Number.Format -%]
+[% data1 | format_number | unformat_number %]
+-- expect --
+-- process --
+[% data1 %]
+
+-- test --
+-- name plugin test --
+[% USE nf = Number.Format -%]
+[% nf.format_number(data1) %]
+-- expect --
+-- process --
+1,234,567,890
+
+-- test --
+-- name filter plugin test --
+[% USE nf = Number.Format -%]
+[% data1 | $nf %]
+-- expect --
+-- process --
+1,234,567,890
@@ -1,118 +0,0 @@
-#!/usr/bin/perl
-# vim: set ft=perl:
-
-use strict;
-use Template::Test;
-use Template::Plugin::Number::Format;
-
-my %vars = (
- "data1" => "1234567890",
- "data2" => "1029384756",
- "neg" => "-30949043",
- "dec1" => "1937849302.309498032",
- "dec2" => "42.9",
-);
-
-test_expect(\*DATA, undef, \%vars);
-
-__DATA__
--- test --
--- name round --
-[% USE Number.Format -%]
-[% dec1 | round %]
--- expect --
-1937849302.31
-
--- test --
--- name format_number --
-[% USE Number.Format -%]
-[% data1 | format_number %]
--- expect --
-1,234,567,890
-
--- test --
--- name format_number --
-[% USE Number.Format -%]
-[% dec2 | format_number(5) %]
--- expect --
-42.9
-
--- test --
--- name format_number --
-[% USE Number.Format -%]
-[% dec2 | format_number(5, 5) %]
--- expect --
-42.90000
-
--- test --
--- name format_negative --
-[% USE Number.Format -%]
-[% neg | format_negative %]
--- expect --
--30949043
-
--- test --
--- name format_negative --
-[% USE Number.Format -%]
-[% neg | format_negative("(x)") %]
--- expect --
-(30949043)
-
--- test --
--- name format_negative --
-[% USE Number.Format(NEG_FORMAT = "(x)") -%]
-[% neg | format_negative %]
--- expect --
-(30949043)
-
--- test --
--- name format_price --
-[% USE Number.Format -%]
-[% dec2 | format_price %]
--- expect --
-USD 42.90
-
--- test --
--- name format_price --
-[% USE Number.Format(INT_CURR_SYMBOL = '$') -%]
-[% dec2 | format_price %]
--- expect --
-$ 42.90
-
--- test --
--- name format_bytes --
-[% USE Number.Format -%]
-[% data1 | format_bytes %]
--- expect --
-1.15G
-
--- test --
--- name format_bytes --
-[% USE Number.Format(GIGA_SUFFIX = 'g') -%]
-[% data1 | format_bytes %]
--- expect --
-1.15g
-
--- test --
--- name unformat_number --
-[% USE Number.Format -%]
-[% data1 | format_number | unformat_number %]
--- expect --
--- process --
-[% data1 %]
-
--- test --
--- name plugin test --
-[% USE nf = Number.Format -%]
-[% nf.format_number(data1) %]
--- expect --
--- process --
-1,234,567,890
-
--- test --
--- name filter plugin test --
-[% USE nf = Number.Format -%]
-[% data1 | $nf %]
--- expect --
--- process --
-1,234,567,890