| 1 | package WebEditor::OldController::Msg; | ||||||||||||
| 2 | |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use vars qw($VERSION); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/); | |||||||||||
| 6 | |||||||||||||
| 7 | 1 | ▶ | use base 'Class::Accessor'; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 1 | __PACKAGE__->mk_accessors(qw(C EditorLang Messages)); | |||||||||||
| 10 | |||||||||||||
| 11 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 12 | 0 | my($class, $c, $lang) = @_; | |||||||||||
| 13 | 0 | ▶ | my $self = { C => $c, | ||||||||||
|
Condition0%0/2
$lang || 'en'
MC/DC0%0/1
$lang || 'en'
$lang
Truth table0%0/2
A
A= $lang
| |||||||||||||
| 14 | EditorLang => $lang||"en", # named EditorLang for OldController.pm compat | ||||||||||||
| 15 | Messages => {}, | ||||||||||||
| 16 | }; | ||||||||||||
| 17 | 0 | bless $self, $class; | |||||||||||
| 18 | } | ||||||||||||
| 19 | |||||||||||||
| 20 | 0 | ▶ | sub msg { | ||||||||||
|
Subroutine
msg: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||
| 21 | 0 | my($self, $key) = @_; | |||||||||||
| 22 | 0 | my $stash = $self->Messages->{$self->EditorLang}; | |||||||||||
| 23 | 0 | ▶ | if (!$stash) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 24 | 0 | my $c = $self->C; | |||||||||||
| 25 | 0 | my @try_langs = ($self->EditorLang); | |||||||||||
| 26 | 0 | ▶ | push @try_langs, "en" if $self->EditorLang ne "en"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 27 | 0 | for my $lang (@try_langs) { | |||||||||||
| 28 | 0 | my $langres_file = $c->paths->we_templatebase . "/langres_$lang"; | |||||||||||
| 29 | 0 | ▶ | if (-r $langres_file) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | last if $stash; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | } | ||||||||||||
| 36 | } | ||||||||||||
| 37 | 0 | ▶ | if (!$stash) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 38 | 0 | return "[[$key]]"; | |||||||||||
| 39 | } | ||||||||||||
| 40 | 0 | $self->Messages->{$self->EditorLang} = $stash; | |||||||||||
| 41 | } | ||||||||||||
| 42 | 0 | my $val = $stash->get($key); | |||||||||||
| 43 | 0 | ▶ | if (!defined $val) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 44 | 0 | "[[$key]]"; | |||||||||||
| 45 | } else { | ||||||||||||
| 46 | 0 | $val; | |||||||||||
| 47 | } | ||||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | 0 | ▶ | sub fmt_msg { | ||||||||||
|
Subroutine
fmt_msg: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 51 | 0 | my($self, $key, @arg) = @_; | |||||||||||
| 52 | 0 | sprintf $self->msg($key), @arg; | |||||||||||
| 53 | } | ||||||||||||
| 54 | |||||||||||||
| 55 | 1 | 1; | |||||||||||