File Coverage

lib/Petal/TranslationService/MOFile.pm
Criterion Covered Total %
statement 26 30 86.6
branch 5 8 62.5
condition 2 5 40.0
subroutine 6 6 100.0
pod 0 2 0.0
total 39 51 76.4


line stmt bran cond sub pod time code
1             package Petal::TranslationService::MOFile;
2 1     1   19022 use Locale::Maketext::Gettext;
  1         3  
  1         49  
3 1     1   6 use Encode;
  1         12  
  1         65  
4 1     1   10 use strict;
  1         2  
  1         33  
5 1     1   6 use warnings;
  1         4  
  1         346  
6              
7              
8             sub new
9             {
10 4     4 0 2820 my $class = shift;
11 4   33     15 my $file = shift || do {
12             warn "No file specified for " . __PACKAGE__ . "::new (\$file)";
13             return bless {}, $class;
14             };
15              
16 4 50       74 -e $file or do {
17 0         0 warn "$file does not seem to exist";
18 0         0 return bless {}, $class;
19             };
20              
21 4 50       53 -f $file or do {
22 0         0 warn "$file does not seem to be a file";
23 0         0 return bless {}, $class;
24             };
25              
26 4         21 my $self = bless { file => $file }, $class;
27 4         22 $self->{lexicon} = { read_mo ($file) };
28              
29 4         822 ($self->{encoding}) = $self->{lexicon}{""} =~ /^Content-Type: text\/plain; charset=(.*)$/im;
30 4         16 return $self;
31             }
32              
33              
34             sub maketext
35             {
36 10     10 0 373 my $self = shift;
37 10   50     23 my $id = shift || return;
38 10 50       23 $self->{lexicon} || return;
39 10         16 my $res = $self->{lexicon}->{$id};
40              
41 10 100       33 return undef unless defined $res;
42              
43 8         27 return decode($self->{encoding}, $res);
44             }
45              
46              
47             1;
48              
49              
50             __END__