| 1 | package Finance::Budget; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||
| 6 | 1 | ▶ | { use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Text::CSV; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Date::Manip; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use File::Slurp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | sub new | ||||||||||||||||||||||||||||
| 13 | 1 | { | |||||||||||||||||||||||||||
| 14 | 0 | ▶ | my ( $class, $param_hr ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=17 SCAR=57.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | croak sprintf 'usage: %s->new(<hash ref>)', $class | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | if ref $param_hr ne 'HASH'; | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | my %self = ( | ||||||||||||||||||||||||||||
| 20 | days => 365, | ||||||||||||||||||||||||||||
| 21 | currency_symbol => '$', | ||||||||||||||||||||||||||||
| 22 | date_format => '%m/%d/%Y', | ||||||||||||||||||||||||||||
| 23 | 0 | ▶ | markup_callback => sub { return $_[0]->{string} }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 24 | 0 | opening_balance => 0, | |||||||||||||||||||||||||||
| 25 | transaction_types => [], | ||||||||||||||||||||||||||||
| 26 | exceptions => [], | ||||||||||||||||||||||||||||
| 27 | recent_history => [], | ||||||||||||||||||||||||||||
| 28 | categorizer => {}, | ||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | for my $opt (keys %{$param_hr}) | |||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||
| 33 | croak sprintf '%s is not a recognized option among %s', | ||||||||||||||||||||||||||||
| 34 | $opt, ( join ',', keys %self ) | ||||||||||||||||||||||||||||
| 35 | 0 | ▶ | if not exists $self{$opt}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $type = ref $param_hr->{$opt}; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | if ( !$type && stat $param_hr->{$opt} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $type and stat $param_hr->{$opt}
MC/DC0%0/2
not $type and stat $param_hr->{$opt}
not $type
stat $param_hr->{$opt}
Truth table0%0/3
not(A) and B
A= not $typeB= stat $param_hr->{$opt}
| |||||||||||||||||||||||||||||
| 40 | { | ||||||||||||||||||||||||||||
| 41 | 0 | ▶ | if ( $param_hr->{$opt} =~ m{ [.] csv \z}xmsi ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | { | ||||||||||||||||||||||||||||
| 43 | 0 | my @lines = File::Slurp::slurp( $param_hr->{$opt} ); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | $param_hr->{$opt} = \@lines; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | else | ||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | 0 | $param_hr->{$opt} = do $param_hr->{$opt}; | |||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | $type = ref $param_hr->{$opt}; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | if ( $type eq 'ARRAY' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||
| 56 | 0 | chomp @{ $param_hr->{$opt} }; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if ( ref $self{$opt} ) | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||
| 62 | croak sprintf '%s should be of type %s ref', | ||||||||||||||||||||||||||||
| 63 | $opt, ( ref $self{$opt} ) | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | if $type ne ref $self{$opt}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | elsif ( $self{$opt} =~ m{\A [%] }xms ) | ||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||
| 68 | croak sprintf '%s should be a format string', $opt | ||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if $param_hr->{$opt} !~ m{ [%][a-z] }xmsi; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | elsif ( $self{$opt} =~ m{\A \d }xms ) | ||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||
| 73 | croak sprintf '%s should be a number', $opt | ||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if $param_hr->{$opt} !~ m{\A \d+ (?: [.] \d+ )? \z}xms; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 0 | $self{$opt} = $param_hr->{$opt}; | |||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | croak 'there must be 1+ transaction types' | ||||||||||||||||||||||||||||
| 81 | 0 | ▶ | if 0 == @{ $self{transaction_types} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | croak 'there must be 1+ recent history for each transaction type' | ||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if @{ $self{recent_history} } < 1 + @{ $self{transaction_types} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | croak 'there must be 1+ categorizer for each transaction type' | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | if @{ $self{transaction_types} } > keys %{ $self{categorizer} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | $self{opening_balance} *= 100; # dollars to cents | |||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | _set_base_dates( \%self ); | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | _build_transactions( \%self ); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | return bless \%self, $class; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | sub get_last_occurences { | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_last_occurences: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 0 | my %last_occurred; | |||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | TYPE: | ||||||||||||||||||||||||||||
| 104 | 0 | for my $type_hr (@{ $self->{transaction_types} }) | |||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||
| 106 | 0 | my $category = $type_hr->{category}; | |||||||||||||||||||||||||||
| 107 | 0 | my $base_date = $type_hr->{base_date}; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | next TYPE | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | if not $category; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | $last_occurred{$category} = $base_date->printf('%m/%d/%Y'); | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | return \%last_occurred; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | sub opening_balance | ||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||
| 120 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
opening_balance: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 121 | 0 | return _format_currency( $self->{opening_balance}, $self->{currency_symbol} ); | |||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | sub next | ||||||||||||||||||||||||||||
| 125 | { | ||||||||||||||||||||||||||||
| 126 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | return | ||||||||||||||||||||||||||||
| 129 | 0 | ▶ | if not @{ $self->{transactions} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 0 | return shift @{ $self->{transactions} }; | |||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | sub get_chokepoints | ||||||||||||||||||||||||||||
| 135 | { | ||||||||||||||||||||||||||||
| 136 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_chokepoints: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | croak "no chokepoints encountered" | ||||||||||||||||||||||||||||
| 139 | 0 | ▶ | if not exists $self->{chokepoints}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | return Finance::Budget::Chokepoints->new( | ||||||||||||||||||||||||||||
| 142 | { chokepoints => $self->{chokepoints}, | ||||||||||||||||||||||||||||
| 143 | markup => $self->{markup_callback}, | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 0 | ); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | sub _set_base_dates | ||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_set_base_dates: not called CC=15 SCAR=54.8
| |||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | my %base_date_for | ||||||||||||||||||||||||||||
| 153 | 0 | = map { $_->{category} => 0 } | |||||||||||||||||||||||||||
| 154 | 0 | grep { exists $_->{category} } | |||||||||||||||||||||||||||
| 155 | 0 | @{ $self->{transaction_types} }; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ( @{ $self->{recent_history} } > 1 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||
| 159 | 0 | ▶ | my $csv = Text::CSV->new() | ||||||||||||||||||||||||||
|
Condition0%0/2
'Text::CSV'->new || die(sprintf("Text::CSV: %s\n", 'Text::CSV'->error_diag))
MC/DC0%0/1
'Text::CSV'->new || die(sprintf("Text::CSV: %s\n", 'Text::CSV'->error_diag))
'Text::CSV'->new
Truth table0%0/2
A
A= 'Text::CSV'->new
| |||||||||||||||||||||||||||||
| 160 | || die sprintf "Text::CSV: %s\n", | ||||||||||||||||||||||||||||
| 161 | Text::CSV->error_diag(); | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 0 | chomp @{ $self->{recent_history} }; | |||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||
| 165 | 0 | my @cols; | |||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||
| 167 | 0 | my ($header) = shift @{ $self->{recent_history} }; | |||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 0 | ▶ | $csv->parse(lc $header) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 170 | || die sprintf "Text::CSV::parse %s\n", | ||||||||||||||||||||||||||||
| 171 | Text::CSV->error_diag(); | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | @cols = $csv->fields(); | |||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | croak "recent history CSV header must have a 'date' column" | ||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if 0 == grep { $_ eq 'date' } @cols; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | croak "recent history CSV header must have a 'description' column" | ||||||||||||||||||||||||||||
| 180 | 0 | ▶ | if 0 == grep { $_ eq 'description' } @cols; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||
| 182 | my $categorize = sub { | ||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my ($event_hr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||
| 184 | 0 | for my $category (keys %{ $self->{categorizer} }) | |||||||||||||||||||||||||||
| 185 | { | ||||||||||||||||||||||||||||
| 186 | 0 | my $categorizer = $self->{categorizer}->{$category}; | |||||||||||||||||||||||||||
| 187 | 0 | my $type = ref $categorizer; | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | croak 'categorizer should be a %s or a %s', | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type ne "ARRAY" and $type ne "CODE"
MC/DC0%0/2
$type ne "ARRAY" and $type ne "CODE"
$type ne "ARRAY"
$type ne "CODE"
Truth table0%0/3
A and B
A= $type ne "ARRAY"B= $type ne "CODE"
| |||||||||||||||||||||||||||||
| 190 | 'hash of array refs', 'hash of code refs' | ||||||||||||||||||||||||||||
| 191 | if $type ne 'ARRAY' && $type ne 'CODE'; | ||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ( $type eq 'CODE' ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | { | ||||||||||||||||||||||||||||
| 195 | 0 | ▶ | return $category | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | if $categorizer->($event_hr); | ||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | else | ||||||||||||||||||||||||||||
| 199 | { | ||||||||||||||||||||||||||||
| 200 | 0 | for my $regex (@{$categorizer}) | |||||||||||||||||||||||||||
| 201 | { | ||||||||||||||||||||||||||||
| 202 | return $category | ||||||||||||||||||||||||||||
| 203 | 0 | ▶ | if $event_hr->{description} =~ m/$regex/xmsi; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | 0 | return; | |||||||||||||||||||||||||||
| 208 | 0 | }; | |||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | EVENT: | ||||||||||||||||||||||||||||
| 211 | 0 | for my $event_csv (@{ $self->{recent_history} }) | |||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||
| 213 | 0 | ▶ | $csv->parse($event_csv) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | || die sprintf "Text::CSV::parse %s\n", | ||||||||||||||||||||||||||||
| 215 | Text::CSV->error_diag(); | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 0 | my %event; | |||||||||||||||||||||||||||
| 218 | 0 | @event{@cols} = $csv->fields(); | |||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | my $category = $categorize->( \%event ) | ||||||||||||||||||||||||||
|
Condition0%0/2
&$categorize(\%event) || (next EVENT)
MC/DC0%0/1
&$categorize(\%event) || (next EVENT)
&$categorize(\%event)
Truth table0%0/2
A
A= &$categorize(\%event)
| |||||||||||||||||||||||||||||
| 221 | || next EVENT; | ||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||
| 223 | next EVENT | ||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ref $base_date_for{$category}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | my $date = Date::Manip::Date->new(); | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | my $err = $date->parse($event{date}); | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | die sprintf "Date::Manip::Date::parse %s -- %s\n", | ||||||||||||||||||||||||||||
| 231 | 0 | ▶ | $event{date}, $err | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 232 | if $err; | ||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | $base_date_for{$category} = $date; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | CAT: | ||||||||||||||||||||||||||||
| 239 | 0 | for my $category (keys %base_date_for) | |||||||||||||||||||||||||||
| 240 | { | ||||||||||||||||||||||||||||
| 241 | croak sprintf 'failed to find base date for %s in recent history', | ||||||||||||||||||||||||||||
| 242 | $category | ||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if not ref $base_date_for{$category}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 0 | for my $type_hr (@{ $self->{transaction_types} }) | |||||||||||||||||||||||||||
| 246 | { | ||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if ( $type_hr->{category} eq $category ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 248 | { | ||||||||||||||||||||||||||||
| 249 | 0 | $type_hr->{base_date} = $base_date_for{$category}; | |||||||||||||||||||||||||||
| 250 | |||||||||||||||||||||||||||||
| 251 | 0 | next CAT; | |||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | 0 | return; | |||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | sub _build_transactions { | ||||||||||||||||||||||||||||
| 260 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_build_transactions: not called CC=17 SCAR=57.2
| |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 0 | my $width = 0; | |||||||||||||||||||||||||||
| 263 | 0 | my $balance = $self->{opening_balance}; | |||||||||||||||||||||||||||
| 264 | 0 | my ( %events_for, @transactions, @chokepoints ); | |||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 0 | my $start_date = ParseDate('today'); | |||||||||||||||||||||||||||
| 267 | 0 | my $end_date = DateCalc('today', sprintf '+%dD', $self->{days}); | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | my ($major_income) | ||||||||||||||||||||||||||||
| 270 | 0 | = map { $_->{category} } | |||||||||||||||||||||||||||
| 271 | 0 | sort { $b->{amount} <=> $a->{amount} } | |||||||||||||||||||||||||||
| 272 | 0 | @{ $self->{transaction_types} }; | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | my ($major_payment) | ||||||||||||||||||||||||||||
| 275 | 0 | = map { $_->{category} } | |||||||||||||||||||||||||||
| 276 | 0 | sort { $a->{amount} <=> $b->{amount} } | |||||||||||||||||||||||||||
| 277 | 0 | @{ $self->{transaction_types} }; | |||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 0 | my %amount_for; | |||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 0 | for my $except_hr (@{ $self->{exceptions} }) | |||||||||||||||||||||||||||
| 282 | { | ||||||||||||||||||||||||||||
| 283 | 0 | for my $field ( keys %{$except_hr} ) | |||||||||||||||||||||||||||
| 284 | { | ||||||||||||||||||||||||||||
| 285 | croak "exceptions must have: { date, category, amount }" | ||||||||||||||||||||||||||||
| 286 | 0 | ▶ | if not exists $except_hr->{$field}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | } | ||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 0 | my $date = Date::Manip::Date->new(); | |||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | 0 | my $err = $date->parse($except_hr->{date}); | |||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | die sprintf "Date::Manip::Date::parse %s -- %s\n", | ||||||||||||||||||||||||||||
| 294 | 0 | ▶ | $except_hr->{date}, $err | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | if $err; | ||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 0 | my $category = lc $except_hr->{category}; | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 0 | $amount_for{ $date->printf("$category:%s") } = $except_hr->{amount}; | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | my $find_amount_cr = sub { | ||||||||||||||||||||||||||||
| 303 | 0 | ▶ | my ( $category, $epoch, $default ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||
| 305 | 0 | my $exception_key = lc "$category:$epoch"; | |||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||
| 307 | return $amount_for{$exception_key} | ||||||||||||||||||||||||||||
| 308 | 0 | ▶ | if exists $amount_for{$exception_key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 0 | return $default; | |||||||||||||||||||||||||||
| 311 | 0 | }; | |||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 0 | my $type_help | |||||||||||||||||||||||||||
| 314 | = "transaction_types must have { category, amount, recurrence }"; | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 0 | my $major_payment_hit = 0; | |||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||
| 318 | 0 | for my $type_hr (@{ $self->{transaction_types} }) | |||||||||||||||||||||||||||
| 319 | { | ||||||||||||||||||||||||||||
| 320 | 0 | ▶ | my $category = $type_hr->{category} || die "$type_help\n"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$type_hr->{'category'} || die("$type_help\n")
MC/DC0%0/1
$type_hr->{'category'} || die("$type_help\n")
$type_hr->{'category'}
Truth table0%0/2
A
A= $type_hr->{'category'}
| |||||||||||||||||||||||||||||
| 321 | 0 | ▶ | my $amount = $type_hr->{amount} // die "$type_help\n"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$type_hr->{"amount"} // die("$type_help\n")
MC/DC0%0/1
$type_hr->{"amount"} // die("$type_help\n")
$type_hr->{"amount"}
Truth table0%0/2
A
A= $type_hr->{"amount"}
| |||||||||||||||||||||||||||||
| 322 | 0 | ▶ | my $recurrence = $type_hr->{recurrence} || die "$type_help\n"; | ||||||||||||||||||||||||||
|
Condition0%0/2
$type_hr->{'recurrence'} || die("$type_help\n")
MC/DC0%0/1
$type_hr->{'recurrence'} || die("$type_help\n")
$type_hr->{'recurrence'}
Truth table0%0/2
A
A= $type_hr->{'recurrence'}
| |||||||||||||||||||||||||||||
| 323 | 0 | my $base_date = $type_hr->{base_date}; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 0 | ▶ | $width = $width < length $category ? length $category : $width; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 0 | my $recur = Date::Manip::Recur->new(); | |||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||
| 329 | 0 | $recur->parse( $recurrence, $base_date, $start_date, $end_date ); | |||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 0 | my @dates = $recur->dates(); | |||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 0 | for my $date (@dates) | |||||||||||||||||||||||||||
| 334 | { | ||||||||||||||||||||||||||||
| 335 | 0 | my $epoch = $date->printf('%s'); | |||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||
| 337 | $amount = $find_amount_cr->( | ||||||||||||||||||||||||||||
| 338 | $type_hr->{category}, | ||||||||||||||||||||||||||||
| 339 | $epoch, | ||||||||||||||||||||||||||||
| 340 | $type_hr->{amount}, | ||||||||||||||||||||||||||||
| 341 | 0 | ); | |||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||
| 343 | 0 | ▶ | $events_for{$epoch} //= []; | ||||||||||||||||||||||||||
|
Condition0%0/2
$events_for{$epoch} //= []
MC/DC0%0/1
$events_for{$epoch} //= []
$events_for{$epoch}
Truth table0%0/2
A
A= $events_for{$epoch}
| |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||
| 345 | 0 | push @{ $events_for{$epoch} }, | |||||||||||||||||||||||||||
| 346 | { category => $type_hr->{category}, | ||||||||||||||||||||||||||||
| 347 | 0 | cents => ( 100 * $amount ), | |||||||||||||||||||||||||||
| 348 | date => $date, | ||||||||||||||||||||||||||||
| 349 | }; | ||||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 0 | for my $epoch (sort { $a <=> $b } keys %events_for) | |||||||||||||||||||||||||||
| 354 | { | ||||||||||||||||||||||||||||
| 355 | my @events | ||||||||||||||||||||||||||||
| 356 | 0 | = sort { $b->{cents} <=> $a->{cents} } @{ $events_for{$epoch} }; | |||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||
| 358 | 0 | for my $event_hr (@events) | |||||||||||||||||||||||||||
| 359 | { | ||||||||||||||||||||||||||||
| 360 | 0 | ▶ | if ( $event_hr->{category} eq $major_income ) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 361 | { | ||||||||||||||||||||||||||||
| 362 | 0 | ▶ | if ( $major_payment_hit ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 363 | { | ||||||||||||||||||||||||||||
| 364 | 0 | my $past_hr = $transactions[-1]->{event}; | |||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||
| 366 | push @chokepoints, | ||||||||||||||||||||||||||||
| 367 | { date => $past_hr->{date}, | ||||||||||||||||||||||||||||
| 368 | date_str => $past_hr->{date_str}, | ||||||||||||||||||||||||||||
| 369 | cents => $balance, | ||||||||||||||||||||||||||||
| 370 | balance => $balance, | ||||||||||||||||||||||||||||
| 371 | balance_str => _format_currency( | ||||||||||||||||||||||||||||
| 372 | $balance, | ||||||||||||||||||||||||||||
| 373 | $self->{currency_symbol} | ||||||||||||||||||||||||||||
| 374 | 0 | ), | |||||||||||||||||||||||||||
| 375 | }; | ||||||||||||||||||||||||||||
| 376 | } | ||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||
| 378 | 0 | $major_payment_hit = 0; | |||||||||||||||||||||||||||
| 379 | } | ||||||||||||||||||||||||||||
| 380 | elsif ( $event_hr->{category} eq $major_payment ) | ||||||||||||||||||||||||||||
| 381 | { | ||||||||||||||||||||||||||||
| 382 | 0 | $major_payment_hit = 1; | |||||||||||||||||||||||||||
| 383 | } | ||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||
| 385 | 0 | $balance += $event_hr->{cents}; | |||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||
| 387 | push @transactions, | ||||||||||||||||||||||||||||
| 388 | Finance::Budget::Transaction->new( | ||||||||||||||||||||||||||||
| 389 | { event => $event_hr, | ||||||||||||||||||||||||||||
| 390 | balance => $balance, | ||||||||||||||||||||||||||||
| 391 | width => $width, | ||||||||||||||||||||||||||||
| 392 | date_format => $self->{date_format}, | ||||||||||||||||||||||||||||
| 393 | markup => $self->{markup_callback}, | ||||||||||||||||||||||||||||
| 394 | currency_symbol => $self->{currency_symbol}, | ||||||||||||||||||||||||||||
| 395 | } | ||||||||||||||||||||||||||||
| 396 | 0 | ); | |||||||||||||||||||||||||||
| 397 | } | ||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||
| 400 | 0 | $self->{chokepoints} = \@chokepoints; | |||||||||||||||||||||||||||
| 401 | 0 | $self->{transactions} = \@transactions; | |||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||
| 403 | 0 | return; | |||||||||||||||||||||||||||
| 404 | } | ||||||||||||||||||||||||||||
| 405 | |||||||||||||||||||||||||||||
| 406 | sub _format_currency { | ||||||||||||||||||||||||||||
| 407 | 0 | ▶ | my ($cents, $currency) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_format_currency: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | 0 | ▶ | my $sign = $cents < 0 ? '-' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | 0 | $cents = abs $cents; | |||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | 0 | my ( $dollars, $pennies ); | |||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 0 | ▶ | if ( $cents < 99 ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | { | ||||||||||||||||||||||||||||
| 417 | 0 | $dollars = substr 0, 1, sprintf '0.%02d', $cents; | |||||||||||||||||||||||||||
| 418 | 0 | ▶ | $dollars ||= '0.00'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$dollars ||= "0.00"
MC/DC0%0/1
$dollars ||= "0.00"
$dollars
Truth table0%0/2
A
A= $dollars
| |||||||||||||||||||||||||||||
| 419 | } | ||||||||||||||||||||||||||||
| 420 | else | ||||||||||||||||||||||||||||
| 421 | { | ||||||||||||||||||||||||||||
| 422 | 0 | $dollars = sprintf '%.2f', ( $cents / 100 ); | |||||||||||||||||||||||||||
| 423 | } | ||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 0 | return sprintf '% 10s', "${sign}${currency}${dollars}"; | |||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||
| 428 | package Finance::Budget::Transaction; | ||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||
| 430 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 431 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 432 | use overload ( | ||||||||||||||||||||||||||||
| 433 | q{""} => \&_stringify, | ||||||||||||||||||||||||||||
| 434 | q{<} => \&_lt, | ||||||||||||||||||||||||||||
| 435 | q{==} => \&_eq, | ||||||||||||||||||||||||||||
| 436 | 0 | ▶ | q{!=} => sub { !_eq( @_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 437 | 0 | ▶ | q{>} => sub { !_eq( @_ ) && !_lt( @_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
_eq(@_) || _lt(@_)
MC/DC0%0/2
_eq(@_) || _lt(@_)
_eq(@_)
_lt(@_)
Truth table0%0/3
A || B
A= _eq(@_)B= _lt(@_)
| |||||||||||||||||||||||||||||
| 438 | 1 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||
| 440 | sub new { | ||||||||||||||||||||||||||||
| 441 | 0 | ▶ | my ($class, $conf_hr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||
| 443 | 0 | $conf_hr->{width} += 1; | |||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||
| 445 | $conf_hr->{event}->{date_str} | ||||||||||||||||||||||||||||
| 446 | 0 | = $conf_hr->{event}->{date}->printf($conf_hr->{date_format}); | |||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | $conf_hr->{event}->{title} | ||||||||||||||||||||||||||||
| 449 | 0 | = sprintf "% $conf_hr->{width}s", $conf_hr->{event}->{category}; | |||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | $conf_hr->{event}->{amount} = Finance::Budget::_format_currency( | ||||||||||||||||||||||||||||
| 452 | $conf_hr->{event}->{cents}, | ||||||||||||||||||||||||||||
| 453 | $conf_hr->{currency_symbol} | ||||||||||||||||||||||||||||
| 454 | 0 | ); | |||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | 0 | $conf_hr->{event}->{balance} = $conf_hr->{balance}; | |||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||
| 458 | $conf_hr->{event}->{balance_str} = Finance::Budget::_format_currency( | ||||||||||||||||||||||||||||
| 459 | $conf_hr->{balance}, | ||||||||||||||||||||||||||||
| 460 | $conf_hr->{currency_symbol} | ||||||||||||||||||||||||||||
| 461 | 0 | ); | |||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||
| 463 | $conf_hr->{event}->{string} = join ' ', | ||||||||||||||||||||||||||||
| 464 | 0 | @{ $conf_hr->{event} }{qw( date_str title amount balance_str )}; | |||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 0 | return bless $conf_hr, $class; | |||||||||||||||||||||||||||
| 467 | } | ||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||
| 469 | sub get_date { | ||||||||||||||||||||||||||||
| 470 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_date: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 471 | 0 | return $self->{event}->{date_str}; | |||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||
| 474 | sub get_category { | ||||||||||||||||||||||||||||
| 475 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_category: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 476 | 0 | return $self->{event}->{category}; | |||||||||||||||||||||||||||
| 477 | } | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | sub get_amount { | ||||||||||||||||||||||||||||
| 480 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_amount: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 481 | 0 | return $self->{event}->{amount}; | |||||||||||||||||||||||||||
| 482 | } | ||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||
| 484 | sub get_balance { | ||||||||||||||||||||||||||||
| 485 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
get_balance: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 486 | 0 | return $self->{balance_str}; | |||||||||||||||||||||||||||
| 487 | } | ||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||
| 489 | sub _stringify { | ||||||||||||||||||||||||||||
| 490 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_stringify: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||
| 492 | return $self->{markup}->( $self->{event} ) | ||||||||||||||||||||||||||||
| 493 | 0 | ▶ | if $self->{markup}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||
| 495 | 0 | return $self->{event}->{string}; | |||||||||||||||||||||||||||
| 496 | } | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | sub _lt { | ||||||||||||||||||||||||||||
| 499 | 0 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_lt: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 500 | 0 | return $self->{event}->{cents} < $arg; | |||||||||||||||||||||||||||
| 501 | } | ||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||
| 503 | sub _eq { | ||||||||||||||||||||||||||||
| 504 | 0 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_eq: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 505 | 0 | return $self->{event}->{cents} == $arg; | |||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||
| 509 | package Finance::Budget::Chokepoints; | ||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 512 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 513 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||
| 515 | sub new | ||||||||||||||||||||||||||||
| 516 | { | ||||||||||||||||||||||||||||
| 517 | 0 | ▶ | my ($class, $param_hr) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||
| 519 | die "$class requires 'chokepoints' parameter" | ||||||||||||||||||||||||||||
| 520 | 0 | ▶ | if not exists $param_hr->{chokepoints}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 521 | |||||||||||||||||||||||||||||
| 522 | 0 | return bless $param_hr, $class; | |||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | sub eye | ||||||||||||||||||||||||||||
| 526 | { | ||||||||||||||||||||||||||||
| 527 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
eye: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||
| 529 | croak 'no chokepoints encountered' | ||||||||||||||||||||||||||||
| 530 | 0 | ▶ | if not @{ $self->{chokepoints} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | my ($eye_hr) | ||||||||||||||||||||||||||||
| 533 | 0 | = sort { $a->{cents} <=> $b->{cents} } @{ $self->{chokepoints} }; | |||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | return Finance::Budget::Chokepoint->new( | ||||||||||||||||||||||||||||
| 536 | { point => $eye_hr, | ||||||||||||||||||||||||||||
| 537 | markup => $self->{markup}, | ||||||||||||||||||||||||||||
| 538 | } | ||||||||||||||||||||||||||||
| 539 | 0 | ); | |||||||||||||||||||||||||||
| 540 | } | ||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||
| 542 | sub next | ||||||||||||||||||||||||||||
| 543 | { | ||||||||||||||||||||||||||||
| 544 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
next: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | return | ||||||||||||||||||||||||||||
| 547 | 0 | ▶ | if not @{ $self->{chokepoints} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||
| 549 | 0 | my $point_hr = shift @{ $self->{chokepoints} }; | |||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | return Finance::Budget::Chokepoint->new( | ||||||||||||||||||||||||||||
| 552 | { point => $point_hr, | ||||||||||||||||||||||||||||
| 553 | markup => $self->{markup}, | ||||||||||||||||||||||||||||
| 554 | } | ||||||||||||||||||||||||||||
| 555 | 0 | ); | |||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | package Finance::Budget::Chokepoint; | ||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||
| 560 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 561 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 562 | use overload ( | ||||||||||||||||||||||||||||
| 563 | q{""} => \&_stringify, | ||||||||||||||||||||||||||||
| 564 | q{<} => \&_lt, | ||||||||||||||||||||||||||||
| 565 | q{==} => \&_eq, | ||||||||||||||||||||||||||||
| 566 | 0 | ▶ | q{!=} => sub { !_eq( @_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 567 | 0 | ▶ | q{>} => sub { !_eq( @_ ) && !_lt( @_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
_eq(@_) || _lt(@_)
MC/DC0%0/2
_eq(@_) || _lt(@_)
_eq(@_)
_lt(@_)
Truth table0%0/3
A || B
A= _eq(@_)B= _lt(@_)
| |||||||||||||||||||||||||||||
| 568 | 1 | ▶ | ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | sub new | ||||||||||||||||||||||||||||
| 571 | { | ||||||||||||||||||||||||||||
| 572 | 0 | ▶ | my ( $class, $param_hr ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 573 | $param_hr->{point}->{string} | ||||||||||||||||||||||||||||
| 574 | 0 | = sprintf '%s %s', @{ $param_hr->{point} }{qw( date_str balance_str)}; | |||||||||||||||||||||||||||
| 575 | 0 | return bless $param_hr, $class; | |||||||||||||||||||||||||||
| 576 | } | ||||||||||||||||||||||||||||
| 577 | |||||||||||||||||||||||||||||
| 578 | sub _stringify | ||||||||||||||||||||||||||||
| 579 | { | ||||||||||||||||||||||||||||
| 580 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_stringify: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 581 | 0 | return $self->{markup}->( $self->{point} ); | |||||||||||||||||||||||||||
| 582 | } | ||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||
| 584 | sub _lt { | ||||||||||||||||||||||||||||
| 585 | 0 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_lt: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 586 | 0 | return $self->{point}->{cents} < $arg; | |||||||||||||||||||||||||||
| 587 | } | ||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | sub _eq { | ||||||||||||||||||||||||||||
| 590 | 0 | ▶ | my ($self, $arg) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_eq: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 591 | 0 | return $self->{point}->{cents} == $arg; | |||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||
| 594 | |||||||||||||||||||||||||||||
| 595 | 1 | 1; | |||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||
| 597 | __END__ | ||||||||||||||||||||||||||||