Flute/Filter/CountryName.pm untested

filter: Statementstmt 0.0% 0 / 23 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 42 CC 4 SCAR 18.3
CC
4
Cov
0%
filter
12.0
init
6.0
BEGIN
2.0
CRAP 6.2
1 package Template::Flute::Filter::CountryName;
2  
3 use strict;
4 use warnings;
5  
6 use Locales;
7  
8 use base 'Template::Flute::Filter';
9  
10 =head1 NAME
11  
12 Template::Flute::Filter::CountryName - country name filter
13  
14 =head1 DESCRIPTION
15  
16 Country name filter based on L<Locales>.
17  
18 =head1 PREREQUISITES
19  
20 L<Locales> module.
21  
22 =head1 METHODS
23  
24 =head2 init
25  
26 The init method allows you to set the following options:
27  
28 =over 4
29  
30 =item locale
31  
32 Locale for country name output.
33  
34 =item clear_current_locale
35  
36 Whether to return an empty string for the current locale or not.
37  
38 =back
39  
40 =cut
41  
42 sub init {
43 my ($self, %args) = @_;
44  
45 $self->{locale} = $args{options}->{locale} || 'en';
46 $self->{clear_current_locale} = $args{options}->{clear_current_locale};
47  
48 unless ($self->{object} = Locales->new($self->{locale})) {
49 die $@;
50 }
51 }
52  
53 =head2 filter
54  
55 Country name filter.
56  
57 =cut
58  
59 sub filter {
60 my ($self, $code) = @_;
61 my $name = '';
62  
63 if ($code) {
64 unless ($self->{clear_current_locale} && $code eq $self->{locale}) {
65 $name = $self->{object}->get_territory_from_code($code);
66 }
67 }
68
69 return $name;
70 }
71  
72 =head1 AUTHOR
73  
74 Stefan Hornburg (Racke), <racke@linuxia.de>
75  
76 =head1 LICENSE AND COPYRIGHT
77  
78 Copyright 2012-2016 Stefan Hornburg (Racke) <racke@linuxia.de>.
79  
80 This program is free software; you can redistribute it and/or modify it
81 under the terms of either: the GNU General Public License as published
82 by the Free Software Foundation; or the Artistic License.
83  
84 See http://dev.perl.org/licenses/ for more information.
85  
86 =cut
87  
88 1;