| Number-Object documentation | Contained in the Number-Object distribution. |
Number::Object::Plugin::Tax - tax calc
my $price = Number::Object->new(100, {
load_plugins => [qw/ Tax /],
config => {
Tax => { rate => 1.5, method => 'ceil' }
}
});
tax rate
Method of processing decimal point.
floor or ceil( default is floor )
Kazuhiro Osawa <ko@yappo.ne.jp>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
| Number-Object documentation | Contained in the Number-Object distribution. |
package Number::Object::Plugin::Tax; use strict; use warnings; use base 'Class::Component::Plugin'; use POSIX (); our $RATE = '1.05'; sub tax :Method { my($self, $c, $args) = @_; $c->clone($self->calc($c)); } sub include_tax :Method { my($self, $c, $args) = @_; $c->clone($self->calc($c) + $c->{value}); } sub calc { my($self, $c, $rate) = @_; $rate ||= $self->config->{rate} || 1; my $price = $c->{value}; my $method = $self->config->{method} || 'floor'; $method = 'floor' unless $method eq 'ceil'; $method = "calc_$method"; $self->$method(($price * $rate) - $price); } sub calc_floor { my($self, $price) = @_; POSIX::floor($price); } sub calc_ceil { my($self, $price) = @_; POSIX::ceil($price); } 1; __END__