I18NUtils/Locale.pm

filter: Statementstmt 100% 36 / 36 Branchbran 90.0% 9 / 10 Conditioncond 50.0% 3 / 6 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 88.5% 54 / 61 CC 8 SCAR 11.7
CC
8
Cov
92%
AUTOLOAD
4.0
new
3.2
_split_locale
3.0
CRAP 3.2
« I18NUtils.pm ↑ Summary
1 package Mojolicious::Plugin::I18NUtils::Locale;
2  
3 # ABSTRACT: class that represents a locale string
4  
5 28 ▶use Mojo::Base qw(-base);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 28 our $VERSION = 0.01;
8  
9 28 has 'locale' => 'en';
10 28 has 'lang' => '';
11 28 has 'script' => '';
12 28 has 'region' => '';
13 28 has 'ext' => '';
14  
15 35 ▶sub new {
Subroutine new: called CC=3 SCAR=11.6
Pod documented
16 35 my $self = shift->SUPER::new(@_);
17  
18 35 ▶ if ( @_ && @_ % 2 == 0 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_ and @_ % 2 == 0) 35 0 35
Condition33%1/3
@_ and @_ % 2 == 0
!ll&&!rl&&r
0035
MC/DC0%0/2
@_ and @_ % 2 == 0
@_ @_ % 2 == 0
Truth table33%1/3
A and B
A= @_B= @_ % 2 == 0
ABresult
0X0
100
111
19 35 my %attrs = @_;
20 35 $self->locale( $attrs{locale} );
21 }
22  
23 35 $self->_split_locale();
24  
25 35 $self;
26 }
27  
28 28 our $AUTOLOAD;
29 39 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=4 SCAR=13.9
30 39 my $self = shift;
31  
32 39 my @infos = split //, (split /::/, $AUTOLOAD)[-1];
33 39 my %attrs = qw/l lang s script r region e ext/;
34 39 ▶ my @wanted = map{ my $attr = $attrs{$_}; ( $attr && $self->$attr() ) ? $self->$attr() : () }@infos;
Branch: 1 branch
BranchTrueFalseTotal
$attr && $self->$attr ? : 45 15 60
Condition66%2/3
$attr and $self->$attr
!ll&&!rl&&r
01545
MC/DC50%1/2
$attr and $self->$attr
$attr $self->$attr
Truth table66%2/3
A and B
A= $attrB= $self->$attr
ABresult
0X0
100
111
35  
36 39 ▶ @wanted = ('') if !@wanted;
Branch: 1 branch
BranchTrueFalseTotal
unless @wanted 6 33 39
37  
38 39 return join '-', @wanted;
39 }
40  
41 35 ▶sub _split_locale {
Subroutine _split_locale: called CC=3 SCAR=11.0
42 35 my ($self) = @_;
43
44 35 my $locale = $self->locale;
45
46 35 $locale = lc $locale;
47 35 $locale =~ tr{_}{-};
48
49 35 my ($lang, $script, $region, $ext) = $locale =~ m{ ^
50 ( [a-z]{2,3} ) # language
51 (?: - ( [a-z]{4} ) )? # script
52 (?: - ( [a-z]{2} | [0-9]{3} ) )? # country or region
53 (?: - ( u- .+ ) )? # extension
54 -? # trailing separator
55 $ }xi;
56
57 35 ▶ $script = ucfirst $script if $script;
Branch: 1 branch
BranchTrueFalseTotal
if $script 11 24 35
58 35 ▶ $region = uc $region if $region;
Branch: 1 branch
BranchTrueFalseTotal
if $region 11 24 35
59
60 35 $self->lang( $lang );
61 35 $self->script( $script );
62 35 $self->region( $region );
63 35 $self->ext( $ext );
64 }
65  
66 28 1;
67  
68 __END__
« I18NUtils.pm ↑ Summary