line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Finance::Currency::ParValueSeparate; |
2
|
1
|
|
|
1
|
|
771
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
99
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
73
|
|
4
|
|
|
|
|
|
|
our $VERSION = sprintf "%d.%02d", q$Revision: 1.3 $ =~ /: (\d+)\.(\d+)/; |
5
|
1
|
|
|
1
|
|
1057
|
use Data::Dumper; |
|
1
|
|
|
|
|
12431
|
|
|
1
|
|
|
|
|
1749
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub new { |
8
|
5
|
|
|
5
|
1
|
908
|
my $class = shift; |
9
|
5
|
|
|
|
|
23
|
my %opt = @_; |
10
|
5
|
|
|
|
|
7
|
my $concrete = $class; |
11
|
5
|
|
|
|
|
8
|
my $amount = []; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
# called base class |
14
|
5
|
100
|
|
|
|
17
|
if ( $class eq 'Finance::Currency::ParValueSeparate' ){ |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
# which subclass we wanner using? |
17
|
3
|
100
|
|
|
|
7
|
if ( defined $opt{'currency'} ){ |
18
|
1
|
|
|
|
|
4
|
$concrete = "Finance::Currency::ParValueSeparate::".$opt{'currency'}; |
19
|
|
|
|
|
|
|
}else{ |
20
|
2
|
|
|
|
|
4
|
$concrete = "Finance::Currency::ParValueSeparate::" . shift @_; |
21
|
2
|
100
|
|
|
|
9
|
$amount = ( ref $_[0] eq 'ARRAY' ) ? $_[0] : [ @_ ]; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# try to require the subclass |
25
|
3
|
|
|
|
|
282
|
eval "require $concrete;"; |
26
|
3
|
50
|
|
|
|
15
|
die "subclass: $concrete could not required!" if $@; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# called subclass |
29
|
|
|
|
|
|
|
}else{ |
30
|
2
|
100
|
|
|
|
8
|
$amount = ( ref $_[0] eq 'ARRAY' ) ? $_[0] : [ @_ ]; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
5
|
|
|
|
|
16
|
my $self = bless {}, $concrete; |
34
|
5
|
|
|
|
|
22
|
$self->amount( $amount ); |
35
|
5
|
|
|
|
|
18
|
$self->with_dollar( $self->dollar ); |
36
|
5
|
|
|
|
|
18
|
$self->with_cent( $self->cent ); |
37
|
|
|
|
|
|
|
|
38
|
5
|
|
|
|
|
19
|
return $self; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _amount_format { |
42
|
21
|
|
|
21
|
|
23
|
my $self = shift; |
43
|
21
|
|
|
|
|
23
|
my $amount = shift; |
44
|
21
|
|
|
|
|
150
|
return sprintf( '%.2f', $amount ); |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub amount { |
48
|
15
|
|
|
15
|
1
|
304
|
my $self = shift; |
49
|
15
|
100
|
|
|
|
42
|
my $amount_ref = ( ref $_[0] eq 'ARRAY' ) ? $_[0] : [ @_ ]; |
50
|
15
|
100
|
|
|
|
42
|
$self->{_AMOUNT} = [ map { $self->_amount_format( $_ ) } @$amount_ref ] |
|
21
|
|
|
|
|
47
|
|
51
|
|
|
|
|
|
|
if scalar @$amount_ref; |
52
|
15
|
100
|
|
|
|
49
|
return wantarray ? @{$self->{_AMOUNT}} : $self->{_AMOUNT}; |
|
5
|
|
|
|
|
20
|
|
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub with_dollar { |
56
|
23
|
|
|
23
|
1
|
331
|
my $self = shift; |
57
|
23
|
100
|
|
|
|
66
|
my $with_dollar = ( ref $_[0] eq 'ARRAY' ) ? $_[0] : [ @_ ]; |
58
|
23
|
100
|
|
|
|
49
|
if ( @_ ){ |
59
|
7
|
|
|
|
|
8
|
my $valid_dollar; |
60
|
7
|
|
|
|
|
18
|
map { $valid_dollar->{$_}++; } $self->dollar; |
|
49
|
|
|
|
|
85
|
|
61
|
7
|
|
|
|
|
16
|
$self->{_with_dollar} = [ grep { $valid_dollar->{$_} } @$with_dollar ]; |
|
40
|
|
|
|
|
68
|
|
62
|
|
|
|
|
|
|
|
63
|
7
|
|
|
|
|
11
|
map { delete $valid_dollar->{$_} } @$with_dollar; |
|
40
|
|
|
|
|
59
|
|
64
|
7
|
|
|
|
|
30
|
$self->{_without_dollar} = [ keys %$valid_dollar ]; |
65
|
|
|
|
|
|
|
} |
66
|
23
|
100
|
|
|
|
48
|
return wantarray ? @{$self->{_with_dollar}} : $self->{_with_dollar}; |
|
16
|
|
|
|
|
84
|
|
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
sub without_dollar { |
69
|
4
|
|
|
4
|
1
|
699
|
my $self = shift; |
70
|
4
|
100
|
|
|
|
18
|
my $without_dollar = ( ref $_[0] eq 'ARRAY' ) ? $_[0] : [ @_ ]; |
71
|
4
|
100
|
|
|
|
12
|
if ( @_ ){ |
72
|
2
|
|
|
|
|
4
|
my $valid_dollar; |
73
|
2
|
|
|
|
|
8
|
map { $valid_dollar->{$_}++; } $self->dollar; |
|
14
|
|
|
|
|
30
|
|
74
|
2
|
|
|
|
|
6
|
$self->{_without_dollar} = [ grep { $valid_dollar->{$_} } @$without_dollar ]; |
|
5
|
|
|
|
|
16
|
|
75
|
|
|
|
|
|
|
|
76
|
2
|
|
|
|
|
5
|
map { delete $valid_dollar->{$_} } @$without_dollar; |
|
5
|
|
|
|
|
11
|
|
77
|
2
|
|
|
|
|
13
|
$self->{_with_dollar} = [ keys %$valid_dollar ]; |
78
|
|
|
|
|
|
|
} |
79
|
4
|
100
|
|
|
|
16
|
return wantarray ? @{$self->{_without_dollar}} : $self->{_without_dollar}; |
|
2
|
|
|
|
|
14
|
|
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub with_cent { |
83
|
19
|
|
|
19
|
1
|
20
|
my $self = shift; |
84
|
19
|
50
|
|
|
|
51
|
my $with_cent = ( ref $_[0] eq 'ARRAY' ) ? $_[0] : [ @_ ]; |
85
|
19
|
100
|
|
|
|
40
|
if ( @_ ){ |
86
|
5
|
|
|
|
|
5
|
my $valid_cent; |
87
|
5
|
|
|
|
|
13
|
map { $valid_cent->{$_}++; } $self->cent; |
|
30
|
|
|
|
|
50
|
|
88
|
5
|
|
|
|
|
10
|
$self->{_with_cent} = [ grep { $valid_cent->{$_} } @$with_cent ]; |
|
30
|
|
|
|
|
49
|
|
89
|
|
|
|
|
|
|
|
90
|
5
|
|
|
|
|
21
|
map { delete $valid_cent->{$_} } @$with_cent; |
|
30
|
|
|
|
|
43
|
|
91
|
5
|
|
|
|
|
15
|
$self->{_without_cent} = [ keys %$valid_cent ]; |
92
|
|
|
|
|
|
|
} |
93
|
19
|
100
|
|
|
|
40
|
return wantarray ? @{$self->{_with_cent}} : $self->{_with_cent}; |
|
14
|
|
|
|
|
120
|
|
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
sub without_cent { |
96
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
97
|
0
|
0
|
|
|
|
0
|
my $without_cent = ( ref $_[0] eq 'ARRAY' ) ? $_[0] : [ @_ ]; |
98
|
0
|
0
|
|
|
|
0
|
if ( @_ ){ |
99
|
0
|
|
|
|
|
0
|
my $valid_cent; |
100
|
0
|
|
|
|
|
0
|
map { $valid_cent->{$_}++; } $self->cent; |
|
0
|
|
|
|
|
0
|
|
101
|
0
|
|
|
|
|
0
|
$self->{_without_cent} = [ grep { $valid_cent->{$_} } @$without_cent ]; |
|
0
|
|
|
|
|
0
|
|
102
|
|
|
|
|
|
|
|
103
|
0
|
|
|
|
|
0
|
map { delete $valid_cent->{$_} } @$without_cent; |
|
0
|
|
|
|
|
0
|
|
104
|
0
|
|
|
|
|
0
|
$self->{_with_cent} = [ keys %$valid_cent ]; |
105
|
|
|
|
|
|
|
} |
106
|
0
|
0
|
|
|
|
0
|
return wantarray ? @{$self->{_without_cent}} : $self->{_without_cent}; |
|
0
|
|
|
|
|
0
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub only_dollar { |
110
|
17
|
|
|
17
|
1
|
146
|
my $self = shift; |
111
|
17
|
|
|
|
|
20
|
my $flag = shift; |
112
|
17
|
100
|
|
|
|
35
|
if ( defined $flag ){ |
113
|
2
|
100
|
|
|
|
7
|
$self->{_only_dollar} = ( $flag ) ? 1 : 0; |
114
|
|
|
|
|
|
|
} |
115
|
17
|
|
|
|
|
116
|
return $self->{_only_dollar}; |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
sub parse { |
119
|
4
|
|
|
4
|
1
|
194
|
my $self = shift; |
120
|
4
|
|
|
|
|
13
|
$self->amount(@_); |
121
|
4
|
|
|
|
|
12
|
delete $self->{_DOLLAR}; |
122
|
4
|
|
|
|
|
8
|
delete $self->{_CENT}; |
123
|
|
|
|
|
|
|
|
124
|
14
|
|
|
|
|
31
|
map { |
125
|
4
|
|
|
|
|
11
|
my $dollar = int $_; |
126
|
14
|
|
|
|
|
90
|
my ( $cent ) = ( $_ =~ /\.(.*)$/ ); |
127
|
|
|
|
|
|
|
|
128
|
14
|
|
|
|
|
46
|
foreach my $parvalue ( sort { $b<=>$a } $self->with_dollar ){ |
|
126
|
|
|
|
|
147
|
|
129
|
70
|
|
|
|
|
96
|
my $number = ( $dollar - $dollar % $parvalue ) / $parvalue; |
130
|
70
|
|
|
|
|
78
|
$dollar -= $number * $parvalue; |
131
|
70
|
|
|
|
|
121
|
$self->{_DOLLAR}{$parvalue} += $number; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
14
|
50
|
|
|
|
40
|
next if $self->only_dollar; |
135
|
|
|
|
|
|
|
|
136
|
14
|
|
|
|
|
26
|
foreach my $parvalue ( sort { $b<=>$a } $self->with_cent ){ |
|
126
|
|
|
|
|
144
|
|
137
|
84
|
|
|
|
|
111
|
my $number = ( $cent - $cent % $parvalue ) / $parvalue; |
138
|
84
|
|
|
|
|
81
|
$cent -= $number * $parvalue; |
139
|
84
|
|
|
|
|
168
|
$self->{_CENT}{$parvalue} += $number; |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
} $self->amount; |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub dollar_parvalues { |
146
|
4
|
|
|
4
|
1
|
23
|
my $self = shift; |
147
|
4
|
|
|
|
|
5
|
return sort { $b <=> $a } keys %{$self->{_DOLLAR}}; |
|
30
|
|
|
|
|
45
|
|
|
4
|
|
|
|
|
19
|
|
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
sub number_of_dollar { |
150
|
20
|
|
|
20
|
1
|
93
|
my $self = shift; |
151
|
20
|
|
|
|
|
24
|
my $parvalue = shift; |
152
|
20
|
|
|
|
|
547
|
return $self->{_DOLLAR}{$parvalue}; |
153
|
|
|
|
|
|
|
} |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub cent_parvalues { |
156
|
4
|
|
|
4
|
1
|
26
|
my $self = shift; |
157
|
4
|
|
|
|
|
5
|
return sort { $b <=> $a } keys %{$self->{_CENT}}; |
|
36
|
|
|
|
|
55
|
|
|
4
|
|
|
|
|
21
|
|
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
sub number_of_cent { |
160
|
24
|
|
|
24
|
1
|
122
|
my $self = shift; |
161
|
24
|
|
|
|
|
29
|
my $parvalue = shift; |
162
|
24
|
|
|
|
|
717
|
return $self->{_CENT}{$parvalue}; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# subclass override them |
167
|
|
|
|
|
|
|
sub currency_name { |
168
|
0
|
|
|
0
|
0
|
|
croak 'base class has no currency_name, use subclass'; |
169
|
|
|
|
|
|
|
} |
170
|
|
|
|
|
|
|
sub dollar { |
171
|
0
|
|
|
0
|
0
|
|
croak 'base class has no dollar denomination informations, use subclass'; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
sub cent { |
174
|
0
|
|
|
0
|
0
|
|
croak 'base class has no cent denomination informations, use subclass'; |
175
|
|
|
|
|
|
|
} |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |
178
|
|
|
|
|
|
|
__END__ |