blib/lib/ClearPress/Localize.pm

filter: Statementstmt 60.5% 23 / 38 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 70.0% 7 / 10 Podpod 100% 3 / 3 totaltotal 55.0% 33 / 60 CC 4 SCAR 14.8
CC
4
Cov
51%
localizer
12.0
lang
6.0
__ANON__
2.0
CRAP 4.4
« blib/lib/ClearPress/util.pm ↑ Summary blib/lib/ClearPress/authenticator/passwd.pm »
1 #!/usr/bin/env perl
2 # -*- mode: cperl; tab-width: 8; indent-tabs-mode: nil; basic-offset: 2 -*-
3 # vim:ts=8:sw=2:et:sta:sts=2
4 #########
5 # Author: rmp
6 #
7 package ClearPress::Localize;
8 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 7 ▶use base qw(Locale::Maketext);
Subroutine BEGIN: called CC=1 SCAR=0.0
11 7 ▶use HTTP::ClientDetect::Language;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 7 ▶use Locale::Maketext::Lexicon {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 7 _auto => 1,
14 _style => 'gettext',
15 7 };
16 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 7 our $VERSION = q[2026.07.25];
19  
20 83 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
21 83 my ($class, $locales) = @_;
22 83 Locale::Maketext::Lexicon->import($locales);
23 83 return 1;
24 }
25  
26 0 ▶sub lang {
Subroutine lang: not called CC=2 SCAR=17.9
Pod documented
27 0 my $lang_detect = HTTP::ClientDetect::Language->new(server_default => 'en_GB');
28 my $req = {
29 accept_language => $ENV{HTTP_ACCEPT_LANGUAGE},
30 0 };
31  
32 0 my $sym = \%ClearPress::request::;
33 0 ▶ if(!exists $sym->{accept_language}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $sym->{"accept_language"}) 0 0 0
34 0 ▶ *ClearPress::request::accept_language = sub { my $self = shift; return $self->{accept_language}; };
Subroutine __ANON__: not called CC=1 SCAR=6.9
35 }
36  
37 0 bless $req, 'ClearPress::request';
38 0 my $lang = $lang_detect->language($req);
39  
40 # if($lang) {
41 # carp qq[Detected $lang from $ENV{HTTP_ACCEPT_LANGUAGE}];
42 # }
43 0 return $lang;
44 }
45  
46 0 ▶sub localizer {
Subroutine localizer: not called CC=3 SCAR=24.8
Pod documented
47 0 my ($class, $lang) = @_;
48  
49 0 ▶ my $lh = __PACKAGE__->get_handle($lang || __PACKAGE__->lang());
Condition0%0/3
$lang || __PACKAGE__->lang
l!l&&r!l&&!r
000
MC/DC0%0/2
$lang || __PACKAGE__->lang
$lang __PACKAGE__->lang
Truth table0%0/3
A || B
A= $langB= __PACKAGE__->lang
ABresult
1X1
011
000
50 0 ▶ if(!$lh) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($lh) 0 0 0
51 0 carp qq[Could not construct localizer for $lang];
52 }
53 0 return $lh;
54 }
55  
56 7 1;
57 __END__
« blib/lib/ClearPress/util.pm ↑ Summary blib/lib/ClearPress/authenticator/passwd.pm »