| 1 | package App::BPOMUtils::NutritionFacts; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict 'subs', 'vars'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Log::ger; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY | |||||||||||||||||||||||||||
| 12 | 1 | our $DATE = '2024-11-05'; # DATE | |||||||||||||||||||||||||||
| 13 | 1 | our $DIST = 'App-BPOMUtils-NutritionFacts'; # DIST | |||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.028'; # VERSION | |||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 1 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 17 | bpom_show_nutrition_facts | ||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | our %SPEC; | |||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 1 | $SPEC{':package'} = { | |||||||||||||||||||||||||||
| 23 | v => 1.1, | ||||||||||||||||||||||||||||
| 24 | summary => 'Utilities related to BPOM nutrition facts', | ||||||||||||||||||||||||||||
| 25 | }; | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 1 | my $res; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | ▶ | my $M = "\N{MULTIPLICATION SIGN}"; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub _nearest { | ||||||||||||||||||||||||||
|
Subroutine
_nearest: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 32 | 0 | require Math::Round; | |||||||||||||||||||||||||||
| 33 | 0 | Math::Round::nearest(@_); | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | ▶ | sub _fmt_num_id { | ||||||||||||||||||||||||||
|
Subroutine
_fmt_num_id: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 37 | 0 | require Number::Format; | |||||||||||||||||||||||||||
| 38 | 0 | state $nf = Number::Format->new(THOUSANDS_SEP=>".", DECIMAL_POINT=>","); | |||||||||||||||||||||||||||
| 39 | 0 | $nf->format_number(@_); | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 1 | my @output_formats = (qw/ | |||||||||||||||||||||||||||
| 43 | raw_table | ||||||||||||||||||||||||||||
| 44 | vertical_html_table vertical_text_table | ||||||||||||||||||||||||||||
| 45 | linear_html linear_text raw_linear | ||||||||||||||||||||||||||||
| 46 | calculation_html calculation_text | ||||||||||||||||||||||||||||
| 47 | /); | ||||||||||||||||||||||||||||
| 48 | # horizontal_html_table horizontal_text_table formats not supported yet | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | sub _add_real_and_nufact_args { | ||||||||||||||||||||||||||
|
Subroutine
_add_real_and_nufact_args: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 51 | 1 | my %args = @_; | |||||||||||||||||||||||||||
| 52 | 1 | my %res; | |||||||||||||||||||||||||||
| 53 | 1 | for my $key (keys %args) { | |||||||||||||||||||||||||||
| 54 | 33 | $res{$key} = $args{$key}; | |||||||||||||||||||||||||||
| 55 | $res{"${key}_nufact"} = { | ||||||||||||||||||||||||||||
| 56 | summary => "$args{$key}{summary} (value to be used in nutrition facts table instead the lab test result)", | ||||||||||||||||||||||||||||
| 57 | schema => $args{$key}{schema}, | ||||||||||||||||||||||||||||
| 58 | 33 | }; | |||||||||||||||||||||||||||
| 59 | 33 | $res{"${key}_nufact_note"} = { | |||||||||||||||||||||||||||
| 60 | schema => "str*", | ||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | 1 | %res; | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | $SPEC{bpom_show_nutrition_facts} = { | ||||||||||||||||||||||||||||
| 67 | 1 | v => 1.1, | |||||||||||||||||||||||||||
| 68 | summary => 'Render BPOM-compliant nutrition fact table (ING - informasi nilai gizi) in various formats', | ||||||||||||||||||||||||||||
| 69 | args => { | ||||||||||||||||||||||||||||
| 70 | name => {schema=>'str*'}, | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | output_format => { | ||||||||||||||||||||||||||||
| 73 | summary => 'Pick an output format for the nutrition fact', | ||||||||||||||||||||||||||||
| 74 | schema => ['str*', {in=>\@output_formats}], | ||||||||||||||||||||||||||||
| 75 | description => <<'_', | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | `vertical_text_table` is the default. The /(vertical)?.*table/ formats presents | ||||||||||||||||||||||||||||
| 78 | the information in a table, while the /linear/ formats presents the information | ||||||||||||||||||||||||||||
| 79 | in a paragraph. | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | _ | ||||||||||||||||||||||||||||
| 82 | default => 'vertical_text_table', | ||||||||||||||||||||||||||||
| 83 | cmdline_aliases => { | ||||||||||||||||||||||||||||
| 84 | f=>{}, | ||||||||||||||||||||||||||||
| 85 | }, | ||||||||||||||||||||||||||||
| 86 | tags => ['category:output'], | ||||||||||||||||||||||||||||
| 87 | }, | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | browser => { | ||||||||||||||||||||||||||||
| 90 | summary => 'View output HTML in browser instead of returning it', | ||||||||||||||||||||||||||||
| 91 | schema => 'true*', | ||||||||||||||||||||||||||||
| 92 | tags => ['category:output'], | ||||||||||||||||||||||||||||
| 93 | }, | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | color => { | ||||||||||||||||||||||||||||
| 96 | schema => ['str*', in=>[qw/always auto never/]], | ||||||||||||||||||||||||||||
| 97 | default => 'auto', | ||||||||||||||||||||||||||||
| 98 | tags => ['category:output'], | ||||||||||||||||||||||||||||
| 99 | }, | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | _add_real_and_nufact_args( | ||||||||||||||||||||||||||||
| 102 | fat => {summary => 'Total fat, in g/100g' , schema => 'ufloat*', req=>1}, | ||||||||||||||||||||||||||||
| 103 | saturated_fat => {summary => 'Saturated fat, in g/100g' , schema => 'ufloat*', req=>1}, | ||||||||||||||||||||||||||||
| 104 | cholesterol => {summary => 'Cholesterol, in mg/100g' , schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 105 | protein => {summary => 'Protein, in g/100g' , schema => 'ufloat*', req=>1}, | ||||||||||||||||||||||||||||
| 106 | carbohydrate => {summary => 'Total carbohydrate, in g/100g' , schema => 'ufloat*', req=>1}, | ||||||||||||||||||||||||||||
| 107 | sugar => {summary => 'Total sugar, in g/100g' , schema => 'ufloat*', req=>1}, | ||||||||||||||||||||||||||||
| 108 | sodium => {summary => 'Sodium, in mg/100g' , schema => 'ufloat*', req=>1, cmdline_aliases=>{salt=>{}}}, | ||||||||||||||||||||||||||||
| 109 | va => {summary => 'Vitamin A, in mcg/100g (all-trans-)retinol', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 110 | vd => {summary => 'Vitamin D, in mcg', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 111 | ve => {summary => 'Vitamin E, in mg alpha-TE (tocopherol-equivalent)', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 112 | vk => {summary => 'Vitamin K, in mcg', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 113 | vb1 => {summary => 'Vitamin B1, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 114 | vb2 => {summary => 'Vitamin B2, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 115 | vb3 => {summary => 'Vitamin B3, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 116 | vb5 => {summary => 'Vitamin B5 (pantothenic acid), in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 117 | vb6 => {summary => 'Vitamin B6, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 118 | folate => {summary => 'Folate (vitamin B9), in mcg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 119 | vb12 => {summary => 'Vitamin B12, in mcg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 120 | biotin => {summary => 'Biotin, in mcg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 121 | choline => {summary => 'Choline, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 122 | vc => {summary => 'Vitamin C, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 123 | ca => {summary => 'Calcium, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 124 | phosphorus => {summary => 'Phosphorus, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 125 | mg => {summary => 'Magnesium, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 126 | k => {summary => 'Potassium, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 127 | mn => {summary => 'Manganese, in mcg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 128 | cu => {summary => 'Copper, in mcg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 129 | cr => {summary => 'Chromium, in mcg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 130 | fe => {summary => 'Iron, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 131 | iodium => {summary => 'Iodium, in mcg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 132 | zn => {summary => 'Zinc, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 133 | se => {summary => 'Selenium, in mcg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 134 | fluorine => {summary => 'Fluorine, in mg/100g', schema => 'ufloat*'}, | ||||||||||||||||||||||||||||
| 135 | ), | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | serving_size => {summary => 'Serving size, in g' , schema => 'ufloat*', req=>1}, | ||||||||||||||||||||||||||||
| 138 | package_size => {summary => 'Packaging size, in g' , schema => 'ufloat*', req=>1}, | ||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||
| 140 | has_claims => {summary => 'Whether food is registered as having claims', schema=>'bool*'}, | ||||||||||||||||||||||||||||
| 141 | }, | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | examples => [ | ||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||
| 145 | summary => 'An example, in linear text format (color/emphasis is shown with markup)', | ||||||||||||||||||||||||||||
| 146 | args => {fat=>0.223, saturated_fat=>0.010, protein=>0.990, carbohydrate=>13.113, sugar=>7.173, sodium=>0.223, serving_size=>175, package_size=>20, output_format=>"raw_linear", color=>"never"}, | ||||||||||||||||||||||||||||
| 147 | test => 0, | ||||||||||||||||||||||||||||
| 148 | }, | ||||||||||||||||||||||||||||
| 149 | { | ||||||||||||||||||||||||||||
| 150 | summary => 'An example, in raw_linear format (just like linear_text but with no border)', | ||||||||||||||||||||||||||||
| 151 | args => {fat=>0.223, saturated_fat=>0.010, protein=>0.990, carbohydrate=>13.113, sugar=>7.173, sodium=>0.223, serving_size=>175, package_size=>20, output_format=>"linear_text", color=>"never"}, | ||||||||||||||||||||||||||||
| 152 | test => 0, | ||||||||||||||||||||||||||||
| 153 | }, | ||||||||||||||||||||||||||||
| 154 | { | ||||||||||||||||||||||||||||
| 155 | summary => 'The same example in vertical HTML table format', | ||||||||||||||||||||||||||||
| 156 | args => {fat=>0.223, saturated_fat=>0.010, protein=>0.990, carbohydrate=>13.113, sugar=>7.173, sodium=>0.223, serving_size=>175, package_size=>20, output_format=>"vertical_html_table"}, | ||||||||||||||||||||||||||||
| 157 | test => 0, | ||||||||||||||||||||||||||||
| 158 | }, | ||||||||||||||||||||||||||||
| 159 | { | ||||||||||||||||||||||||||||
| 160 | summary => 'The same example, in vertical text format (color/emphasis is shown with markup)', | ||||||||||||||||||||||||||||
| 161 | args => {fat=>0.223, saturated_fat=>0.010, protein=>0.990, carbohydrate=>13.113, sugar=>7.173, sodium=>0.223, serving_size=>175, package_size=>20, output_format=>"vertical_text_table", color=>"never"}, | ||||||||||||||||||||||||||||
| 162 | test => 0, | ||||||||||||||||||||||||||||
| 163 | }, | ||||||||||||||||||||||||||||
| 164 | { | ||||||||||||||||||||||||||||
| 165 | summary => 'The same example, in calculation text format', | ||||||||||||||||||||||||||||
| 166 | args => {fat=>0.223, saturated_fat=>0.010, protein=>0.990, carbohydrate=>13.113, sugar=>7.173, sodium=>0.223, serving_size=>175, package_size=>20, output_format=>"calculation_text", color=>"never"}, | ||||||||||||||||||||||||||||
| 167 | test => 0, | ||||||||||||||||||||||||||||
| 168 | }, | ||||||||||||||||||||||||||||
| 169 | ], | ||||||||||||||||||||||||||||
| 170 | }; | ||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub bpom_show_nutrition_facts { | ||||||||||||||||||||||||||
|
Subroutine
bpom_show_nutrition_facts: not called CC=179 SCAR=103.8
Pod
documented
| |||||||||||||||||||||||||||||
| 172 | 0 | my %args = @_; | |||||||||||||||||||||||||||
| 173 | 0 | ▶ | my $output_format = $args{output_format} // 'raw_table'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"output_format"} // "raw_table"
MC/DC0%0/1
$args{"output_format"} // "raw_table"
$args{"output_format"}
Truth table0%0/2
A
A= $args{"output_format"}
| |||||||||||||||||||||||||||||
| 174 | 0 | ▶ | return [400, "Unknown output format '$output_format'"] unless grep { $output_format eq $_ } @output_formats; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 0 | ▶ | my $color = $args{color} // 'auto'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"color"} // "auto"
MC/DC0%0/1
$args{"color"} // "auto"
$args{"color"}
Truth table0%0/2
A
A= $args{"color"}
| |||||||||||||||||||||||||||||
| 177 | 0 | my $is_interactive = -t STDOUT; ## no critic: InputOutput::ProhibitInteractiveTest | |||||||||||||||||||||||||||
| 178 | 0 | ▶ | my $use_color = $color eq 'never' ? 0 : $color eq 'always' ? 1 : $is_interactive; | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | my @rows; | |||||||||||||||||||||||||||
| 181 | 0 | my $funcraw = {}; | |||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 0 | ▶ | my $attr = $output_format =~ /html/ ? "raw_html" : "text"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 0 | ▶ | my $code_fmttext = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=6 SCAR=37.4
| |||||||||||||||||||||||||||||
| 185 | 0 | my $text = shift; | |||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ($output_format =~ /html/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | require Org::To::HTML; | |||||||||||||||||||||||||||
| 188 | 0 | my $res = Org::To::HTML::org_to_html(source_str => $text, naked=>1); | |||||||||||||||||||||||||||
| 189 | 0 | ▶ | die "Can't convert Org to HTML: $res->[0] - $res->[1]" if $res->[0] != 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 0 | $res->[2]; | |||||||||||||||||||||||||||
| 191 | } else { | ||||||||||||||||||||||||||||
| 192 | 0 | my $res; | |||||||||||||||||||||||||||
| 193 | 0 | ▶ | if ($use_color) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 0 | require Org::To::ANSIText; | |||||||||||||||||||||||||||
| 195 | 0 | $res = Org::To::ANSIText::org_to_ansi_text(source_str => $text); | |||||||||||||||||||||||||||
| 196 | 0 | ▶ | die "Can't convert Org to ANSI text: $res->[0] - $res->[1]" if $res->[0] != 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | } else { | ||||||||||||||||||||||||||||
| 198 | 0 | require Org::To::Text; | |||||||||||||||||||||||||||
| 199 | 0 | $res = Org::To::Text::org_to_text(source_str => $text); | |||||||||||||||||||||||||||
| 200 | 0 | ▶ | die "Can't convert Org to text: $res->[0] - $res->[1]" if $res->[0] != 200; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | 0 | $res->[2]; | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | 0 | }; | |||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 0 | ▶ | my $per_package_ing = $args{serving_size} > $args{package_size} ? 1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 207 | 0 | ▶ | my $size_key = $per_package_ing ? 'package_size' : 'serving_size'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 208 | 0 | ▶ | my $BR = $output_format =~ /html/ ? "<br />" : "\n"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | $funcraw->{per_package_ing} = $per_package_ing; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | ▶ | if ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 213 | 0 | push @rows, [{colspan=>5, align=>'middle', $attr => $code_fmttext->("*INFORMASI NILAI GIZI*")}]; | |||||||||||||||||||||||||||
| 214 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 215 | 0 | ▶ | if ($output_format =~ /html/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 0 | push @rows, "<big><b>INFORMASI NILAI GIZI</b></big> "; | |||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||
| 218 | 0 | push @rows, $code_fmttext->("*INFORMASI NILAI GIZI* "); | |||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 221 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr => $code_fmttext->("*PERHITUNGAN INFORMASI NILAI GIZI*")}]; | |||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if ($per_package_ing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 0 | ▶ | if ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 226 | 0 | push @rows, [{colspan=>5, text=>''}]; | |||||||||||||||||||||||||||
| 227 | 0 | push @rows, [{colspan=>5, align=>'left', $attr => $code_fmttext->("*JUMLAH PER KEMASAN ($args{package_size} g)*")}]; | |||||||||||||||||||||||||||
| 228 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 229 | 0 | push @rows, $code_fmttext->(" *JUMLAH PER KEMASAN ($args{package_size} g)* : "); | |||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||
| 231 | } else { | ||||||||||||||||||||||||||||
| 232 | 0 | my $srvs_per_pkg = _nearest(0.5, $args{package_size} / $args{serving_size}); | |||||||||||||||||||||||||||
| 233 | 0 | $funcraw->{srvs_per_pkg} = $srvs_per_pkg; | |||||||||||||||||||||||||||
| 234 | 0 | ▶ | if ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 235 | 0 | push @rows, [{colspan=>5, text=>''}]; | |||||||||||||||||||||||||||
| 236 | push @rows, [{colspan=>5, align=>'left', bottom_border=>1, | ||||||||||||||||||||||||||||
| 237 | $attr => | ||||||||||||||||||||||||||||
| 238 | 0 | $code_fmttext->("Takaran saji "._fmt_num_id($args{serving_size})." g"). $BR . | |||||||||||||||||||||||||||
| 239 | $code_fmttext->(_fmt_num_id($srvs_per_pkg)." Sajian per Kemasan") | ||||||||||||||||||||||||||||
| 240 | }]; | ||||||||||||||||||||||||||||
| 241 | 0 | push @rows, [{colspan=>5, align=>'left', $attr => $code_fmttext->("*JUMLAH PER SAJIAN*")}]; | |||||||||||||||||||||||||||
| 242 | 0 | push @rows, [{colspan=>5, text=>''}]; | |||||||||||||||||||||||||||
| 243 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 244 | 0 | push @rows, $code_fmttext->("Takaran saji : " . _fmt_num_id($args{serving_size}) . " g, " . | |||||||||||||||||||||||||||
| 245 | _fmt_num_id($srvs_per_pkg)." Sajian per Kemasan *JUMLAH PER SAJIAN* : "); | ||||||||||||||||||||||||||||
| 246 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 247 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Sajian per kemasan*')}]; | |||||||||||||||||||||||||||
| 248 | push @rows, [{align=>'right', text=>'Sajian per kemasan'}, | ||||||||||||||||||||||||||||
| 249 | 0 | {align=>'left', $attr=>"= $args{package_size} / $args{serving_size} = ".($args{package_size}/$args{serving_size})}]; | |||||||||||||||||||||||||||
| 250 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan 0,5 terdekat)"}, | |||||||||||||||||||||||||||
| 251 | {align=>'left', $attr=>$code_fmttext->("= *".$srvs_per_pkg."*")}]; | ||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||
| 256 | ENERGY: { | ||||||||||||||||||||||||||||
| 257 | 0 | ▶ | my $code_round_energy = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 258 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 259 | 0 | ▶ | if ($val < 5) { 0 } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 260 | 0 | elsif ($val <= 50) { _nearest( 5, $val) } | |||||||||||||||||||||||||||
| 261 | 0 | else { _nearest(10, $val) } | |||||||||||||||||||||||||||
| 262 | 0 | }; | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 0 | my $val0 = $args{fat} * 9 + $args{protein} * 4 + $args{carbohydrate} * 4; | |||||||||||||||||||||||||||
| 265 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 266 | 0 | my $valr = $code_round_energy->($val); | |||||||||||||||||||||||||||
| 267 | 0 | my $pct_dv = $val/2150*100; | |||||||||||||||||||||||||||
| 268 | 0 | my $pct_dv_R = _nearest(1, $pct_dv); | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | $funcraw->{total_energy_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | $funcraw->{total_energy_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 271 | 0 | ▶ | $funcraw->{total_energy_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 272 | 0 | ▶ | $funcraw->{total_energy_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | $funcraw->{total_energy_pct_dv} = $pct_dv; | |||||||||||||||||||||||||||
| 274 | 0 | $funcraw->{total_energy_pct_dv_rounded} = $pct_dv_R; | |||||||||||||||||||||||||||
| 275 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 276 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | name_eng => 'Total energy', | ||||||||||||||||||||||||||||
| 278 | name_ind => 'Energi total', | ||||||||||||||||||||||||||||
| 279 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 280 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 281 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 282 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 283 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 284 | pct_dv => $pct_dv, | ||||||||||||||||||||||||||||
| 285 | pct_dv_R => $pct_dv_R, | ||||||||||||||||||||||||||||
| 286 | }; | ||||||||||||||||||||||||||||
| 287 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ($per_package_ing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | push @rows, [{bottom_border=>1, colspan=>5, $attr=>$code_fmttext->("*Energi total $valr kkal*")}]; | |||||||||||||||||||||||||||
| 290 | } else { | ||||||||||||||||||||||||||||
| 291 | 0 | push @rows, [{colspan=>3, $attr=>$code_fmttext->("*Energi total*")}, {colspan=>2, align=>'right', $attr=>$code_fmttext->("*$valr kkal*")}]; | |||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 294 | 0 | ▶ | if ($per_package_ing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | 0 | push @rows, $code_fmttext->("*Energi total $valr kkal*, "); | |||||||||||||||||||||||||||
| 296 | } else { | ||||||||||||||||||||||||||||
| 297 | 0 | push @rows, $code_fmttext->("*Energi total $valr kkal*, "); | |||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||
| 299 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 300 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Energi total*')}]; | |||||||||||||||||||||||||||
| 301 | 0 | push @rows, [{align=>'right', text=>'Energi total per 100 g'}, | |||||||||||||||||||||||||||
| 302 | {align=>'left', $attr=>"= lemak $M 9 + protein $M 4 + karbohidrat $M 4 = $args{fat} $M 9 + $args{protein} $M 4 + $args{carbohydrate} $M 4 = $val0 kkal"}]; | ||||||||||||||||||||||||||||
| 303 | 0 | ▶ | push @rows, [{align=>'right', text=>"Energi total per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val kkal"}]; | ||||||||||||||||||||||||||||
| 305 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <5 -> 0, <=50 -> 5 kkal terdekat, >50 -> 10 kkal terdekat)"}, | |||||||||||||||||||||||||||
| 306 | {align=>'left', $attr=>$code_fmttext->("= *$valr* kkal")}]; | ||||||||||||||||||||||||||||
| 307 | 0 | push @rows, ['', '']; | |||||||||||||||||||||||||||
| 308 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*%AKG energi total*')}]; | |||||||||||||||||||||||||||
| 309 | 0 | push @rows, [{align=>'right', text=>"\%AKG"}, | |||||||||||||||||||||||||||
| 310 | {align=>'left', $attr=>"= $val / 2150 $M 100 = $pct_dv"}]; | ||||||||||||||||||||||||||||
| 311 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan ke % terdekat)"}, | |||||||||||||||||||||||||||
| 312 | {align=>'left', $attr=>$code_fmttext->("= *$pct_dv_R*")}]; | ||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | ENERGY_FROM_FAT: { | ||||||||||||||||||||||||||||
| 316 | 0 | my $val0 = $args{fat} * 9; | |||||||||||||||||||||||||||
| 317 | 0 | my $val = $val0*$args{serving_size}/100; | |||||||||||||||||||||||||||
| 318 | 0 | my $valr = $code_round_energy->($val); | |||||||||||||||||||||||||||
| 319 | 0 | ▶ | $funcraw->{energy_from_fat_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 320 | 0 | ▶ | $funcraw->{energy_from_fat_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 321 | 0 | ▶ | $funcraw->{energy_from_fat_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | 0 | ▶ | $funcraw->{energy_from_fat_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 324 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 325 | name_eng => 'Energy from fat', | ||||||||||||||||||||||||||||
| 326 | name_ind => 'Energi dari lemak', | ||||||||||||||||||||||||||||
| 327 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 328 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 329 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 330 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 331 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 332 | }; | ||||||||||||||||||||||||||||
| 333 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 334 | 0 | ▶ | if ($per_package_ing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 335 | } else { | ||||||||||||||||||||||||||||
| 336 | 0 | push @rows, ['', {colspan=>2, $attr=>$code_fmttext->("Energi dari lemak")}, {colspan=>2, align=>'right', $attr=>$code_fmttext->("$valr kkal")}]; | |||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||
| 338 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 339 | 0 | push @rows, $code_fmttext->("Energi dari lemak $valr kkal, "); | |||||||||||||||||||||||||||
| 340 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 341 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Energi dari lemak*')}]; | |||||||||||||||||||||||||||
| 342 | 0 | push @rows, [{align=>'right', text=>'Energi dari lemak per 100 g'}, | |||||||||||||||||||||||||||
| 343 | {align=>'left', $attr=>"= lemak $M 9 = $args{fat} $M 9 = $val0 kkal"}]; | ||||||||||||||||||||||||||||
| 344 | 0 | ▶ | push @rows, [{align=>'right', text=>"Energi dari lemak per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val kkal"}]; | ||||||||||||||||||||||||||||
| 346 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <5 -> 0, <=50 -> 5 kkal terdekat, >50 -> 10 kkal terdekat)"}, | |||||||||||||||||||||||||||
| 347 | {align=>'left', $attr=>$code_fmttext->("= *$valr* kkal")}]; | ||||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||
| 351 | ENERGY_FROM_SATURATED_FAT: { | ||||||||||||||||||||||||||||
| 352 | 0 | my $val0 = $args{saturated_fat} * 9; | |||||||||||||||||||||||||||
| 353 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 354 | 0 | my $valr = $code_round_energy->($val); | |||||||||||||||||||||||||||
| 355 | 0 | ▶ | $funcraw->{energy_from_saturated_fat_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 356 | 0 | ▶ | $funcraw->{energy_from_saturated_fat_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 357 | 0 | ▶ | $funcraw->{energy_from_saturated_fat_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | 0 | ▶ | $funcraw->{energy_from_saturated_fat_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 360 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 361 | name_eng => 'Energy from saturated fat', | ||||||||||||||||||||||||||||
| 362 | name_ind => 'Energi dari lemak jenuh', | ||||||||||||||||||||||||||||
| 363 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 364 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 365 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 366 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 367 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 368 | }; | ||||||||||||||||||||||||||||
| 369 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 370 | 0 | ▶ | if ($per_package_ing) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 371 | } else { | ||||||||||||||||||||||||||||
| 372 | 0 | push @rows, [{bottom_border=>1, text=>''}, {colspan=>2, $attr=>$code_fmttext->("Energi dari lemak jenuh")}, {colspan=>2, align=>'right', $attr=>$code_fmttext->("$valr kkal")}]; | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 375 | 0 | push @rows, $code_fmttext->("Energi dari lemak jenuh $valr kkal, "); | |||||||||||||||||||||||||||
| 376 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 377 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Energi dari lemak jenuh*')}]; | |||||||||||||||||||||||||||
| 378 | 0 | push @rows, [{align=>'right', text=>'Energi dari lemak per 100 g'}, | |||||||||||||||||||||||||||
| 379 | {align=>'left', $attr=>"= lemak jenuh $M 9 = $args{saturated_fat} $M 9 = $val0 kkal"}]; | ||||||||||||||||||||||||||||
| 380 | 0 | ▶ | push @rows, [{align=>'right', text=>"Energi dari lemak jenuh per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 381 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val kkal"}]; | ||||||||||||||||||||||||||||
| 382 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <5 -> 0, <=50 -> 5 kkal terdekat, >50 -> 10 kkal terdekat)"}, | |||||||||||||||||||||||||||
| 383 | {align=>'left', $attr=>$code_fmttext->("= *$valr* kkal")}]; | ||||||||||||||||||||||||||||
| 384 | } | ||||||||||||||||||||||||||||
| 385 | } | ||||||||||||||||||||||||||||
| 386 | } # ENERGY | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 389 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 390 | 0 | push @rows, [{colspan=>3, text=>''}, {colspan=>2, align=>'middle', $attr=>$code_fmttext->("*\% AKG**")}]; | |||||||||||||||||||||||||||
| 391 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 392 | } | ||||||||||||||||||||||||||||
| 393 | |||||||||||||||||||||||||||||
| 394 | FAT: { | ||||||||||||||||||||||||||||
| 395 | 0 | ▶ | my $code_round_fat = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 396 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 397 | 0 | ▶ | if ($val < 0.5) { 0 } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 398 | 0 | elsif ($val <= 5) { sprintf("%.1f", _nearest(0.5, $val)) } | |||||||||||||||||||||||||||
| 399 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 400 | 0 | }; | |||||||||||||||||||||||||||
| 401 | 0 | ▶ | my $code_round_fat_pct_dv = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 402 | 0 | my ($val, $valr) = @_; | |||||||||||||||||||||||||||
| 403 | 0 | ▶ | if ($valr == 0) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 404 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 405 | 0 | }; | |||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | 0 | my $val0 = $args{fat}; | |||||||||||||||||||||||||||
| 408 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 409 | 0 | my $valr = $code_round_fat->($val); | |||||||||||||||||||||||||||
| 410 | 0 | my $pct_dv = $val/67*100; | |||||||||||||||||||||||||||
| 411 | 0 | my $pct_dv_R = $code_round_fat_pct_dv->($pct_dv, $valr); | |||||||||||||||||||||||||||
| 412 | 0 | ▶ | $funcraw->{total_fat_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 413 | 0 | ▶ | $funcraw->{total_fat_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 414 | 0 | ▶ | $funcraw->{total_fat_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 415 | 0 | ▶ | $funcraw->{total_fat_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 416 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 417 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 418 | name_eng => 'Total fat', | ||||||||||||||||||||||||||||
| 419 | name_ind => 'Lemak total', | ||||||||||||||||||||||||||||
| 420 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 421 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 422 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 423 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 424 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 425 | pct_dv => $pct_dv, | ||||||||||||||||||||||||||||
| 426 | pct_dv_R => $pct_dv_R, | ||||||||||||||||||||||||||||
| 427 | }; | ||||||||||||||||||||||||||||
| 428 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 429 | 0 | push @rows, [{colspan=>2, $attr=>$code_fmttext->("*Lemak total*")}, {align=>'right', $attr=>$code_fmttext->("*$valr g*")}, {align=>'right', $attr=>"$pct_dv_R %"}, '']; | |||||||||||||||||||||||||||
| 430 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 431 | 0 | push @rows, $code_fmttext->("*Lemak total $valr g ($pct_dv_R% AKG)*, "); | |||||||||||||||||||||||||||
| 432 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 433 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Lemak total*')}]; | |||||||||||||||||||||||||||
| 434 | 0 | push @rows, [{align=>'right', text=>'Lemak total per 100 g'}, | |||||||||||||||||||||||||||
| 435 | {align=>'left', $attr=>"= $args{fat} g"}]; | ||||||||||||||||||||||||||||
| 436 | 0 | ▶ | push @rows, [{align=>'right', text=>"Lemak total per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 437 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val g"}]; | ||||||||||||||||||||||||||||
| 438 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <0.5 -> 0, <=5 -> 0.5 g terdekat, >=5 -> 1 g terdekat)"}, | |||||||||||||||||||||||||||
| 439 | {align=>'left', $attr=>$code_fmttext->("= *$valr* g")}]; | ||||||||||||||||||||||||||||
| 440 | 0 | push @rows, ['', '']; | |||||||||||||||||||||||||||
| 441 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*%AKG lemak total*')}]; | |||||||||||||||||||||||||||
| 442 | 0 | push @rows, [{align=>'right', text=>"\%AKG"}, | |||||||||||||||||||||||||||
| 443 | {align=>'left', $attr=>"= $val / 67 $M 100 = $pct_dv"}]; | ||||||||||||||||||||||||||||
| 444 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan ke % terdekat)"}, | |||||||||||||||||||||||||||
| 445 | {align=>'left', $attr=>$code_fmttext->("= *$pct_dv_R*")}]; | ||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||
| 448 | SATURATED_FAT: { | ||||||||||||||||||||||||||||
| 449 | 0 | my $val0 = $args{saturated_fat}; | |||||||||||||||||||||||||||
| 450 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 451 | 0 | my $valr = $code_round_fat->($val); | |||||||||||||||||||||||||||
| 452 | 0 | my $pct_dv = $val/20*100; | |||||||||||||||||||||||||||
| 453 | 0 | my $pct_dv_R = $code_round_fat_pct_dv->($pct_dv, $valr); | |||||||||||||||||||||||||||
| 454 | 0 | ▶ | $funcraw->{saturated_fat_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 455 | 0 | ▶ | $funcraw->{saturated_fat_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 456 | 0 | ▶ | $funcraw->{saturated_fat_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 457 | 0 | ▶ | $funcraw->{saturated_fat_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 458 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 459 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 460 | name_eng => 'Saturated fat', | ||||||||||||||||||||||||||||
| 461 | name_ind => 'Lemak jenuh', | ||||||||||||||||||||||||||||
| 462 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 463 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 464 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 465 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 466 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 467 | pct_dv => $pct_dv, | ||||||||||||||||||||||||||||
| 468 | pct_dv_R => $pct_dv_R, | ||||||||||||||||||||||||||||
| 469 | }; | ||||||||||||||||||||||||||||
| 470 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 471 | 0 | push @rows, [{colspan=>2, $attr=>$code_fmttext->("*Lemak jenuh*")}, {align=>'right', $attr=>$code_fmttext->("*$valr g*")}, {align=>'right', $attr=>"$pct_dv_R %"}, '']; | |||||||||||||||||||||||||||
| 472 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 473 | 0 | push @rows, $code_fmttext->("*Lemak jenuh $valr g ($pct_dv_R% AKG)*, "); | |||||||||||||||||||||||||||
| 474 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 475 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Lemak jenuh*')}]; | |||||||||||||||||||||||||||
| 476 | 0 | push @rows, [{align=>'right', text=>'Lemak jenuh per 100 g'}, | |||||||||||||||||||||||||||
| 477 | {align=>'left', $attr=>"= $args{saturated_fat} g"}]; | ||||||||||||||||||||||||||||
| 478 | 0 | ▶ | push @rows, [{align=>'right', text=>"Lemak jenuh per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 479 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val g"}]; | ||||||||||||||||||||||||||||
| 480 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <0.5 -> 0, <=5 -> 0.5 g terdekat, >=5 -> 1 g terdekat)"}, | |||||||||||||||||||||||||||
| 481 | {align=>'left', $attr=>$code_fmttext->("= *$valr* g")}]; | ||||||||||||||||||||||||||||
| 482 | 0 | push @rows, ['', '']; | |||||||||||||||||||||||||||
| 483 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*%AKG lemak jenuh*')}]; | |||||||||||||||||||||||||||
| 484 | 0 | push @rows, [{align=>'right', text=>"\%AKG"}, | |||||||||||||||||||||||||||
| 485 | {align=>'left', $attr=>"= $val / 67 $M 100 = $pct_dv"}]; | ||||||||||||||||||||||||||||
| 486 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan ke % terdekat)"}, | |||||||||||||||||||||||||||
| 487 | {align=>'left', $attr=>$code_fmttext->("= *$pct_dv_R*")}]; | ||||||||||||||||||||||||||||
| 488 | } | ||||||||||||||||||||||||||||
| 489 | } # FAT | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | CHOLESTEROL: { | ||||||||||||||||||||||||||||
| 492 | 0 | ▶ | my $code_round_cholesterol = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 493 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 494 | 0 | ▶ | if ($val < 2) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 495 | 0 | ▶ | if ($val <= 5) { _nearest(1 , $val) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 496 | 0 | else { _nearest(5 , $val) } | |||||||||||||||||||||||||||
| 497 | 0 | }; | |||||||||||||||||||||||||||
| 498 | 0 | ▶ | my $code_round_cholesterol_pct_dv = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 499 | 0 | my ($val, $valr) = @_; | |||||||||||||||||||||||||||
| 500 | 0 | ▶ | if ($valr == 0) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 501 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 502 | 0 | }; | |||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||
| 504 | 0 | my $val0 = $args{cholesterol}; | |||||||||||||||||||||||||||
| 505 | 0 | ▶ | last unless defined $val0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 506 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 507 | 0 | my $valr = $code_round_cholesterol->($val); | |||||||||||||||||||||||||||
| 508 | 0 | my $pct_dv = $val/300*100; | |||||||||||||||||||||||||||
| 509 | 0 | my $pct_dv_R = $code_round_cholesterol_pct_dv->($pct_dv, $valr); | |||||||||||||||||||||||||||
| 510 | 0 | ▶ | $funcraw->{cholesterol_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 511 | 0 | ▶ | $funcraw->{cholesterol_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 512 | 0 | ▶ | $funcraw->{cholesterol_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 513 | 0 | ▶ | $funcraw->{cholesterol_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 514 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 515 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 516 | name_eng => 'Cholesterol', | ||||||||||||||||||||||||||||
| 517 | name_ind => 'Kolesterol', | ||||||||||||||||||||||||||||
| 518 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 519 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 520 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 521 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 522 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 523 | pct_dv => $pct_dv, | ||||||||||||||||||||||||||||
| 524 | pct_dv_R => $pct_dv_R, | ||||||||||||||||||||||||||||
| 525 | }; | ||||||||||||||||||||||||||||
| 526 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 527 | 0 | push @rows, [{colspan=>2, $attr=>$code_fmttext->("Kolesterol")}, {align=>'right', $attr=>$code_fmttext->("$valr mg")}, {align=>'right', $attr=>"$pct_dv_R %"}, '']; | |||||||||||||||||||||||||||
| 528 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 529 | 0 | push @rows, $code_fmttext->("Kolesterol $valr mg ($pct_dv_R% AKG), "); | |||||||||||||||||||||||||||
| 530 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 531 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Kolesterol*')}]; | |||||||||||||||||||||||||||
| 532 | 0 | push @rows, [{align=>'right', text=>'Kolesterol per 100 g'}, | |||||||||||||||||||||||||||
| 533 | {align=>'left', $attr=>"= $args{cholesterol} mg"}]; | ||||||||||||||||||||||||||||
| 534 | 0 | ▶ | push @rows, [{align=>'right', text=>"Kolesterol total per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 535 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val mg"}]; | ||||||||||||||||||||||||||||
| 536 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <2 -> 0, 2-5 -> 1 mg terdekat, >5 -> 5 mg terdekat)"}, | |||||||||||||||||||||||||||
| 537 | {align=>'left', $attr=>$code_fmttext->("= *$valr* mg")}]; | ||||||||||||||||||||||||||||
| 538 | 0 | push @rows, ['', '']; | |||||||||||||||||||||||||||
| 539 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*%AKG kolesterol*')}]; | |||||||||||||||||||||||||||
| 540 | 0 | push @rows, [{align=>'right', text=>"\%AKG"}, | |||||||||||||||||||||||||||
| 541 | {align=>'left', $attr=>"= $val / 300 $M 100 = $pct_dv"}]; | ||||||||||||||||||||||||||||
| 542 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan ke % terdekat)"}, | |||||||||||||||||||||||||||
| 543 | {align=>'left', $attr=>$code_fmttext->("= *$pct_dv_R*")}]; | ||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||
| 545 | } | ||||||||||||||||||||||||||||
| 546 | |||||||||||||||||||||||||||||
| 547 | PROTEIN: { | ||||||||||||||||||||||||||||
| 548 | 0 | ▶ | my $code_round_protein = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 549 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 550 | 0 | ▶ | if ($val < 0.5) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 551 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 552 | 0 | }; | |||||||||||||||||||||||||||
| 553 | 0 | ▶ | my $code_round_protein_pct_dv = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 554 | 0 | my ($val, $valr) = @_; | |||||||||||||||||||||||||||
| 555 | 0 | ▶ | if ($valr == 0) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 556 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 557 | 0 | }; | |||||||||||||||||||||||||||
| 558 | |||||||||||||||||||||||||||||
| 559 | 0 | my $val0 = $args{protein}; | |||||||||||||||||||||||||||
| 560 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 561 | 0 | my $valr = $code_round_protein->($val); | |||||||||||||||||||||||||||
| 562 | 0 | my $pct_dv = $val/60*100; | |||||||||||||||||||||||||||
| 563 | 0 | my $pct_dv_R = $code_round_protein_pct_dv->($pct_dv, $valr); | |||||||||||||||||||||||||||
| 564 | 0 | ▶ | $funcraw->{protein_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 565 | 0 | ▶ | $funcraw->{protein_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 566 | 0 | ▶ | $funcraw->{protein_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 567 | 0 | ▶ | $funcraw->{protein_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 568 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 569 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 570 | name_eng => 'Protein', | ||||||||||||||||||||||||||||
| 571 | name_ind => 'Protein', | ||||||||||||||||||||||||||||
| 572 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 573 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 574 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 575 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 576 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 577 | pct_dv => $pct_dv, | ||||||||||||||||||||||||||||
| 578 | pct_dv_R => $pct_dv_R, | ||||||||||||||||||||||||||||
| 579 | }; | ||||||||||||||||||||||||||||
| 580 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 581 | 0 | push @rows, [{colspan=>2, $attr=>$code_fmttext->("*Protein*")}, {align=>'right', $attr=>$code_fmttext->("*$valr g*")}, {align=>'right', $attr=>"$pct_dv_R %"}, '']; | |||||||||||||||||||||||||||
| 582 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 583 | 0 | push @rows, $code_fmttext->("*Protein $valr g ($pct_dv_R% AKG)*, "); | |||||||||||||||||||||||||||
| 584 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 585 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Protein*')}]; | |||||||||||||||||||||||||||
| 586 | 0 | push @rows, [{align=>'right', text=>'Protein per 100 g'}, | |||||||||||||||||||||||||||
| 587 | {align=>'left', $attr=>"= $args{protein} g"}]; | ||||||||||||||||||||||||||||
| 588 | 0 | ▶ | push @rows, [{align=>'right', text=>"Protein total per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 589 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val g"}]; | ||||||||||||||||||||||||||||
| 590 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <0.5 -> 0, >=0.5 -> 1 g terdekat)"}, | |||||||||||||||||||||||||||
| 591 | {align=>'left', $attr=>$code_fmttext->("= *$valr* g")}]; | ||||||||||||||||||||||||||||
| 592 | 0 | push @rows, ['', '']; | |||||||||||||||||||||||||||
| 593 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*%AKG protein*')}]; | |||||||||||||||||||||||||||
| 594 | 0 | push @rows, [{align=>'right', text=>"\%AKG"}, | |||||||||||||||||||||||||||
| 595 | {align=>'left', $attr=>"= $val / 60 $M 100 = $pct_dv"}]; | ||||||||||||||||||||||||||||
| 596 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan ke % terdekat)"}, | |||||||||||||||||||||||||||
| 597 | {align=>'left', $attr=>$code_fmttext->("= *$pct_dv_R*")}]; | ||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | CARBOHYDRATE: { | ||||||||||||||||||||||||||||
| 602 | 0 | ▶ | my $code_round_carbohydrate = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 603 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 604 | 0 | ▶ | if ($val < 0.5) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 605 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 606 | 0 | }; | |||||||||||||||||||||||||||
| 607 | 0 | ▶ | my $code_round_carbohydrate_pct_dv = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 608 | 0 | my ($val, $valr) = @_; | |||||||||||||||||||||||||||
| 609 | 0 | ▶ | if ($valr == 0) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 610 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 611 | 0 | }; | |||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | 0 | my $val0 = $args{carbohydrate}; | |||||||||||||||||||||||||||
| 614 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 615 | 0 | my $valr = $code_round_carbohydrate->($val); | |||||||||||||||||||||||||||
| 616 | 0 | my $pct_dv_R = $code_round_carbohydrate_pct_dv->($val/325*100, $valr); | |||||||||||||||||||||||||||
| 617 | 0 | ▶ | $funcraw->{carbohydrate_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 618 | 0 | ▶ | $funcraw->{carbohydrate_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 619 | 0 | ▶ | $funcraw->{carbohydrate_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 620 | 0 | ▶ | $funcraw->{carbohydrate_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 621 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 622 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 623 | name_eng => 'Total carbohydrate', | ||||||||||||||||||||||||||||
| 624 | name_ind => 'Karbohidrat total', | ||||||||||||||||||||||||||||
| 625 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 626 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 627 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 628 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 629 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 630 | pct_dv => $val/325*100, | ||||||||||||||||||||||||||||
| 631 | pct_dv_R => $pct_dv_R, | ||||||||||||||||||||||||||||
| 632 | }; | ||||||||||||||||||||||||||||
| 633 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 634 | 0 | push @rows, [{colspan=>2, $attr=>$code_fmttext->("*Karbohidrat total*")}, {align=>'right', $attr=>$code_fmttext->("*$valr g*")}, {align=>'right', $attr=>"$pct_dv_R %"}, '']; | |||||||||||||||||||||||||||
| 635 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 636 | 0 | push @rows, $code_fmttext->("*Karbohidrat total $valr g ($pct_dv_R% AKG)*, "); | |||||||||||||||||||||||||||
| 637 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 638 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Karbohidrat total*')}]; | |||||||||||||||||||||||||||
| 639 | 0 | push @rows, [{align=>'right', text=>'Karbohidrat total per 100 g'}, | |||||||||||||||||||||||||||
| 640 | {align=>'left', $attr=>"= $args{carbohydrate} g"}]; | ||||||||||||||||||||||||||||
| 641 | 0 | ▶ | push @rows, [{align=>'right', text=>"Karbohidrat total per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 642 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val g"}]; | ||||||||||||||||||||||||||||
| 643 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <0.5 -> 0, >=0.5 -> 1 g terdekat)"}, | |||||||||||||||||||||||||||
| 644 | {align=>'left', $attr=>$code_fmttext->("= *$valr* g")}]; | ||||||||||||||||||||||||||||
| 645 | 0 | push @rows, ['', '']; | |||||||||||||||||||||||||||
| 646 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*%AKG karbohidrat total*')}]; | |||||||||||||||||||||||||||
| 647 | 0 | push @rows, [{align=>'right', text=>"\%AKG"}, | |||||||||||||||||||||||||||
| 648 | {align=>'left', $attr=>"= $val / 325 $M 100 = $pct_dv"}]; | ||||||||||||||||||||||||||||
| 649 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan ke % terdekat)"}, | |||||||||||||||||||||||||||
| 650 | {align=>'left', $attr=>$code_fmttext->("= *$pct_dv_R*")}]; | ||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||
| 652 | } | ||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | SUGAR: { | ||||||||||||||||||||||||||||
| 655 | 0 | ▶ | my $code_round_sugar = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 656 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 657 | 0 | ▶ | if ($val < 0.5) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 658 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 659 | 0 | }; | |||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | 0 | my $val0 = $args{sugar}; | |||||||||||||||||||||||||||
| 662 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 663 | 0 | my $valr = $code_round_sugar->($val); | |||||||||||||||||||||||||||
| 664 | 0 | ▶ | $funcraw->{total_sugar_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 665 | 0 | ▶ | $funcraw->{total_sugar_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 666 | 0 | ▶ | $funcraw->{total_sugar_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 667 | 0 | ▶ | $funcraw->{total_sugar_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 668 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 669 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 670 | name_eng => 'Total sugar', | ||||||||||||||||||||||||||||
| 671 | name_ind => 'Gula total', | ||||||||||||||||||||||||||||
| 672 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 673 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 674 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 675 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 676 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 677 | }; | ||||||||||||||||||||||||||||
| 678 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 679 | 0 | push @rows, [{colspan=>2, $attr=>$code_fmttext->("*Gula*")}, {align=>'right', $attr=>$code_fmttext->("*$valr g*")}, '', '']; | |||||||||||||||||||||||||||
| 680 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 681 | 0 | push @rows, $code_fmttext->("*Gula $valr g*, "); | |||||||||||||||||||||||||||
| 682 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 683 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Gula*')}]; | |||||||||||||||||||||||||||
| 684 | 0 | push @rows, [{align=>'right', text=>'Gula per 100 g'}, | |||||||||||||||||||||||||||
| 685 | {align=>'left', $attr=>"= $args{sugar} g"}]; | ||||||||||||||||||||||||||||
| 686 | 0 | ▶ | push @rows, [{align=>'right', text=>"Gula per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 687 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val g"}]; | ||||||||||||||||||||||||||||
| 688 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <0.5 -> 0, >=0.5 -> 1 g terdekat)"}, | |||||||||||||||||||||||||||
| 689 | {align=>'left', $attr=>$code_fmttext->("= *$valr* g")}]; | ||||||||||||||||||||||||||||
| 690 | } | ||||||||||||||||||||||||||||
| 691 | } | ||||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | SODIUM: { | ||||||||||||||||||||||||||||
| 694 | 0 | ▶ | my $code_round_sodium = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 695 | 0 | my $val = shift; | |||||||||||||||||||||||||||
| 696 | 0 | ▶ | if ($val < 5) { 0 } | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 697 | 0 | elsif ($val <= 140) { _nearest( 5, $val) } | |||||||||||||||||||||||||||
| 698 | 0 | else { _nearest(10, $val) } | |||||||||||||||||||||||||||
| 699 | 0 | }; | |||||||||||||||||||||||||||
| 700 | 0 | ▶ | my $code_round_sodium_pct_dv = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 701 | 0 | my ($val, $fat_valr) = @_; | |||||||||||||||||||||||||||
| 702 | 0 | ▶ | if ($fat_valr == 0) { 0 } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 703 | 0 | else { _nearest(1 , $val) } | |||||||||||||||||||||||||||
| 704 | 0 | }; | |||||||||||||||||||||||||||
| 705 | |||||||||||||||||||||||||||||
| 706 | 0 | my $val0 = $args{sodium}; | |||||||||||||||||||||||||||
| 707 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 708 | 0 | my $valr = $code_round_sodium->($val); | |||||||||||||||||||||||||||
| 709 | 0 | my $pct_dv = $val/1500*100; | |||||||||||||||||||||||||||
| 710 | 0 | my $pct_dv_R = $code_round_sodium_pct_dv->($val/1500*100, $valr); | |||||||||||||||||||||||||||
| 711 | 0 | ▶ | $funcraw->{sodium_per_srv} = $val if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 712 | 0 | ▶ | $funcraw->{sodium_per_srv_rounded} = $valr if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 713 | 0 | ▶ | $funcraw->{sodium_per_pkg} = $val if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 714 | 0 | ▶ | $funcraw->{sodium_per_pkg_rounded} = $valr if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 715 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 716 | 0 | ▶ | push @rows, { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 717 | name_eng => 'Salt (Sodium)', | ||||||||||||||||||||||||||||
| 718 | name_ind => 'Garam (Natrium)', | ||||||||||||||||||||||||||||
| 719 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 720 | (val_per_srv => $val, | ||||||||||||||||||||||||||||
| 721 | val_per_srv_R => $valr) x ($per_package_ing ? 0:1), | ||||||||||||||||||||||||||||
| 722 | (val_per_pkg => $val, | ||||||||||||||||||||||||||||
| 723 | val_per_pkg_R => $valr) x $per_package_ing, | ||||||||||||||||||||||||||||
| 724 | pct_dv => $val/325*100, | ||||||||||||||||||||||||||||
| 725 | pct_dv_R => $pct_dv_R, | ||||||||||||||||||||||||||||
| 726 | }; | ||||||||||||||||||||||||||||
| 727 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 728 | 0 | push @rows, [{bottom_border=>1, colspan=>2, $attr=>$code_fmttext->("*Garam (Natrium)*")}, {align=>'right', $attr=>$code_fmttext->("*$valr mg*")}, {align=>'right', $attr=>"$pct_dv_R %"}, '']; | |||||||||||||||||||||||||||
| 729 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 730 | 0 | push @rows, $code_fmttext->("*Garam (Natrium) $valr mg ($pct_dv_R% AKG)*. "); | |||||||||||||||||||||||||||
| 731 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 732 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*Natrium*')}]; | |||||||||||||||||||||||||||
| 733 | 0 | push @rows, [{align=>'right', text=>'Natrium per 100 g'}, | |||||||||||||||||||||||||||
| 734 | {align=>'left', $attr=>"= $args{sodium} mg"}]; | ||||||||||||||||||||||||||||
| 735 | 0 | ▶ | push @rows, [{align=>'right', text=>"Natrium per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 736 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val mg"}]; | ||||||||||||||||||||||||||||
| 737 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan: <5 -> 0, <=140 -> 5 mg terdekat, >140 -> 10 mg terdekat)"}, | |||||||||||||||||||||||||||
| 738 | {align=>'left', $attr=>$code_fmttext->("= *$valr* mg")}]; | ||||||||||||||||||||||||||||
| 739 | 0 | push @rows, ['', '']; | |||||||||||||||||||||||||||
| 740 | 0 | push @rows, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->('*%AKG natrium*')}]; | |||||||||||||||||||||||||||
| 741 | 0 | push @rows, [{align=>'right', text=>"\%AKG"}, | |||||||||||||||||||||||||||
| 742 | {align=>'left', $attr=>"= $val / 1500 $M 100 = $pct_dv"}]; | ||||||||||||||||||||||||||||
| 743 | 0 | push @rows, [{align=>'right', text=>"(dibulatkan ke % terdekat)"}, | |||||||||||||||||||||||||||
| 744 | {align=>'left', $attr=>$code_fmttext->("= *$pct_dv_R*")}]; | ||||||||||||||||||||||||||||
| 745 | } | ||||||||||||||||||||||||||||
| 746 | } | ||||||||||||||||||||||||||||
| 747 | } | ||||||||||||||||||||||||||||
| 748 | |||||||||||||||||||||||||||||
| 749 | VITAMIN_MINERAL_NONNUTRIENTS: { | ||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||
| 751 | 0 | my @rows_vm; | |||||||||||||||||||||||||||
| 752 | VITAMIN_MINERAL: { | ||||||||||||||||||||||||||||
| 753 | 0 | ▶ | my $code_round_vitamin_mineral_pct_dv = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 754 | 0 | my ($val, $valr) = @_; | |||||||||||||||||||||||||||
| 755 | 0 | ▶ | if ($val <= 10) { _nearest(2, $val) } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 756 | 0 | else { _nearest(5, $val) } | |||||||||||||||||||||||||||
| 757 | 0 | }; | |||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||
| 759 | 0 | ▶ | my $do_vm = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=18 SCAR=58.3
| |||||||||||||||||||||||||||||
| 760 | 0 | my ($sym, $name_ind, $akg, $unit, $name_eng) = @_; | |||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||
| 762 | 0 | my $val0 = $args{$sym}; | |||||||||||||||||||||||||||
| 763 | 0 | my $val0_nufact = $args{"${sym}_nufact"}; | |||||||||||||||||||||||||||
| 764 | 0 | my $nufact_note = $args{"${sym}_nufact_note"}; | |||||||||||||||||||||||||||
| 765 | |||||||||||||||||||||||||||||
| 766 | 0 | ▶ | if (defined $val0_nufact) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 767 | 0 | ▶ | if ($args{has_claims}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 768 | 0 | ▶ | if ($val0 < $val0_nufact) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 769 | 0 | die "$name_eng: In food with claims, value in lab test result ($val0) must be greater than or equal to value to be shown in nufacts"; | |||||||||||||||||||||||||||
| 770 | } | ||||||||||||||||||||||||||||
| 771 | } else { | ||||||||||||||||||||||||||||
| 772 | 0 | ▶ | if ($val0 < $val0_nufact * 0.8) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 773 | 0 | die "$name_eng: In food without claims, value in lab test result ($val0) must at least be 80% of value to be shown in nufacts"; | |||||||||||||||||||||||||||
| 774 | } | ||||||||||||||||||||||||||||
| 775 | } | ||||||||||||||||||||||||||||
| 776 | 0 | $val0 = $val0_nufact; | |||||||||||||||||||||||||||
| 777 | } | ||||||||||||||||||||||||||||
| 778 | |||||||||||||||||||||||||||||
| 779 | 0 | ▶ | $name_eng //= $name_ind; | ||||||||||||||||||||||||||
|
Condition0%0/3
$name_eng //= $name_ind
MC/DC0%0/2
$name_eng //= $name_ind
$name_eng
$name_ind
Truth table0%0/3
A //= B
A= $name_engB= $name_ind
| |||||||||||||||||||||||||||||
| 780 | 0 | my $val = $val0*$args{$size_key}/100; | |||||||||||||||||||||||||||
| 781 | 0 | my $pct_dv = $val/$akg *100; | |||||||||||||||||||||||||||
| 782 | 0 | my $pct_dv_R = $code_round_vitamin_mineral_pct_dv->($pct_dv, $pct_dv); | |||||||||||||||||||||||||||
| 783 | 0 | ▶ | if ($pct_dv_R < 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 784 | 0 | die "$name_eng value is below 2% AKG, can't show in nutrition facts\n"; | |||||||||||||||||||||||||||
| 785 | 0 | return; | |||||||||||||||||||||||||||
| 786 | } | ||||||||||||||||||||||||||||
| 787 | 0 | ▶ | $funcraw->{"${sym}_pct_dv_per_srv"} = $pct_dv if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 788 | 0 | ▶ | $funcraw->{"${sym}_pct_dv_per_srv_rounded"} = $pct_dv_R if !$per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 789 | 0 | ▶ | $funcraw->{"${sym}_pct_dv_per_pkg"} = $pct_dv if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 790 | 0 | ▶ | $funcraw->{"${sym}_pct_dv_per_pkg_rounded"} = $pct_dv_R if $per_package_ing; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 791 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 792 | 0 | ▶ | push @rows_vm, { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 793 | name_eng => $name_eng, | ||||||||||||||||||||||||||||
| 794 | name_ind => $name_ind, | ||||||||||||||||||||||||||||
| 795 | val_per_100g => $val0, | ||||||||||||||||||||||||||||
| 796 | (val_per_srv => $val) x (!$per_package_ing ? 1:0), | ||||||||||||||||||||||||||||
| 797 | (val_per_pkg => $val) x ( $per_package_ing ? 1:0), | ||||||||||||||||||||||||||||
| 798 | pct_dv => $pct_dv, | ||||||||||||||||||||||||||||
| 799 | pct_dv_R => $pct_dv_R, | ||||||||||||||||||||||||||||
| 800 | }; | ||||||||||||||||||||||||||||
| 801 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 802 | 0 | push @rows_vm, [{}, {colspan=>2, $attr=>$code_fmttext->($name_ind)}, {colspan=>2, align=>'right', $attr=>$code_fmttext->("$pct_dv_R %")}]; | |||||||||||||||||||||||||||
| 803 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 804 | 0 | push @rows_vm, $code_fmttext->("$name_ind ($pct_dv_R% AKG)"); | |||||||||||||||||||||||||||
| 805 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 806 | 0 | push @rows_vm, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->("*$name_ind*")}]; | |||||||||||||||||||||||||||
| 807 | 0 | push @rows_vm, [{align=>'right', text=>"$name_ind per 100 g"}, | |||||||||||||||||||||||||||
| 808 | {align=>'left', $attr=>"= $val0 $unit"}]; | ||||||||||||||||||||||||||||
| 809 | 0 | ▶ | push @rows_vm, [{align=>'right', text=>"$name_ind total per ".($per_package_ing ? "kemasan $args{package_size} g" : "takaran saji $args{serving_size} g")}, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 810 | {align=>'left', $attr=>"= $val0 $M $args{$size_key} / 100 = $val $unit"}]; | ||||||||||||||||||||||||||||
| 811 | 0 | push @rows_vm, ['', '']; | |||||||||||||||||||||||||||
| 812 | 0 | push @rows_vm, [{colspan=>2, align=>'middle', $attr=>$code_fmttext->("*%AKG $name_ind*")}]; | |||||||||||||||||||||||||||
| 813 | 0 | push @rows_vm, [{align=>'right', text=>"\%AKG"}, | |||||||||||||||||||||||||||
| 814 | {align=>'left', $attr=>"= $val / $akg $M 100 = $pct_dv"}]; | ||||||||||||||||||||||||||||
| 815 | 0 | push @rows_vm, [{align=>'right', text=>"(dibulatkan [<=10% AKG -> 2% terdekat, >10% AKG -> 5% terdekat])"}, | |||||||||||||||||||||||||||
| 816 | {align=>'left', $attr=>$code_fmttext->("= *$pct_dv_R*")}]; | ||||||||||||||||||||||||||||
| 817 | } | ||||||||||||||||||||||||||||
| 818 | 0 | }; # do_vm | |||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||
| 820 | 0 | ▶ | $do_vm->("va", "Vitamin A", 600, "mcg (all-trans-)retinol") if $args{va}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 821 | 0 | ▶ | $do_vm->("vd", "Vitamin D", 15, "mcg") if $args{vd}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 822 | 0 | ▶ | $do_vm->("ve", "Vitamin E", 15, "mg alpha-TE (tocopherol-equivalent)") if $args{ve}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 823 | 0 | ▶ | $do_vm->("vk", "Vitamin K", 60, "mcg") if $args{vk}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 824 | 0 | ▶ | $do_vm->("vb1", "Vitamin B1", 1.4, "mg") if $args{vb1}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 825 | 0 | ▶ | $do_vm->("vb2", "Vitamin B2", 1.6, "mg") if $args{vb2}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 826 | 0 | ▶ | $do_vm->("vb3", "Vitamin B3", 15, "mg") if $args{vb3}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 827 | 0 | ▶ | $do_vm->("vb5", "Vitamin B5", 5, "mg") if $args{vb5}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 828 | 0 | ▶ | $do_vm->("vb6", "Vitamin B6", 1.3, "mg") if $args{vb6}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 829 | 0 | ▶ | $do_vm->("folate", "Folat", 400, "mcg", "Folate") if $args{folate}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 830 | 0 | ▶ | $do_vm->("vb12", "Vitamin B12", 2.4, "mcg") if $args{vb12}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 831 | 0 | ▶ | $do_vm->("biotin", "Biotin", 30, "mcg") if $args{biotin}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 832 | 0 | ▶ | $do_vm->("choline", "Kolin", 450, "mg", "Choline") if $args{choline}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 833 | 0 | ▶ | $do_vm->("vc", "Vitamin C", 90, "mg") if $args{vc}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 834 | 0 | ▶ | $do_vm->("ca", "Kalsium", 1100, "mg", "Calcium") if $args{ca}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 835 | 0 | ▶ | $do_vm->("phosphorus", "Fosfor", 700, "mg", "Phosphorus") if $args{phosphorus}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 836 | 0 | ▶ | $do_vm->("mg", "Magnesium", 350, "mg") if $args{mg}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 837 | 0 | ▶ | $do_vm->("potassium", "Kalium", 4700, "mg", "Potassium") if $args{potassium}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 838 | 0 | ▶ | $do_vm->("mn", "Mangan", 2000, "mcg", "Manganese") if $args{mn}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 839 | 0 | ▶ | $do_vm->("cu", "Tembaga", 800, "mcg", "Copper") if $args{cu}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 840 | 0 | ▶ | $do_vm->("cr", "Kromium", 26, "mcg", "Chromium") if $args{cr}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 841 | 0 | ▶ | $do_vm->("fe", "Besi", 22, "mg", "Iron") if $args{fe}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 842 | 0 | ▶ | $do_vm->("iodium", "Iodium", 90, "mcg", "Iodium") if $args{iodium}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 843 | 0 | ▶ | $do_vm->("zn", "Seng", 13, "mg", "Zinc") if $args{zn}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 844 | 0 | ▶ | $do_vm->("se", "Selenium", 30, "mcg") if $args{se}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 845 | 0 | ▶ | $do_vm->("fluorine", "Fluor", 2.5, "mg", "Fluorine") if $args{fluorine}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 846 | } # VITAMIN_MINERAL | ||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||
| 848 | 0 | my @rows_nn; | |||||||||||||||||||||||||||
| 849 | NONNUTRIENTS: { | ||||||||||||||||||||||||||||
| 850 | 0 | 1; | |||||||||||||||||||||||||||
| 851 | } # NONNUTRIENTS | ||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||
| 853 | # add heading & border | ||||||||||||||||||||||||||||
| 854 | 0 | ▶ | if (@rows_vm) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 855 | 0 | ▶ | if ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 856 | 0 | push @rows, [{colspan=>5, $attr=>$code_fmttext->("Vitamin dan mineral")}]; | |||||||||||||||||||||||||||
| 857 | 0 | ▶ | unless (@rows_nn) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 858 | 0 | for (@{ $rows_vm[-1] }) { $_->{bottom_border} = 1 } | |||||||||||||||||||||||||||
| 859 | } | ||||||||||||||||||||||||||||
| 860 | } | ||||||||||||||||||||||||||||
| 861 | } | ||||||||||||||||||||||||||||
| 862 | 0 | ▶ | if (@rows_nn) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 863 | 0 | ▶ | if ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 864 | 0 | push @rows, [{colspan=>5, $attr=>$code_fmttext->("Zat Nongizi")}]; | |||||||||||||||||||||||||||
| 865 | 0 | for (@{ $rows_nn[-1] }) { $_->{bottom_border} = 1 } | |||||||||||||||||||||||||||
| 866 | } | ||||||||||||||||||||||||||||
| 867 | } | ||||||||||||||||||||||||||||
| 868 | |||||||||||||||||||||||||||||
| 869 | 0 | ▶ | if ($output_format =~ /linear/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 870 | 0 | ▶ | push @rows, join(", ", @rows_vm, @rows_nn), (@rows_vm || @rows_nn ? ". " : ""); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@rows_vm or @rows_nn
MC/DC0%0/2
@rows_vm or @rows_nn
@rows_vm
@rows_nn
Truth table0%0/3
A or B
A= @rows_vmB= @rows_nn
| |||||||||||||||||||||||||||||
| 871 | } else { | ||||||||||||||||||||||||||||
| 872 | 0 | push @rows, @rows_vm, @rows_nn; | |||||||||||||||||||||||||||
| 873 | } | ||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||
| 875 | } # VITAMIN_MINERAL_NONNUTRIENTS | ||||||||||||||||||||||||||||
| 876 | |||||||||||||||||||||||||||||
| 877 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 878 | } elsif ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||||
| 879 | 0 | push @rows, [{colspan=>5, $attr=>$code_fmttext->("/*Persen AKG berdasarkan kebutuhan energi 2150 kkal. Kebutuhan energi Anda mungkin lebih tinggi atau lebih rendah./")}]; | |||||||||||||||||||||||||||
| 880 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 881 | 0 | push @rows, $code_fmttext->( "/Persen AKG berdasarkan kebutuhan energi 2150 kkal. Kebutuhan energi Anda mungkin lebih tinggi atau lebih rendah./"); | |||||||||||||||||||||||||||
| 882 | } | ||||||||||||||||||||||||||||
| 883 | |||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||
| 885 | OUTPUT: | ||||||||||||||||||||||||||||
| 886 | 0 | ▶ | if ($output_format eq 'raw_table') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 887 | 0 | return [200, "OK", \@rows, {'table.fields'=>[qw/name_eng name_ind val_per_100g val_per_srv val_per_srv_R val_per_pkg val_per_pkg_R pct_dv pct_dv_R/]}]; | |||||||||||||||||||||||||||
| 888 | } | ||||||||||||||||||||||||||||
| 889 | |||||||||||||||||||||||||||||
| 890 | 0 | my $text; | |||||||||||||||||||||||||||
| 891 | 0 | ▶ | if ($output_format =~ /vertical/) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 892 | 0 | ▶ | if ($output_format =~ /html/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 893 | 0 | require Text::Table::HTML; | |||||||||||||||||||||||||||
| 894 | 0 | my $table = Text::Table::HTML::table(rows => \@rows, header_row=>0); | |||||||||||||||||||||||||||
| 895 | 0 | $table =~ s!<table>!<table class="$output_format"><colgroup><col style="width:16pt;"><col style="width:200pt;"><col style="width:48pt;"><col style="width:48pt;"><col style="width:36pt;"></colgroup>!; | |||||||||||||||||||||||||||
| 896 | 0 | $text = " | |||||||||||||||||||||||||||
| 897 | <style> | ||||||||||||||||||||||||||||
| 898 | table.$output_format { border-collapse: collapse; border: solid 1pt black; } | ||||||||||||||||||||||||||||
| 899 | table.$output_format tr.has_bottom_border { border-bottom: solid 1pt black; } | ||||||||||||||||||||||||||||
| 900 | </style>\n" . $table; | ||||||||||||||||||||||||||||
| 901 | } else { | ||||||||||||||||||||||||||||
| 902 | 0 | require Text::Table::More; | |||||||||||||||||||||||||||
| 903 | 0 | $text = Text::Table::More::generate_table(rows => \@rows, color=>1, header_row=>0); | |||||||||||||||||||||||||||
| 904 | } | ||||||||||||||||||||||||||||
| 905 | } elsif ($output_format =~ /linear/) { | ||||||||||||||||||||||||||||
| 906 | 0 | ▶ | if ($output_format =~ /html/) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 907 | 0 | $text = " | |||||||||||||||||||||||||||
| 908 | <style> | ||||||||||||||||||||||||||||
| 909 | p.$output_format { border: solid 1pt black; } | ||||||||||||||||||||||||||||
| 910 | </style> | ||||||||||||||||||||||||||||
| 911 | <p class=\"$output_format\">" . join("", @rows). "</p>\n"; | ||||||||||||||||||||||||||||
| 912 | } elsif ($output_format =~ /text/) { | ||||||||||||||||||||||||||||
| 913 | 0 | require Text::ANSI::Util; | |||||||||||||||||||||||||||
| 914 | 0 | require Text::Table::More; | |||||||||||||||||||||||||||
| 915 | 0 | ▶ | my $ing = Text::ANSI::Util::ta_wrap(join("", @rows), $ENV{COLUMNS} // 80); | ||||||||||||||||||||||||||
|
Condition0%0/2
$ENV{"COLUMNS"} // 80
MC/DC0%0/1
$ENV{"COLUMNS"} // 80
$ENV{"COLUMNS"}
Truth table0%0/2
A
A= $ENV{"COLUMNS"}
| |||||||||||||||||||||||||||||
| 916 | 0 | $text = Text::Table::More::generate_table(rows => [[$ing]], header_row=>0); | |||||||||||||||||||||||||||
| 917 | } else { | ||||||||||||||||||||||||||||
| 918 | # raw_linear | ||||||||||||||||||||||||||||
| 919 | 0 | $text = join("", @rows) . "\n"; | |||||||||||||||||||||||||||
| 920 | } | ||||||||||||||||||||||||||||
| 921 | } elsif ($output_format =~ /calculation/) { | ||||||||||||||||||||||||||||
| 922 | 0 | ▶ | if ($output_format =~ /html/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 923 | 0 | require Text::Table::HTML; | |||||||||||||||||||||||||||
| 924 | 0 | my $table = Text::Table::HTML::table(rows => \@rows, header_row=>0); | |||||||||||||||||||||||||||
| 925 | 0 | $table =~ s!<table>!<table class="$output_format">!; | |||||||||||||||||||||||||||
| 926 | 0 | $text = " | |||||||||||||||||||||||||||
| 927 | <style> | ||||||||||||||||||||||||||||
| 928 | table.$output_format { font-size: smaller; border-collapse: collapse; border: solid 1pt black; } | ||||||||||||||||||||||||||||
| 929 | table.$output_format tr.has_bottom_border { border-bottom: solid 1pt black; } | ||||||||||||||||||||||||||||
| 930 | </style>\n" . $table; | ||||||||||||||||||||||||||||
| 931 | } else { | ||||||||||||||||||||||||||||
| 932 | 0 | require Text::Table::More; | |||||||||||||||||||||||||||
| 933 | 0 | $text = Text::Table::More::generate_table(rows => \@rows, color=>1, header_row=>0); | |||||||||||||||||||||||||||
| 934 | } | ||||||||||||||||||||||||||||
| 935 | } | ||||||||||||||||||||||||||||
| 936 | |||||||||||||||||||||||||||||
| 937 | 0 | ▶ | if ($output_format =~ /html/ && $args{browser}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$output_format =~ /html/ and $args{"browser"}
MC/DC0%0/2
$output_format =~ /html/ and $args{"browser"}
$output_format =~ /html/
$args{"browser"}
Truth table0%0/3
A and B
A= $output_format =~ /html/B= $args{"browser"}
| |||||||||||||||||||||||||||||
| 938 | 0 | require Browser::Open; | |||||||||||||||||||||||||||
| 939 | 0 | require File::Slurper; | |||||||||||||||||||||||||||
| 940 | 0 | require File::Temp; | |||||||||||||||||||||||||||
| 941 | |||||||||||||||||||||||||||||
| 942 | 0 | my $tempdir = File::Temp::tempdir(); | |||||||||||||||||||||||||||
| 943 | 0 | my $temppath = "$tempdir/ing.html"; | |||||||||||||||||||||||||||
| 944 | 0 | File::Slurper::write_text($temppath, $text); | |||||||||||||||||||||||||||
| 945 | |||||||||||||||||||||||||||||
| 946 | 0 | my $url = "file:$temppath"; | |||||||||||||||||||||||||||
| 947 | 0 | my $err = Browser::Open::open_browser($url); | |||||||||||||||||||||||||||
| 948 | 0 | ▶ | return [500, "Can't open browser"] if $err; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 949 | 0 | return [200]; | |||||||||||||||||||||||||||
| 950 | } | ||||||||||||||||||||||||||||
| 951 | |||||||||||||||||||||||||||||
| 952 | 0 | return [200, "OK", $text, {'func.raw' => $funcraw, 'cmdline.skip_format'=>1}]; | |||||||||||||||||||||||||||
| 953 | } | ||||||||||||||||||||||||||||
| 954 | |||||||||||||||||||||||||||||
| 955 | 1 | 1; | |||||||||||||||||||||||||||
| 956 | # ABSTRACT: Utilities related to BPOM nutrition facts | ||||||||||||||||||||||||||||
| 957 | |||||||||||||||||||||||||||||
| 958 | __END__ | ||||||||||||||||||||||||||||