| 1 | package Money::PaymentPreparer; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | Money::PaymentPreparer - change sum to bills and coins. | ||||||||||
| 9 | |||||||||||
| 10 | =head1 VERSION | ||||||||||
| 11 | |||||||||||
| 12 | Version 0.03 | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | 1 | our $VERSION = "0.03"; | |||||||||
| 17 | |||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||
| 19 | |||||||||||
| 20 | use Money::PaymentPreparer; | ||||||||||
| 21 | |||||||||||
| 22 | my @my_bills = qw (200 100 50 20 10 5 2 1); | ||||||||||
| 23 | |||||||||||
| 24 | my $object = PaymentPreparer->new(); | ||||||||||
| 25 | $object->set_bill(@my_bills); | ||||||||||
| 26 | $object->add(153); | ||||||||||
| 27 | $object->add(68); | ||||||||||
| 28 | %result = $object->get(); | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | sub new { | ||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 33 | 0 | my $class = shift; | |||||||||
| 34 | 0 | my $self = {}; | |||||||||
| 35 | 0 | $self->{units} = undef; | |||||||||
| 36 | 0 | $self->{bills} = undef; | |||||||||
| 37 | 0 | bless $self, $class; | |||||||||
| 38 | } | ||||||||||
| 39 | |||||||||||
| 40 | 0 | ▶ | sub set_bill { | ||||||||
|
Subroutine
set_bill: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 41 | 0 | my $self = shift; | |||||||||
| 42 | 0 | @{ $self->{units} } = @_; | |||||||||
| 43 | 0 | %{ $self->{bills} } = map { $_ => 0 } @_; | |||||||||
| 44 | } | ||||||||||
| 45 | |||||||||||
| 46 | 0 | ▶ | sub add { | ||||||||
|
Subroutine
add: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||
| 47 | 0 | my $self = shift; | |||||||||
| 48 | 0 | my $temp = shift; | |||||||||
| 49 | 0 | my @units = @{ $self->{units} }; | |||||||||
| 50 | 0 | my %pieces = %{ $self->{bills} }; | |||||||||
| 51 | 0 | my $unit; | |||||||||
| 52 | 0 | my $i = 0; | |||||||||
| 53 | 0 | ▶ | while ($temp) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 54 | 0 | $unit = $units[$i]; | |||||||||
| 55 | |||||||||||
| 56 | 0 | ▶ | while ( $temp >= $unit ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 57 | 0 | $temp -= $unit; | |||||||||
| 58 | 0 | $pieces{$unit} += 1; | |||||||||
| 59 | } | ||||||||||
| 60 | 0 | ▶ | last if $i == (@units); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 0 | $unit = $units[ ++$i ]; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 0 | %{ $self->{bills} } = %pieces; | |||||||||
| 65 | } | ||||||||||
| 66 | |||||||||||
| 67 | |||||||||||
| 68 | 0 | ▶ | sub get { | ||||||||
|
Subroutine
get: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 69 | 0 | my $self = shift; | |||||||||
| 70 | 0 | return %{ $self->{bills}}; | |||||||||
| 71 | |||||||||||
| 72 | } | ||||||||||
| 73 | |||||||||||
| 74 | 1 | 1; | |||||||||
| 75 | |||||||||||
| 76 | __END__ | ||||||||||