line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Money::PaymentPreparer; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23818
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
374
|
|
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
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub new { |
33
|
0
|
|
|
0
|
1
|
|
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
|
|
|
|
|
|
|
sub set_bill { |
41
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
42
|
0
|
|
|
|
|
|
@{ $self->{units} } = @_; |
|
0
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
%{ $self->{bills} } = map { $_ => 0 } @_; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub add { |
47
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
48
|
0
|
|
|
|
|
|
my $temp = shift; |
49
|
0
|
|
|
|
|
|
my @units = @{ $self->{units} }; |
|
0
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my %pieces = %{ $self->{bills} }; |
|
0
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $unit; |
52
|
0
|
|
|
|
|
|
my $i = 0; |
53
|
0
|
|
|
|
|
|
while ($temp) { |
54
|
0
|
|
|
|
|
|
$unit = $units[$i]; |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
while ( $temp >= $unit ) { |
57
|
0
|
|
|
|
|
|
$temp -= $unit; |
58
|
0
|
|
|
|
|
|
$pieces{$unit} += 1; |
59
|
|
|
|
|
|
|
} |
60
|
0
|
0
|
|
|
|
|
last if $i == (@units); |
61
|
0
|
|
|
|
|
|
$unit = $units[ ++$i ]; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
|
%{ $self->{bills} } = %pieces; |
|
0
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub get { |
69
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
return %{ $self->{bills}}; |
|
0
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
__END__ |