DateTime-Locale
view release on metacpan or search on metacpan
tools/lib/ModuleGenerator/Locale.pm view on Meta::CPAN
for my $part (qw( language territory script variant )) {
my $attr = q{_} . $lang . q{_} . $part;
has $attr => (
is => 'ro',
isa => t( 'Maybe', of => t('Str') ),
lazy => 1,
builder => '_build' . $attr,
);
}
}
has _cldr_json_data => (
is => 'ro',
isa => t('HashRef'),
lazy => 1,
builder => '_build_cldr_json_data',
);
has _first_day_of_week => (
is => 'ro',
isa => t('Int'),
lazy => 1,
builder => '_build_first_day_of_week',
);
has version => (
is => 'ro',
isa => t('LaxVersionStr'),
required => 1,
);
has data_hash => (
is => 'ro',
isa => t('HashRef'),
lazy => 1,
builder => '_build_data_hash',
);
{
my %Cache;
sub instance ( $class, %p ) {
return $Cache{ $p{code} } //= $class->new(%p);
}
}
## no critic (ValuesAndExpressions::ProhibitFiletest_f)
sub source_files ($self) {
return grep {-f} $self->_json_file, $self->_glibc_file;
}
sub _build_cldr_json_data ($self) {
my $json = $self->_json_from( $self->_json_file );
my $json_file_id = $self->_json_file->parent->basename;
my $cldr = $json->{main}{$json_file_id};
# https://unicode-org.atlassian.net/browse/CLDR-14361
if ( $self->code =~ /^sd-Deva/
&& $cldr->{dates}{calendars}{gregorian}{quarters}{format}{narrow}{4}
== 1 ) {
$cldr->{dates}{calendars}{gregorian}{quarters}{format}{narrow}{4} = 4;
}
return $cldr;
}
sub _build_data_hash ($self) {
my $cal_root = $self->_cldr_json_data->{dates}{calendars}{gregorian};
my %data = (
## no critic (ValuesAndExpressions::ProhibitCommaSeparatedStatements)
am_pm_abbreviated =>
[ $cal_root->{dayPeriods}{format}{abbreviated}->@{ 'am', 'pm' } ],
available_formats => $cal_root->{dateTimeFormats}{availableFormats},
code => $self->code,
first_day_of_week => $self->_first_day_of_week,
version => $self->version,
$self->_glibc_data->%*,
);
for my $thing (qw( name language script territory variant )) {
for my $type (qw( en native )) {
my $meth
= ( $thing eq 'name' ? q{} : q{_} ) . $type . q{_} . $thing;
my $key = join q{_}, ( ( $type eq 'en' ? () : $type ), $thing );
$data{$key} = $self->$meth;
}
}
for my $thing (qw( date time dateTime )) {
for my $length (qw( full long medium short )) {
my $val = $cal_root->{ $thing . 'Formats' }{$length};
$data{ lc $thing . q{_format_} . $length }
= ref $val ? $val->{_value} : $val;
}
}
my %ordering = (
day => [qw( mon tue wed thu fri sat sun )],
month => [ 1 .. 12 ],
quarter => [ 1 .. 4 ],
);
my @lengths = qw( abbreviated narrow wide );
for my $thing (qw( day month quarter )) {
for my $type (qw( format stand-alone )) {
for my $length (@lengths) {
my $key = join q{_}, $thing, ( $type =~ s/-/_/gr ), $length;
$data{$key}
= [ $cal_root->{ $thing . 's' }{$type}{$length}
->@{ $ordering{$thing}->@* } ];
}
}
}
my %era_length = (
narrow => 'Narrow',
abbreviated => 'Abbr',
wide => 'Names',
);
for my $length (@lengths) {
## no critic (ValuesAndExpressions::ProhibitCommaSeparatedStatements)
$data{ 'era_' . $length }
= [
$cal_root->{eras}{ 'era' . $era_length{$length} }->@{ 0, 1 } ];
}
return \%data;
( run in 0.789 second using v1.01-cache-2.11-cpan-39bf76dae61 )