Business::Price - Handles prices with tax and discount
version 1.000_1
use Business::Price; my $price = Business::Price->new( value => 10, tax => 0.1, discount => 0.5 ); is( $price->full, 11 ); is( $price->full->discounted, 5.5 );
Required
The object stringifies to this attribute.
Default: 0
Defines the tax rate. Valid values are from 0 to 1 (excluded).
Specifies whether value includes tax or not.
Methods will always return a new Business::Price object. It stringifies to value and you can do math on those object since it uses overload.
my $price = Business::Price->new( value => 10 ); ok( $price->isa('Business::Price') ); is( $price, 10 ); is( $price / 2, 5 );
Returns an object with the net price applied (i.e. without tax).
my $price = Business::Price->new( value => 1.1, tax => 0.1, incl => 1); is( $price->net, 1 );
Returns an object with the full price applied (i.e. tax applied).
my $price = Business::Price->new( value => 1, tax => 0.1 ); is( $price->full, 1.1 );
Discount the price by the format defined in discount.
my $price = Business::Price->new( value => 1, discount => 0.5 ); is( $price->discounted, 0.5 ); is( $price->discounted->discounted, 0.25 ); my $price = Business::Price->new( value => 1, discount => sub { my ( $self, $is_reseller ) = @_; return $is_reseller ? $self / 2 : $self; } ); is( $price->discounted(0), 1 ); is( $price->discounted(1), 0.5 );
Clone the object. Any parameters overwrite the object's attributes.
my $price_excl = Business::Price->new( value => 1, incl => 0 ); my $price_incl = $price->clone( incl => 1 );
Business::Tax::Canada, Business::Tax::VAT, Moose
Moritz Onken <onken@netcubed.de>
This software is Copyright (c) 2010 by Moritz Onken.
This is free software, licensed under:
The (three-clause) BSD License
To install Business::Price, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Business::Price
CPAN shell
perl -MCPAN -e shell install Business::Price
For more information on module installation, please visit the detailed CPAN module installation guide.