This repository has been archived on 2023-08-16. You can view files and clone it, but cannot push or open issues or pull requests.
Foodloop-Server/lib/Pear/LocalLoop/Plugin/Currency.pm

30 lines
680 B
Perl
Raw Normal View History

2017-11-15 18:22:49 +00:00
package Pear::LocalLoop::Plugin::Currency;
use Mojo::Base 'Mojolicious::Plugin';
sub register {
2021-03-20 12:09:50 +00:00
my ( $plugin, $app, $cong ) = @_;
2017-11-15 18:22:49 +00:00
2021-03-20 12:09:50 +00:00
$app->helper(
parse_currency => sub {
my ( $c, $currency_string ) = @_;
my $value;
if ( $currency_string =~ /^£([\d.]+)/ ) {
$value = $1 * 1;
}
elsif ( $currency_string =~ /^([\d.]+)/ ) {
$value = $1 * 1;
}
return $value;
}
);
2021-03-20 12:09:50 +00:00
$app->helper(
format_currency_from_db => sub {
my ( $c, $value ) = @_;
return sprintf( '£%.2f', $value / 100000 );
}
);
2017-11-15 18:22:49 +00:00
}
1;