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
|
|
29793
|
use Mojo::Base qw(-base); |
|
28
|
|
|
|
|
7697
|
|
|
28
|
|
|
|
|
302
|
|
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
|
21429
|
my $self = shift->SUPER::new(@_); |
17
|
|
|
|
|
|
|
|
18
|
35
|
50
|
33
|
|
|
529
|
if ( @_ && @_ % 2 == 0 ) { |
19
|
35
|
|
|
|
|
127
|
my %attrs = @_; |
20
|
35
|
|
|
|
|
157
|
$self->locale( $attrs{locale} ); |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
|
23
|
35
|
|
|
|
|
336
|
$self->_split_locale(); |
24
|
|
|
|
|
|
|
|
25
|
35
|
|
|
|
|
484
|
$self; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
our $AUTOLOAD; |
29
|
|
|
|
|
|
|
sub AUTOLOAD { |
30
|
39
|
|
|
39
|
|
5993
|
my $self = shift; |
31
|
|
|
|
|
|
|
|
32
|
39
|
|
|
|
|
261
|
my @infos = split //, (split /::/, $AUTOLOAD)[-1]; |
33
|
39
|
|
|
|
|
295
|
my %attrs = qw/l lang s script r region e ext/; |
34
|
39
|
100
|
66
|
|
|
110
|
my @wanted = map{ my $attr = $attrs{$_}; ( $attr && $self->$attr() ) ? $self->$attr() : () }@infos; |
|
60
|
|
|
|
|
322
|
|
|
60
|
|
|
|
|
253
|
|
35
|
|
|
|
|
|
|
|
36
|
39
|
100
|
|
|
|
470
|
@wanted = ('') if !@wanted; |
37
|
|
|
|
|
|
|
|
38
|
39
|
|
|
|
|
260
|
return join '-', @wanted; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub _split_locale { |
42
|
35
|
|
|
35
|
|
94
|
my ($self) = @_; |
43
|
|
|
|
|
|
|
|
44
|
35
|
|
|
|
|
116
|
my $locale = $self->locale; |
45
|
|
|
|
|
|
|
|
46
|
35
|
|
|
|
|
223
|
$locale = lc $locale; |
47
|
35
|
|
|
|
|
120
|
$locale =~ tr{_}{-}; |
48
|
|
|
|
|
|
|
|
49
|
35
|
|
|
|
|
267
|
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
|
|
|
|
149
|
$script = ucfirst $script if $script; |
58
|
35
|
100
|
|
|
|
128
|
$region = uc $region if $region; |
59
|
|
|
|
|
|
|
|
60
|
35
|
|
|
|
|
157
|
$self->lang( $lang ); |
61
|
35
|
|
|
|
|
297
|
$self->script( $script ); |
62
|
35
|
|
|
|
|
298
|
$self->region( $region ); |
63
|
35
|
|
|
|
|
279
|
$self->ext( $ext ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
__END__ |