NAME
App::BPOMUtils::NutritionFacts - Utilities related to BPOM nutrition facts
VERSION
This document describes version 0.027 of App::BPOMUtils::NutritionFacts (from Perl distribution App-BPOMUtils-NutritionFacts), released on 2024-06-17.
SYNOPSIS
DESCRIPTION
This distribution includes CLI utilities related to BPOM nutrition facts.
FUNCTIONS
bpom_show_nutrition_facts
Usage:
bpom_show_nutrition_facts(%args) -> [$status_code, $reason, $payload, \%result_meta]
Render BPOM-compliant nutrition fact table (ING - informasi nilai gizi) in various formats.
Examples:
An example, in linear text format (color/emphasis is shown with markup):
bpom_show_nutrition_facts( carbohydrate => 13.113, color => "never", fat => 0.223, output_format => "raw_linear", package_size => 20, protein => 0.99, saturated_fat => 0.01, serving_size => 175, sodium => 0.223, sugar => 7.173 );
Result:
[ 200, "OK", "*INFORMASI NILAI GIZI* *JUMLAH PER KEMASAN (20 g)* : *Energi total 10 kkal*, Energi dari lemak 0 kkal, Energi dari lemak jenuh 0 kkal, *Lemak total 0 g (0% AKG)*, *Lemak jenuh 0 g (0% AKG)*, *Protein 0 g (0% AKG)*, *Karbohidrat total 3 g (1% AKG)*, *Gula 1 g*, *Garam (Natrium) 0 mg (0% AKG)*. /Persen AKG berdasarkan kebutuhan energi 2150 kkal. Kebutuhan energi Anda mungkin lebih tinggi atau lebih rendah./\n", { "cmdline.skip_format" => 1, "func.raw" => { carbohydrate_per_pkg => 2.6226, carbohydrate_per_pkg_rounded => 3, energy_from_fat_per_pkg => 3.51225, energy_from_fat_per_pkg_rounded => 0, energy_from_saturated_fat_per_pkg => 0.018, energy_from_saturated_fat_per_pkg_rounded => 0, per_package_ing => 1, protein_per_pkg => 0.198, protein_per_pkg_rounded => 0, saturated_fat_per_pkg => 0.002, saturated_fat_per_pkg_rounded => 0, sodium_per_pkg => 0.0446, sodium_per_pkg_rounded => 0, total_energy_pct_dv => 0.543432558139535, total_energy_pct_dv_rounded => 1, total_energy_per_pkg => 11.6838, total_energy_per_pkg_rounded => 10, total_fat_per_pkg => 0.0446, total_fat_per_pkg_rounded => 0, total_sugar_per_pkg => 1.4346, total_sugar_per_pkg_rounded => 1, }, }, ]
An example, in raw_linear format (just like linear_text but with no border):
bpom_show_nutrition_facts( carbohydrate => 13.113, color => "never", fat => 0.223, output_format => "linear_text", package_size => 20, protein => 0.99, saturated_fat => 0.01, serving_size => 175, sodium => 0.223, sugar => 7.173 );
Result:
[ 200, "OK", ".---------------------------------------------------------------------------------.\n| *INFORMASI NILAI GIZI* *JUMLAH PER KEMASAN (20 g)* : *Energi total 10 kkal*, |\n| Energi dari lemak 0 kkal, Energi dari lemak jenuh 0 kkal, *Lemak total 0 g (0% |\n| AKG)*, *Lemak jenuh 0 g (0% AKG)*, *Protein 0 g (0% AKG)*, *Karbohidrat total 3 |\n| g (1% AKG)*, *Gula 1 g*, *Garam (Natrium) 0 mg (0% AKG)*. /Persen AKG |\n| berdasarkan kebutuhan energi 2150 kkal. Kebutuhan energi Anda mungkin lebih |\n| tinggi atau lebih rendah./ |\n`---------------------------------------------------------------------------------'\n", { "cmdline.skip_format" => 1, "func.raw" => { carbohydrate_per_pkg => 2.6226, carbohydrate_per_pkg_rounded => 3, energy_from_fat_per_pkg => 3.51225, energy_from_fat_per_pkg_rounded => 0, energy_from_saturated_fat_per_pkg => 0.018, energy_from_saturated_fat_per_pkg_rounded => 0, per_package_ing => 1, protein_per_pkg => 0.198, protein_per_pkg_rounded => 0, saturated_fat_per_pkg => 0.002, saturated_fat_per_pkg_rounded => 0, sodium_per_pkg => 0.0446, sodium_per_pkg_rounded => 0, total_energy_pct_dv => 0.543432558139535, total_energy_pct_dv_rounded => 1, total_energy_per_pkg => 11.6838, total_energy_per_pkg_rounded => 10, total_fat_per_pkg => 0.0446, total_fat_per_pkg_rounded => 0, total_sugar_per_pkg => 1.4346, total_sugar_per_pkg_rounded => 1, }, }, ]
The same example in vertical HTML table format:
bpom_show_nutrition_facts( carbohydrate => 13.113, fat => 0.223, output_format => "vertical_html_table", package_size => 20, protein => 0.99, saturated_fat => 0.01, serving_size => 175, sodium => 0.223, sugar => 7.173 );
Result:
[ 200, "OK", "\n<style>\n table.vertical_html_table { border-collapse: collapse; border: solid 1pt black; }\n table.vertical_html_table tr.has_bottom_border { border-bottom: solid 1pt black; }\n</style>\n<table class=\"vertical_html_table\"><colgroup><col style=\"width:16pt;\"><col style=\"width:200pt;\"><col style=\"width:48pt;\"><col style=\"width:48pt;\"><col style=\"width:36pt;\"></colgroup>\n<tbody>\n<tr><td colspan=5 align=\"middle\"><b>INFORMASI NILAI GIZI</b></td></tr>\n<tr><td colspan=5></td></tr>\n<tr><td colspan=5 align=\"left\"><b>JUMLAH PER KEMASAN (20 g)</b></td></tr>\n<tr class=has_bottom_border><td colspan=5><b>Energi total 10 kkal</b></td></tr>\n<tr><td colspan=3></td><td colspan=2 align=\"middle\"><b>% AKG</b>*</td></tr>\n<tr><td colspan=2><b>Lemak total</b></td><td align=\"right\"><b>0 g</b></td><td align=\"right\">0 %</td><td></td></tr>\n<tr><td colspan=2><b>Lemak jenuh</b></td><td align=\"right\"><b>0 g</b></td><td align=\"right\">0 %</td><td></td></tr>\n<tr><td colspan=2><b>Protein</b></td><td align=\"right\"><b>0 g</b></td><td align=\"right\">0 %</td><td></td></tr>\n<tr><td colspan=2><b>Karbohidrat total</b></td><td align=\"right\"><b>3 g</b></td><td align=\"right\">1 %</td><td></td></tr>\n<tr><td colspan=2><b>Gula</b></td><td align=\"right\"><b>1 g</b></td><td></td><td></td></tr>\n<tr class=has_bottom_border><td colspan=2><b>Garam (Natrium)</b></td><td align=\"right\"><b>0 mg</b></td><td align=\"right\">0 %</td><td></td></tr>\n<tr><td colspan=5><i>*Persen AKG berdasarkan kebutuhan energi 2150 kkal. Kebutuhan energi Anda mungkin lebih tinggi atau lebih rendah.</i></td></tr>\n</tbody>\n</table>\n", { "cmdline.skip_format" => 1, "func.raw" => { carbohydrate_per_pkg => 2.6226, carbohydrate_per_pkg_rounded => 3, energy_from_fat_per_pkg => 3.51225, energy_from_fat_per_pkg_rounded => 0, energy_from_saturated_fat_per_pkg => 0.018, energy_from_saturated_fat_per_pkg_rounded => 0, per_package_ing => 1, protein_per_pkg => 0.198, protein_per_pkg_rounded => 0, saturated_fat_per_pkg => 0.002, saturated_fat_per_pkg_rounded => 0, sodium_per_pkg => 0.0446, sodium_per_pkg_rounded => 0, total_energy_pct_dv => 0.543432558139535, total_energy_pct_dv_rounded => 1, total_energy_per_pkg => 11.6838, total_energy_per_pkg_rounded => 10, total_fat_per_pkg => 0.0446, total_fat_per_pkg_rounded => 0, total_sugar_per_pkg => 1.4346, total_sugar_per_pkg_rounded => 1, }, }, ]
The same example, in vertical text format (color/emphasis is shown with markup):
bpom_show_nutrition_facts( carbohydrate => 13.113, color => "never", fat => 0.223, output_format => "vertical_text_table", package_size => 20, protein => 0.99, saturated_fat => 0.01, serving_size => 175, sodium => 0.223, sugar => 7.173 );
Result:
[ 200, "OK", ".---------------------------------------------------------------------------------------------------------------------.\n| *INFORMASI NILAI GIZI* |\n| |\n| *JUMLAH PER KEMASAN (20 g)* |\n| *Energi total 10 kkal* |\n+-----------------------|----------------------|-----------------------+----------------------|-----------------------+\n| | *% AKG** |\n| *Lemak total* | *0 g* | 0 % | |\n| *Lemak jenuh* | *0 g* | 0 % | |\n| *Protein* | *0 g* | 0 % | |\n| *Karbohidrat total* | *3 g* | 1 % | |\n| *Gula* | *1 g* | | |\n| *Garam (Natrium)* | *0 mg* | 0 % | |\n+-----------------------|----------------------+-----------------------+----------------------+-----------------------+\n| /*Persen AKG berdasarkan kebutuhan energi 2150 kkal. Kebutuhan energi Anda mungkin lebih tinggi atau lebih rendah./ |\n`---------------------------------------------------------------------------------------------------------------------'\n", { "cmdline.skip_format" => 1, "func.raw" => { carbohydrate_per_pkg => 2.6226, carbohydrate_per_pkg_rounded => 3, energy_from_fat_per_pkg => 3.51225, energy_from_fat_per_pkg_rounded => 0, energy_from_saturated_fat_per_pkg => 0.018, energy_from_saturated_fat_per_pkg_rounded => 0, per_package_ing => 1, protein_per_pkg => 0.198, protein_per_pkg_rounded => 0, saturated_fat_per_pkg => 0.002, saturated_fat_per_pkg_rounded => 0, sodium_per_pkg => 0.0446, sodium_per_pkg_rounded => 0, total_energy_pct_dv => 0.543432558139535, total_energy_pct_dv_rounded => 1, total_energy_per_pkg => 11.6838, total_energy_per_pkg_rounded => 10, total_fat_per_pkg => 0.0446, total_fat_per_pkg_rounded => 0, total_sugar_per_pkg => 1.4346, total_sugar_per_pkg_rounded => 1, }, }, ]
The same example, in calculation text format:
bpom_show_nutrition_facts( carbohydrate => 13.113, color => "never", fat => 0.223, output_format => "calculation_text", package_size => 20, protein => 0.99, saturated_fat => 0.01, serving_size => 175, sodium => 0.223, sugar => 7.173 );
Result:
[ 200, "OK", ".-------------------------------------------------------------------------------------------------------------------------------------------------------------------------.\n| *PERHITUNGAN INFORMASI NILAI GIZI* |\n| *Energi total* |\n| Energi total per 100 g | = lemak \xD7 9 + protein \xD7 4 + karbohidrat \xD7 4 = 0.223 \xD7 9 + 0.99 \xD7 4 + 13.113 \xD7 4 = 58.419 kkal |\n| Energi total per kemasan 20 g | = 58.419 \xD7 20 / 100 = 11.6838 kkal |\n| (dibulatkan: <5 -> 0, <=50 -> 5 kkal terdekat, >50 -> 10 kkal terdekat) | = *10* kkal |\n| | |\n| *%AKG energi total* |\n| %AKG | = 11.6838 / 2150 \xD7 100 = 0.543432558139535 |\n| (dibulatkan ke % terdekat) | = *1* |\n| *Energi dari lemak* |\n| Energi dari lemak per 100 g | = lemak \xD7 9 = 0.223 \xD7 9 = 2.007 kkal |\n| Energi dari lemak per kemasan 20 g | = 2.007 \xD7 20 / 100 = 3.51225 kkal |\n| (dibulatkan: <5 -> 0, <=50 -> 5 kkal terdekat, >50 -> 10 kkal terdekat) | = *0* kkal |\n| *Energi dari lemak jenuh* |\n| Energi dari lemak per 100 g | = lemak jenuh \xD7 9 = 0.01 \xD7 9 = 0.09 kkal |\n| Energi dari lemak jenuh per kemasan 20 g | = 0.09 \xD7 20 / 100 = 0.018 kkal |\n| (dibulatkan: <5 -> 0, <=50 -> 5 kkal terdekat, >50 -> 10 kkal terdekat) | = *0* kkal |\n| *Lemak total* |\n| Lemak total per 100 g | = 0.223 g |\n| Lemak total per kemasan 20 g | = 0.223 \xD7 20 / 100 = 0.0446 g |\n| (dibulatkan: <0.5 -> 0, <=5 -> 0.5 g terdekat, >=5 -> 1 g terdekat) | = *0* g |\n| | |\n| *%AKG lemak total* |\n| %AKG | = 0.0446 / 67 \xD7 100 = 0.0665671641791045 |\n| (dibulatkan ke % terdekat) | = *0* |\n| *Lemak jenuh* |\n| Lemak jenuh per 100 g | = 0.01 g |\n| Lemak jenuh per kemasan 20 g | = 0.01 \xD7 20 / 100 = 0.002 g |\n| (dibulatkan: <0.5 -> 0, <=5 -> 0.5 g terdekat, >=5 -> 1 g terdekat) | = *0* g |\n| | |\n| *%AKG lemak jenuh* |\n| %AKG | = 0.002 / 67 \xD7 100 = 0.01 |\n| (dibulatkan ke % terdekat) | = *0* |\n| *Protein* |\n| Protein per 100 g | = 0.99 g |\n| Protein total per kemasan 20 g | = 0.99 \xD7 20 / 100 = 0.198 g |\n| (dibulatkan: <0.5 -> 0, >=0.5 -> 1 g terdekat) | = *0* g |\n| | |\n| *%AKG protein* |\n| %AKG | = 0.198 / 60 \xD7 100 = 0.33 |\n| (dibulatkan ke % terdekat) | = *0* |\n| *Karbohidrat total* |\n| Karbohidrat total per 100 g | = 13.113 g |\n| Karbohidrat total per kemasan 20 g | = 13.113 \xD7 20 / 100 = 2.6226 g |\n| (dibulatkan: <0.5 -> 0, >=0.5 -> 1 g terdekat) | = *3* g |\n| | |\n| *%AKG karbohidrat total* |\n| %AKG | = 2.6226 / 325 \xD7 100 = 0.0665671641791045 |\n| (dibulatkan ke % terdekat) | = *1* |\n| *Gula* |\n| Gula per 100 g | = 7.173 g |\n| Gula per kemasan 20 g | = 7.173 \xD7 20 / 100 = 1.4346 g |\n| (dibulatkan: <0.5 -> 0, >=0.5 -> 1 g terdekat) | = *1* g |\n| *Natrium* |\n| Natrium per 100 g | = 0.223 mg |\n| Natrium per kemasan 20 g | = 0.223 \xD7 20 / 100 = 0.0446 mg |\n| (dibulatkan: <5 -> 0, <=140 -> 5 mg terdekat, >140 -> 10 mg terdekat) | = *0* mg |\n| | |\n| *%AKG natrium* |\n| %AKG | = 0.0446 / 1500 \xD7 100 = 0.00297333333333333 |\n| (dibulatkan ke % terdekat) | = *0* |\n`-------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------'\n", { "cmdline.skip_format" => 1, "func.raw" => { carbohydrate_per_pkg => 2.6226, carbohydrate_per_pkg_rounded => 3, energy_from_fat_per_pkg => 3.51225, energy_from_fat_per_pkg_rounded => 0, energy_from_saturated_fat_per_pkg => 0.018, energy_from_saturated_fat_per_pkg_rounded => 0, per_package_ing => 1, protein_per_pkg => 0.198, protein_per_pkg_rounded => 0, saturated_fat_per_pkg => 0.002, saturated_fat_per_pkg_rounded => 0, sodium_per_pkg => 0.0446, sodium_per_pkg_rounded => 0, total_energy_pct_dv => 0.543432558139535, total_energy_pct_dv_rounded => 1, total_energy_per_pkg => 11.6838, total_energy_per_pkg_rounded => 10, total_fat_per_pkg => 0.0446, total_fat_per_pkg_rounded => 0, total_sugar_per_pkg => 1.4346, total_sugar_per_pkg_rounded => 1, }, }, ]
This function is not exported by default, but exportable.
Arguments ('*' denotes required arguments):
biotin => ufloat
Biotin, in mcg/100g.
browser => true
View output HTML in browser instead of returning it.
ca => ufloat
Calcium, in mg/100g.
carbohydrate* => ufloat
Total carbohydrate, in g/100g.
cholesterol => ufloat
Cholesterol, in mg/100g.
choline => ufloat
Choline, in mg/100g.
color => str (default: "auto")
(No description)
cr => ufloat
Chromium, in mcg/100g.
cu => ufloat
Copper, in mcg/100g.
fat* => ufloat
Total fat, in g/100g.
fe => ufloat
Iron, in mg/100g.
fluorine => ufloat
Fluorine, in mg/100g.
folate => ufloat
Folate (vitamin B9), in mcg/100g.
iodium => ufloat
Iodium, in mcg/100g.
k => ufloat
Potassium, in mg/100g.
mg => ufloat
Magnesium, in mg/100g.
mn => ufloat
Manganese, in mcg/100g.
name => str
(No description)
output_format => str (default: "vertical_text_table")
Pick an output format for the nutrition fact.
vertical_text_table
is the default. The /(vertical)?.*table/ formats presents the information in a table, while the /linear/ formats presents the information in a paragraph.package_size* => ufloat
Packaging size, in g.
phosphorus => ufloat
Phosphorus, in mg/100g.
protein* => ufloat
Protein, in g/100g.
saturated_fat* => ufloat
Saturated fat, in g/100g.
se => ufloat
Selenium, in mcg/100g.
serving_size* => ufloat
Serving size, in g.
sodium* => ufloat
Sodium, in mg/100g.
sugar* => ufloat
Total sugar, in g/100g.
va => ufloat
Vitamin A, in mcg/100g (all-trans-)retinol.
vb1 => ufloat
Vitamin B1, in mg/100g.
vb12 => ufloat
Vitamin B12, in mcg/100g.
vb2 => ufloat
Vitamin B2, in mg/100g.
vb3 => ufloat
Vitamin B3, in mg/100g.
vb5 => ufloat
Vitamin B5 (pantothenic acid), in mg/100g.
vb6 => ufloat
Vitamin B6, in mg/100g.
vc => ufloat
Vitamin C, in mg/100g.
vd => ufloat
Vitamin D, in mcg.
ve => ufloat
Vitamin E, in mg alpha-TE (tocopherol-equivalent).
vk => ufloat
Vitamin K, in mcg.
zn => ufloat
Zinc, in mg/100g.
Returns an enveloped result (an array).
First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata.
Return value: (any)
HOMEPAGE
Please visit the project's homepage at https://metacpan.org/release/App-BPOMUtils-NutritionFacts.
SOURCE
Source repository is at https://github.com/perlancar/perl-App-BPOMUtils-NutritionFacts.
SEE ALSO
Other App::BPOMUtils::*
distributions.
AUTHOR
perlancar <perlancar@cpan.org>
CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on GitHub.
Most of the time, you don't need to build the distribution yourself. You can simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your system), you can install Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, Pod::Weaver::PluginBundle::Author::PERLANCAR, and sometimes one or two other Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond that are considered a bug and can be reported to me.
COPYRIGHT AND LICENSE
This software is copyright (c) 2024, 2023, 2022 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
BUGS
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=App-BPOMUtils-NutritionFacts
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.