| 1 | package Template::Flute::Filter::Currency; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use warnings; | ||
| 5 | |||
| 6 | use Number::Format; | ||
| 7 | |||
| 8 | use base 'Template::Flute::Filter'; | ||
| 9 | |||
| 10 | =head1 NAME | ||
| 11 | |||
| 12 | Template::Flute::Filter::Currency - Currency filter for prices | ||
| 13 | |||
| 14 | =head1 DESCRIPTION | ||
| 15 | |||
| 16 | Filters prices to be displayed according to the locale and | ||
| 17 | displayed with a currency symbol. | ||
| 18 | |||
| 19 | This filter is based on L<Number::Format>. Any options are | ||
| 20 | passed through to the L<Number::Format> object. | ||
| 21 | |||
| 22 | =head1 PREREQUISITES | ||
| 23 | |||
| 24 | L<Number::Format> module. | ||
| 25 | |||
| 26 | =head1 METHODS | ||
| 27 | |||
| 28 | =head2 init | ||
| 29 | |||
| 30 | =cut | ||
| 31 | |||
| 32 | sub init { | ||
| 33 | my ($self, %args) = @_; | ||
| 34 | |||
| 35 | $self->{format} = Number::Format->new(%{$args{options} || {}}); | ||
| 36 | } | ||
| 37 | |||
| 38 | =head2 filter | ||
| 39 | |||
| 40 | Currency filter. | ||
| 41 | |||
| 42 | =cut | ||
| 43 | |||
| 44 | sub filter { | ||
| 45 | my ($self, $amount) = @_; | ||
| 46 | |||
| 47 | return $self->{format}->format_price($amount); | ||
| 48 | } | ||
| 49 | |||
| 50 | |||
| 51 | =head1 AUTHOR | ||
| 52 | |||
| 53 | Stefan Hornburg (Racke), <racke@linuxia.de> | ||
| 54 | |||
| 55 | =head1 LICENSE AND COPYRIGHT | ||
| 56 | |||
| 57 | Copyright 2011-2016 Stefan Hornburg (Racke) <racke@linuxia.de>. | ||
| 58 | |||
| 59 | This program is free software; you can redistribute it and/or modify it | ||
| 60 | under the terms of either: the GNU General Public License as published | ||
| 61 | by the Free Software Foundation; or the Artistic License. | ||
| 62 | |||
| 63 | See http://dev.perl.org/licenses/ for more information. | ||
| 64 | |||
| 65 | =cut | ||
| 66 | |||
| 67 | 1; |