File Coverage

blib/lib/Lingua/YaTeA/MessageSet.pm
Criterion Covered Total %
statement 36 37 97.3
branch 3 4 75.0
condition n/a
subroutine 9 9 100.0
pod 5 5 100.0
total 53 55 96.3


line stmt bran cond sub pod time code
1             package Lingua::YaTeA::MessageSet;
2 5     5   27 use strict;
  5         7  
  5         115  
3 5     5   21 use warnings;
  5         10  
  5         94  
4              
5 5     5   1677 use Lingua::YaTeA::Message;
  5         11  
  5         44  
6 5     5   108 use Data::Dumper;
  5         8  
  5         1682  
7              
8             our $VERSION=$Lingua::YaTeA::VERSION;
9              
10             sub new
11             {
12 4     4 1 12 my ($class,$file,$language) = @_;
13 4         8 my $this = {};
14 4         8 bless ($this,$class);
15 4         63 $this->{MESSAGES} = {};
16 4         17 $this->loadMessages($file,$language);
17 4         160 return $this;
18             }
19              
20             sub loadMessages
21             {
22 4     4 1 11 my ($this,$file,$language) = @_;
23 4         11 my $path = $file->getPath;
24 4         28 my $fh = FileHandle->new("<$path");
25 4         322 my $line;
26 4         8 my $line_counter = 0;
27 4         7 my $message;
28             my $option;
29            
30            
31 4         110 while ($line= $fh->getline)
32             {
33 312         5811 $line_counter++;
34 312 100       946 if ($line =~ /^([^\s]+) = \"(.+)\"\s*$/)
35             {
36 300         639 $message = Lingua::YaTeA::Message->new($1,$2,$language);
37 300         510 $this->addMessage($message);
38             }
39             else
40             {
41 12 50       200 if($line !~ /^\s*$/)
42             {
43 0         0 die "ill-formed message in file:" .$file->getPath . " line " . $line_counter . "\n";
44             }
45             }
46             }
47             }
48              
49             sub addMessage
50             {
51 300     300 1 393 my ($this,$message) = @_;
52 300         470 $this->{MESSAGES}->{$message->getName} = $message;
53             }
54              
55              
56             sub getMessage
57             {
58 55     55 1 122 my ($this,$name) = @_;
59 55         133 return $this->getMessages->{$name};
60             }
61              
62             sub getMessages
63             {
64 55     55 1 84 my ($this) = @_;
65 55         236 return $this->{MESSAGES};
66             }
67             1;
68              
69             __END__