The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

DR::Money - module to manipulate by money in perl scripts

SYNOPSIS

    my $m = Money(2.3);
    print $m;           # prints 2.30
    $m += 2.3;          # 4.60
    $m += Money(4.2);   # 8.80

The module supports negative moneys.

Functions

Money

Functional constructor.

    my $money = Money(0.1);
    printf '%s', $money;        # prints 0.10

Methods

new

Class or instance's method. Construct new instance.

value

Returns value (string).

    my $money = Money(0.1);
    $v = $money->value;         # 0.10
    $v = "$money";              # the same

Private (overload methods)

_assign($value)

Private method. Assigns new value to instance. Returns instance.

    my $money = Money(0.1);

    $money->_assign( 0.2 );
    $money = 0.2;               # the same

_cmp

Private method. Compares two instances as string.

    my $money1 = Money(0.1);
    my $money2 = Money(0.01);

    $money1->_cmp($money2);

    $money1 cmp $money2; # the same

_dcmp

Private method. Compares two instances as digit.

    my $money1 = Money(0.1);
    my $money2 = Money(0.01);

    $money1->_dcmp($money2);

    $money1 <=> $money2; # the same

_add

Private method. Add two instances (or instance and number).

    my $money1 = Money(1.23);
    my $money2 = Money(2.34);
    my $money3 = $money1->_add($money2);

    $money3 = $money1 + $money2; # the same

_mul

Private method. Multiplicate money to number

    my $money = Money(1.23);
    
    $money = $money->_mul(234);

    $money = $money * 234; # the same

_sub

Private method. Substract money.

    my $money = Money(1.23);

    $money = $money->_sub(1.22);

    $money  = $money - 1.22; # the same

_div

Private method. Divide money.

    my $money = Money(1.22);

    $money = $money / 2;
    $number = $money / Money(2.54);
    $number = 1.23 / $money;

_inc

Private method. Increment money.

    my $money = Money(1.22);
    $money->_inc;       # 1.23

    $money++;           # the same

_dec

Private method. Decrement money.

    my $money = Money(2.54);
    $money->_dec;       # 2.53

    $money--;           # the same

_addself

Private method. Add value to money.

    $money->_addself(23);

    $money += 23;   # the same

_mulself

Private method. Mull value to money.

    $money->_mulself(23);
    $money *= 23;       # the same

_subself

Private method. Substract value from money.

    $money->_subself(12.34);
    $money -= 12.34; # the same

_divself

Private method. Divide value by number.

    $money->_subself(12.34);
    $money -= 12.34; # the same

_int

Private method. my $money = Money(100.11); my $r = $money->_int; # 100 my $r = int Money; # the same

COPYRIGHT AND LICENSE

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available