File Coverage

blib/lib/Locale/MakePhrase/BackingStore/Cached.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package Locale::MakePhrase::BackingStore::Cached;
2             our $VERSION = 0.2;
3             our $DEBUG = 0;
4              
5             #
6             # This is just a generic caching in-memory backing store, which does
7             # no translation whatsoever. Its really just a lame example...!
8             #
9             # The returned objects are just the requested languages, used with
10             # the key.
11             #
12              
13 1     1   837 use strict;
  1         1  
  1         29  
14 1     1   4 use warnings;
  1         1  
  1         20  
15 1     1   5 use utf8;
  1         2  
  1         5  
16 1     1   1004 use Memoize;
  1         2478  
  1         46  
17 1     1   6 use base qw(Locale::MakePhrase::BackingStore);
  1         2  
  1         212  
18              
19             #--------------------------------------------------------------------------
20             #
21             sub get_rules {
22             my ($self,$key,$context,$languages) = @_;
23             my @translations;
24             foreach my $language (@$languages) {
25             my $rule = new Locale::MakePhrase::LanguageRule(
26             language => $language,
27             translation => "~[$language~] -> $key",
28             );
29             push @translations, $rule;
30             }
31             print STDERR "Found translations:\n", Dumper(@translations) if $DEBUG;
32             return \@translations;
33             }
34              
35             #--------------------------------------------------------------------------
36             #
37             # Memoize the function, so that it gets faster...
38             #
39             # We should never be calling 'get_translations' in list context as we always
40             # want to return a reference to a list, not an actual list (for efficency).
41             #
42             memoize('get_rules', LIST_CACHE => "FAULT");
43              
44             1;
45             __END__