MenuGrinder/Plugin/Localize.pm untested

filter: Statementstmt 0.0% 0 / 27 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 39 CC 2 SCAR 11.5
CC
2
Cov
0%
item_mogrify
6.0
BEGIN
2.0
plugin_required_grinder_methods
2.0
CRAP 3.1
1 package WWW::MenuGrinder::Plugin::Localize;
2 BEGIN {
3 $WWW::MenuGrinder::Plugin::Localize::VERSION = '0.06';
4 }
5  
6 # ABSTRACT: WWW::MenuGrinder plugin for multilingual support
7  
8 use Moose;
9  
10 with 'WWW::MenuGrinder::Role::ItemMogrifier';
11 with 'WWW::MenuGrinder::Role::BeforeMogrify';
12  
13 sub plugin_required_grinder_methods { qw(get_language) }
14  
15 has 'localize_fields' => (
16 is => 'ro',
17 default => sub { [ 'label' ] }
18 );
19  
20 has 'separator' => (
21 is => 'ro',
22 default => '-',
23 );
24  
25 has 'language' => (
26 is => 'rw',
27 );
28  
29 sub before_mogrify {
30 my ($self) = @_;
31  
32 $self->language( $self->grinder->get_language );
33 }
34  
35  
36 sub item_mogrify {
37 my ($self, $item) = @_;
38  
39 my $lang = $self->language;
40 my $separator = $self->separator;
41  
42 for my $field (@{ $self->localize_fields }) {
43
44 if (exists $item->{ "$field$separator$lang" }) {
45 $item->{$field} = $item->{ "$field$separator$lang" };
46 }
47 }
48  
49 return $item;
50 }
51  
52 __PACKAGE__->meta->make_immutable;
53  
54 no Moose;
55 1;
56  
57  
58 __END__