Flute/Filter/LanguageName.pm untested

filter: Statementstmt 0.0% 0 / 24 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 / 43 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::LanguageName;
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::LanguageName - language name filter
13  
14 =head1 DESCRIPTION
15  
16 Language 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 language 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 Language name filter.
56  
57 =cut
58  
59 sub filter {
60 my ($self, $code) = @_;
61 my $name = '';
62  
63 if ($code) {
64 # cut off sub locales
65 $code =~ s/_(\w+)$//;
66  
67 unless ($self->{clear_current_locale} && $code eq $self->{locale}) {
68 $name = $self->{object}->get_language_from_code($code);
69 }
70 }
71
72 return $name;
73 }
74  
75 =head1 AUTHOR
76  
77 Stefan Hornburg (Racke), <racke@linuxia.de>
78  
79 =head1 LICENSE AND COPYRIGHT
80  
81 Copyright 2012-2016 Stefan Hornburg (Racke) <racke@linuxia.de>.
82  
83 This program is free software; you can redistribute it and/or modify it
84 under the terms of either: the GNU General Public License as published
85 by the Free Software Foundation; or the Artistic License.
86  
87 See http://dev.perl.org/licenses/ for more information.
88  
89 =cut
90  
91 1;