line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojolicious::Plugin::I18NUtils::Locale; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: class that represents a locale string |
4
|
|
|
|
|
|
|
|
5
|
28
|
|
|
28
|
|
80100
|
use Mojo::Base qw(-base); |
|
28
|
|
|
|
|
175683
|
|
|
28
|
|
|
|
|
352
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 0.01; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
has 'locale' => 'en'; |
10
|
|
|
|
|
|
|
has 'lang' => ''; |
11
|
|
|
|
|
|
|
has 'script' => ''; |
12
|
|
|
|
|
|
|
has 'region' => ''; |
13
|
|
|
|
|
|
|
has 'ext' => ''; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
35
|
|
|
35
|
1
|
18733
|
my $self = shift->SUPER::new(@_); |
17
|
|
|
|
|
|
|
|
18
|
35
|
50
|
33
|
|
|
442
|
if ( @_ && @_ % 2 == 0 ) { |
19
|
35
|
|
|
|
|
111
|
my %attrs = @_; |
20
|
35
|
|
|
|
|
118
|
$self->locale( $attrs{locale} ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
35
|
|
|
|
|
307
|
$self->_split_locale(); |
24
|
|
|
|
|
|
|
|
25
|
35
|
|
|
|
|
485
|
$self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $AUTOLOAD; |
29
|
|
|
|
|
|
|
sub AUTOLOAD { |
30
|
39
|
|
|
39
|
|
5925
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
39
|
|
|
|
|
228
|
my @infos = split //, (split /::/, $AUTOLOAD)[-1]; |
33
|
39
|
|
|
|
|
182
|
my %attrs = qw/l lang s script r region e ext/; |
34
|
39
|
100
|
66
|
|
|
115
|
my @wanted = map{ my $attr = $attrs{$_}; ( $attr && $self->$attr() ) ? $self->$attr() : () }@infos; |
|
60
|
|
|
|
|
301
|
|
|
60
|
|
|
|
|
212
|
|
35
|
|
|
|
|
|
|
|
36
|
39
|
100
|
|
|
|
444
|
@wanted = ('') if !@wanted; |
37
|
|
|
|
|
|
|
|
38
|
39
|
|
|
|
|
245
|
return join '-', @wanted; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _split_locale { |
42
|
35
|
|
|
35
|
|
78
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
35
|
|
|
|
|
75
|
my $locale = $self->locale; |
45
|
|
|
|
|
|
|
|
46
|
35
|
|
|
|
|
188
|
$locale = lc $locale; |
47
|
35
|
|
|
|
|
88
|
$locale =~ tr{_}{-}; |
48
|
|
|
|
|
|
|
|
49
|
35
|
|
|
|
|
286
|
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
|
100
|
|
|
|
147
|
$script = ucfirst $script if $script; |
58
|
35
|
100
|
|
|
|
110
|
$region = uc $region if $region; |
59
|
|
|
|
|
|
|
|
60
|
35
|
|
|
|
|
105
|
$self->lang( $lang ); |
61
|
35
|
|
|
|
|
247
|
$self->script( $script ); |
62
|
35
|
|
|
|
|
223
|
$self->region( $region ); |
63
|
35
|
|
|
|
|
196
|
$self->ext( $ext ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |