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   14517 use Locale::Maketext::Gettext;
  1         1  
  1         40  
3 1     1   4 use Encode;
  1         1  
  1         57  
4 1     1   4 use strict;
  1         1  
  1         15  
5 1     1   3 use warnings;
  1         2  
  1         241  
6              
7              
8             sub new
9             {
10 4     4 0 2517 my $class = shift;
11 4   33     11 my $file = shift || do {
12             warn "No file specified for " . __PACKAGE__ . "::new (\$file)";
13             return bless {}, $class;
14             };
15              
16 4 50       81 -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       28 -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         13 my $self = bless { file => $file }, $class;
27 4         16 $self->{lexicon} = { read_mo ($file) };
28              
29 4         536 ($self->{encoding}) = $self->{lexicon}{""} =~ /^Content-Type: text\/plain; charset=(.*)$/im;
30 4         11 return $self;
31             }
32              
33              
34             sub maketext
35             {
36 10     10 0 400 my $self = shift;
37 10   50     19 my $id = shift || return;
38 10 50       20 $self->{lexicon} || return;
39 10         12 my $res = $self->{lexicon}->{$id};
40              
41 10 100       24 return undef unless defined $res;
42              
43 8         24 return decode($self->{encoding}, $res);
44             }
45              
46              
47             1;
48              
49              
50             __END__