Acme/MetaSyntactic/Locale.pm

filter: Statementstmt 100% 53 / 53 Branchbran 91.6% 11 / 12 Conditioncond 86.3% 19 / 22 MC/DCmcdc 66.6% 8 / 12 Subroutinesub 100% 10 / 10 Podpod 100% 2 / 2 totaltotal 92.7% 103 / 111 CC 15 SCAR 22.8
CC
15
Cov
95%
new
15.1
BEGIN
1.0
BEGIN
1.0
CRAP 9.8
« Test/MetaSyntactic.pm ↑ Summary Acme/MetaSyntactic/RemoteList.pm »
1 package Acme::MetaSyntactic::Locale;
2 24 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 24 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 24 ▶use Acme::MetaSyntactic (); # do not export metaname and friends
Subroutine BEGIN: called CC=1 SCAR=0.0
5 24 ▶use Acme::MetaSyntactic::MultiList;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 24 ▶use List::Util qw( shuffle );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 24 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 24 our @ISA = qw( Acme::MetaSyntactic::MultiList );
10 24 our $VERSION = '1.000';
11  
12 sub init {
13 # alias the older package variable %Locale to %MultiList
14 24 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 23 ▶ *{"$_[0]::Locale"} = \%{"$_[0]::MultiList"};
Subroutine init: called CC=1 SCAR=0.0
Pod documented
16 23 ${"$_[0]::Separator"} = '_';
17  
18 # call the parent class init code
19 23 goto &Acme::MetaSyntactic::MultiList::init;
20 }
21  
22 sub new {
23 95 ▶ my $class = shift;
Subroutine new: called CC=15 SCAR=27.1
Pod documented
24  
25 24 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
26 95 my $self = bless { @_, cache => [] }, $class;
27  
28 # compute some defaults
29 95 ▶ if( ! exists $self->{category} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (exists $self->{"category"}) 93 2 95
30 $self->{category} =
31 exists $self->{lang}
32 ? $self->{lang}
33 93 ▶ : $ENV{LANGUAGE} || $ENV{LANG} || '';
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'lang'} ? : 18 75 93
Condition100%5/5
$ENV{"LANGUAGE"} or $ENV{"LANG"} or ""
l!l
1362
$ENV{"LANGUAGE"} or $ENV{"LANG"}
l!l&&r!l&&!r
21162
MC/DC100%2/2
$ENV{"LANGUAGE"} or $ENV{"LANG"} or ""
$ENV{"LANGUAGE"} $ENV{"LANG"}
Truth table100%3/3
A or B
A= $ENV{"LANGUAGE"}B= $ENV{"LANG"}
ABresult
1X1
011
000
34 93 ▶ if( !$self->{category} && $^O eq 'MSWin32' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $self->{"category"} and $^O eq "MSWin32") 2 91 93
Condition100%3/3
not $self->{"category"} and $^O eq "MSWin32"
!ll&&!rl&&r
31602
MC/DC100%2/2
not $self->{"category"} and $^O eq "MSWin32"
not $self->{"category"} $^O eq "MSWin32"
Truth table100%3/3
not(A) and B
A= not $self->{"category"}B= $^O eq "MSWin32"
ABresult
0X0
100
111
35 2 eval { require Win32::Locale; };
36 2 ▶ $self->{category} = Win32::Locale::get_language() unless $@;
Branch: 1 branch
BranchTrueFalseTotal
unless $@ 2 0 2
37 }
38 }
39  
40 95 my $cat = $self->{category};
41  
42 # support for territories
43 95 ▶ if ( $cat && $cat ne ':all' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cat and $cat ne ":all") 33 62 95
Condition100%3/3
$cat and $cat ne ":all"
!ll&&!rl&&r
61133
MC/DC100%2/2
$cat and $cat ne ":all"
$cat $cat ne ":all"
Truth table100%3/3
A and B
A= $catB= $cat ne ":all"
ABresult
0X0
100
111
44 33 ($cat) = $cat =~ /^([-A-Za-z_]+)/;
45 33 ▶ $cat = lc( $cat || '' );
Condition50%1/2
$cat || ''
l!l
330
MC/DC0%0/1
$cat || ''
$cat
Truth table50%1/2
A
A= $cat
Aresult
11
00
46 1 while $cat
47 33 ▶ && !exists ${"$class\::MultiList"}{$cat}
Branch: 1 branch
BranchTrueFalseTotal
$cat and not exists do { "${class}::MultiList" }->{$cat} and $cat =~ s/_?[^_]*$// and do { '???' } 5 33 38
Condition83%5/6
$cat and not exists do { "${class}::MultiList" }->{$cat} and $cat =~ s/_?[^_]*$//
!ll&&!rl&&r
3305
$cat and not exists do { "${class}::MultiList" }->{$cat}
!ll&&!rl&&r
2315
MC/DC66%2/3
$cat and not exists do { "${class}::MultiList" }->{$cat} and $cat =~ s/_?[^_]*$//
$cat not exists do { "${class}::MultiList" }->{$cat} $cat =~ s/_?[^_]*$//
Truth table75%3/4
A and not(B) and C
A= $catB= not exists do { "${class}::MultiList" }->{$cat}C= $cat =~ s/_?[^_]*$//
ABCresult
0XX0
10X0
1100
1111
48 && $cat =~ s/_?[^_]*$//;
49 }
50  
51 # fall back to last resort
52 95 ▶ $self->{category} = $cat || ${"$class\::Default"};
Condition66%2/3
$cat || ${"${class}::Default";}
l!l&&r!l&&!r
32630
MC/DC0%0/2
$cat || ${"${class}::Default";}
$cat ${"${class}::Default";}
Truth table66%2/3
A || B
A= $catB= ${"${class}::Default";}
ABresult
1X1
011
000
53 95 $self->_compute_base();
54 95 return $self;
55 }
56  
57 24 *lang = \&Acme::MetaSyntactic::MultiList::category;
58 24 *languages = \&Acme::MetaSyntactic::MultiList::categories;
59  
60 24 1;
61  
62 __END__
« Test/MetaSyntactic.pm ↑ Summary Acme/MetaSyntactic/RemoteList.pm »