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
|
|
39054
|
use Mojo::Base qw(-base); |
|
28
|
|
|
|
|
9868
|
|
|
28
|
|
|
|
|
307
|
|
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
|
18397
|
my $self = shift->SUPER::new(@_); |
17
|
|
|
|
|
|
|
|
18
|
35
|
50
|
33
|
|
|
449
|
if ( @_ && @_ % 2 == 0 ) { |
19
|
35
|
|
|
|
|
96
|
my %attrs = @_; |
20
|
35
|
|
|
|
|
124
|
$self->locale( $attrs{locale} ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
35
|
|
|
|
|
276
|
$self->_split_locale(); |
24
|
|
|
|
|
|
|
|
25
|
35
|
|
|
|
|
413
|
$self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $AUTOLOAD; |
29
|
|
|
|
|
|
|
sub AUTOLOAD { |
30
|
39
|
|
|
39
|
|
4158
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
39
|
|
|
|
|
220
|
my @infos = split //, (split /::/, $AUTOLOAD)[-1]; |
33
|
39
|
|
|
|
|
197
|
my %attrs = qw/l lang s script r region e ext/; |
34
|
39
|
100
|
66
|
|
|
73
|
my @wanted = map{ my $attr = $attrs{$_}; ( $attr && $self->$attr() ) ? $self->$attr() : () }@infos; |
|
60
|
|
|
|
|
352
|
|
|
60
|
|
|
|
|
249
|
|
35
|
|
|
|
|
|
|
|
36
|
39
|
100
|
|
|
|
529
|
@wanted = ('') if !@wanted; |
37
|
|
|
|
|
|
|
|
38
|
39
|
|
|
|
|
248
|
return join '-', @wanted; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _split_locale { |
42
|
35
|
|
|
35
|
|
50
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
35
|
|
|
|
|
93
|
my $locale = $self->locale; |
45
|
|
|
|
|
|
|
|
46
|
35
|
|
|
|
|
220
|
$locale = lc $locale; |
47
|
35
|
|
|
|
|
79
|
$locale =~ tr{_}{-}; |
48
|
|
|
|
|
|
|
|
49
|
35
|
|
|
|
|
223
|
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
|
|
|
|
109
|
$script = ucfirst $script if $script; |
58
|
35
|
100
|
|
|
|
88
|
$region = uc $region if $region; |
59
|
|
|
|
|
|
|
|
60
|
35
|
|
|
|
|
107
|
$self->lang( $lang ); |
61
|
35
|
|
|
|
|
240
|
$self->script( $script ); |
62
|
35
|
|
|
|
|
229
|
$self->region( $region ); |
63
|
35
|
|
|
|
|
212
|
$self->ext( $ext ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |