File Coverage

blib/lib/WebEditor/OldController/Msg.pm
Criterion Covered Total %
statement 9 35 25.7
branch 0 12 0.0
condition 0 2 0.0
subroutine 3 6 50.0
pod 1 3 33.3
total 13 58 22.4


line stmt bran cond sub pod time code
1             package WebEditor::OldController::Msg;
2              
3 1     1   1160 use strict;
  1         2  
  1         33  
4 1     1   6 use vars qw($VERSION);
  1         2  
  1         60  
5             $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
6              
7 1     1   5 use base 'Class::Accessor';
  1         2  
  1         394  
8              
9             __PACKAGE__->mk_accessors(qw(C EditorLang Messages));
10              
11             sub new {
12 0     0 1   my($class, $c, $lang) = @_;
13 0   0       my $self = { C => $c,
14             EditorLang => $lang||"en", # named EditorLang for OldController.pm compat
15             Messages => {},
16             };
17 0           bless $self, $class;
18             }
19              
20             sub msg {
21 0     0 0   my($self, $key) = @_;
22 0           my $stash = $self->Messages->{$self->EditorLang};
23 0 0         if (!$stash) {
24 0           my $c = $self->C;
25 0           my @try_langs = ($self->EditorLang);
26 0 0         push @try_langs, "en" if $self->EditorLang ne "en";
27 0           for my $lang (@try_langs) {
28 0           my $langres_file = $c->paths->we_templatebase . "/langres_$lang";
29 0 0         if (-r $langres_file) {
30 0           require Template::Context;
31 0           my $ctx = Template::Context->new({ ABSOLUTE => 1});
32 0           $ctx->process($langres_file);
33 0           $stash = $ctx->stash;
34 0 0         last if $stash;
35             }
36             }
37 0 0         if (!$stash) {
38 0           return "[[$key]]";
39             }
40 0           $self->Messages->{$self->EditorLang} = $stash;
41             }
42 0           my $val = $stash->get($key);
43 0 0         if (!defined $val) {
44 0           "[[$key]]";
45             } else {
46 0           $val;
47             }
48             }
49              
50             sub fmt_msg {
51 0     0 0   my($self, $key, @arg) = @_;
52 0           sprintf $self->msg($key), @arg;
53             }
54              
55             1;