NAME
Number::Object - pluggable number object
SYNOPSIS
use
Number::Object;
my
$num
= Number::Object->new(1000);
$num
->filtered(
'comma'
);
# 1,000
$num
->value(20000);
$num
;
# 20000
$num
->value(100);
my
$clone1
=
$num
->clone;
my
$clone2
=
$num
->clone(300);
"$num, $clone1, $clone2"
;
# 100, 100, 300
using component and plugin
use
Number::Object;
Number::Object->load_components(
qw/ Autocall::Autoload /
);
Number::Object->load_plugins(
qw/ Tax::JP /
);
my
$num
= Number::Object->new(10000);
$num
->tax;
# 500
$num
->include_tax;
# 10500
$num
->include_tax->filtered(
'comma'
);
# 10,500
using component and plugin # simple
my
$num
= Number::Object->new(10000);
$num
->tax;
# 500
$num
->include_tax;
# 10500
$num
->include_tax->filtered(
'comma'
);
# 10,500
in your module
DESCRIPTION
Number::Object is pluggable number object.
the method that want to be added to number can be added to pluggable. original number object can be made by succeeding to Number::Object.
please refer to Class::Component for the method of making plugin and component.
FILTER
filter used by the filtered method can be added. please refer to mounting Number::Object::Filter::Comma .
OVERLOAD
when the arithmetic operation and comparing it, it is converted into an automatically usual numerical value.
my
$num
= Number::Object->new(100);
(
ref
(
$num
) ||
$num
);
# Number::Object
my
$cast
=
$num
+ 10;
(
ref
(
$cast
) ||
$cast
);
# 110
but, the object is returned by the clone method as for same methods of the plugin.
my
$price
= Number::Object->new(100, {
load_plugins
=> [
qw/ Tax /
],
config
=> {
Tax
=> {
rate
=> 1.5 }
}
});
(
ref
(
$price
) ||
$price
);
# Number::Object
my
$tax
=
$price
->include_tax;
(
ref
(
$tax
) ||
$tax
);
# Number::Object
$tax
;
# 150
with ++ and -- the operator cannot be used.
my
$counter
= Number::Object->new(0);
$counter
++;
# Died
$counter
--;
# Died
++
$counter
;
# Died
--
$counter
;
# Died
former object disappears when operator such as += is used.
my
$assign
= Number::Object->new(100);
$assign
+= 100;
(
ref
(
$assign
) ||
$assign
);
# 200
METHODS
HOOKS
AUTHOR
Kazuhiro Osawa <yappo {at} shibuya {dot} pl>
SEE ALSO
LICENSE
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.