| 1 | # | ||||||||||||||||||||
| 2 | # Copyright (c) 2014-2019 Christian Jaeger, copying@christianjaeger.ch | ||||||||||||||||||||
| 3 | # | ||||||||||||||||||||
| 4 | # This is free software, offered under either the same terms as perl 5 | ||||||||||||||||||||
| 5 | # or the terms of the Artistic License version 2 or the terms of the | ||||||||||||||||||||
| 6 | # MIT License (Expat version). See the file COPYING.md that came | ||||||||||||||||||||
| 7 | # bundled with this file. | ||||||||||||||||||||
| 8 | # | ||||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | =head1 NAME | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | FunctionalPerl::Htmlgen::Cost | ||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | =head1 SYNOPSIS | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | =head1 DESCRIPTION | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =head1 NOTE | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | This is alpha software! Read the status section in the package README | ||||||||||||||||||||
| 22 | or on the L<website|http://functional-perl.org/>. | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | =cut | ||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | package FunctionalPerl::Htmlgen::Cost; | ||||||||||||||||||||
| 27 | 2 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 2 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 2 | ▶ | use warnings FATAL => 'uninitialized'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 2 | ▶ | use experimental "signatures"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | #use Exporter "import"; | ||||||||||||||||||||
| 34 | #@EXPORT = qw(); | ||||||||||||||||||||
| 35 | #@EXPORT_OK = qw(); | ||||||||||||||||||||
| 36 | #%EXPORT_TAGS = (all => [@EXPORT,@EXPORT_OK]); | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 2 | package FunctionalPerl::Htmlgen::Cost::_::Cost { | |||||||||||||||||||
| 39 | 2 | ▶ | use FP::Array ":all"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 2 | ▶ | use FP::Struct [qw(name is_purchaseable basecosts val)]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 0 | ▶ | sub cost ($self, $index) { | ||||||||||||||||||
|
Subroutine
cost: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 44 | 0 | ▶ | $$self{_cost} ||= do { | ||||||||||||||||||
|
Condition0%0/3
$self->{"_cost"} ||= do {
add($self->val, map({$index->{$_}->cost($index);} @{$self->basecosts;}))
}
MC/DC0%0/2
$self->{"_cost"} ||= do {
add($self->val, map({$index->{$_}->cost($index);} @{$self->basecosts;}))
}
$self->{"_cost"}
do {
add($self->val, map({$index->{$_}->cost($index);} @{$self->basecosts;}))
}
Truth table0%0/3
A ||= B
A= $self->{"_cost"}B= do {
add($self->val, map({$index->{$_}->cost($index);} @{$self->basecosts;}))
}
| |||||||||||||||||||||
| 45 | add($self->val, | ||||||||||||||||||||
| 46 | 0 | map { $$index{$_}->cost($index) } @{ $self->basecosts }); | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | 2 | _END_ | |||||||||||||||||||
| 50 | } | ||||||||||||||||||||
| 51 | |||||||||||||||||||||
| 52 | 2 | package FunctionalPerl::Htmlgen::Cost::_::Totalcost { | |||||||||||||||||||
| 53 | 2 | ▶ | use FP::Array_sort ":all"; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 2 | ▶ | use FP::Struct [qw(costs)]; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | sub range($self) { | ||||||||||||||||||
|
Subroutine
range: not called CC=6 SCAR=37.4
| |||||||||||||||||||||
| 58 | 0 | ▶ | @{ $$self{costs} } or die "no costs given"; # | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | 0 | my $index; | |||||||||||||||||||
| 60 | 0 | for (@{ $$self{costs} }) { | |||||||||||||||||||
| 61 | 0 | ▶ | if (defined(my $name = $_->name)) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 62 | 0 | $$index{$name} = $_ | |||||||||||||||||||
| 63 | } | ||||||||||||||||||||
| 64 | } | ||||||||||||||||||||
| 65 | 0 | my $purchaseable = [grep { $_->is_purchaseable } @{ $$self{costs} }]; | |||||||||||||||||||
| 66 | 0 | ▶ | @$purchaseable or die "no purchaseable costs"; # | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 67 | 0 | local our $all | |||||||||||||||||||
| 68 | = array_sort($purchaseable, on the_method("cost", $index), | ||||||||||||||||||||
| 69 | \&real_cmp); | ||||||||||||||||||||
| 70 | 0 | ▶ | ( @$all == 1 | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 71 | ? $$all[0]->cost($index) | ||||||||||||||||||||
| 72 | : $$all[0]->cost($index) . ".." . $$all[-1]->cost($index)) | ||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | 2 | _END_ | |||||||||||||||||||
| 75 | } | ||||||||||||||||||||
| 76 | |||||||||||||||||||||