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   32 use strict;
  5         10  
  5         147  
3 5     5   27 use warnings;
  5         10  
  5         117  
4              
5 5     5   1987 use Lingua::YaTeA::Message;
  5         16  
  5         56  
6 5     5   132 use Data::Dumper;
  5         9  
  5         2044  
7              
8             our $VERSION=$Lingua::YaTeA::VERSION;
9              
10             sub new
11             {
12 4     4 1 13 my ($class,$file,$language) = @_;
13 4         12 my $this = {};
14 4         9 bless ($this,$class);
15 4         25 $this->{MESSAGES} = {};
16 4         18 $this->loadMessages($file,$language);
17 4         193 return $this;
18             }
19              
20             sub loadMessages
21             {
22 4     4 1 14 my ($this,$file,$language) = @_;
23 4         13 my $path = $file->getPath;
24 4         39 my $fh = FileHandle->new("<$path");
25 4         351 my $line;
26 4         13 my $line_counter = 0;
27 4         10 my $message;
28             my $option;
29            
30            
31 4         142 while ($line= $fh->getline)
32             {
33 312         7062 $line_counter++;
34 312 100       1191 if ($line =~ /^([^\s]+) = \"(.+)\"\s*$/)
35             {
36 300         780 $message = Lingua::YaTeA::Message->new($1,$2,$language);
37 300         617 $this->addMessage($message);
38             }
39             else
40             {
41 12 50       226 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 463 my ($this,$message) = @_;
52 300         631 $this->{MESSAGES}->{$message->getName} = $message;
53             }
54              
55              
56             sub getMessage
57             {
58 55     55 1 167 my ($this,$name) = @_;
59 55         164 return $this->getMessages->{$name};
60             }
61              
62             sub getMessages
63             {
64 55     55 1 137 my ($this) = @_;
65 55         330 return $this->{MESSAGES};
66             }
67             1;
68              
69             __END__