<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">package DateTime::Locale::Base;

use strict;
use warnings;
use namespace::autoclean;

our $VERSION = '1.26';

use Carp qw( carp );
use DateTime::Locale;
use List::Util 1.45 ();
use Params::ValidationCompiler 0.13 qw( validation_for );
use Specio::Declare;

BEGIN {
    foreach my $field (
        qw( id en_complete_name native_complete_name
        en_language en_script en_territory en_variant
        native_language native_script native_territory native_variant
        )
    ) {

        # remove leading 'en_' for method name
        ( my $meth_name = $field ) =~ s/^en_//;

        # also remove 'complete_'
        $meth_name =~ s/complete_//;

        no strict 'refs';
        *{$meth_name} = sub { $_[0]-&gt;{$field} };
    }
}

sub new {
    my $class = shift;

    # By making the default format lengths part of the object's hash
    # key, it allows them to be settable.
    return bless {
        @_,
        default_date_format_length =&gt; 'long',
        default_time_format_length =&gt; 'long',
    }, $class;
}

sub language_id  { ( DateTime::Locale::_parse_id( $_[0]-&gt;id ) )[0] }
sub script_id    { ( DateTime::Locale::_parse_id( $_[0]-&gt;id ) )[1] }
sub territory_id { ( DateTime::Locale::_parse_id( $_[0]-&gt;id ) )[2] }
sub variant_id   { ( DateTime::Locale::_parse_id( $_[0]-&gt;id ) )[3] }

my @FormatLengths = qw( short medium long full );

sub date_format_default {
    my $meth = 'date_format_' . $_[0]-&gt;default_date_format_length();
    $_[0]-&gt;$meth();
}

sub date_formats {
    return {
        map {
            my $meth = 'date_format_' . $_;
            $_ =&gt; $_[0]-&gt;$meth()
        } @FormatLengths
    };
}

sub time_format_default {
    my $meth = 'time_format_' . $_[0]-&gt;default_time_format_length();
    $_[0]-&gt;$meth();
}

sub time_formats {
    return {
        map {
            my $meth = 'time_format_' . $_;
            $_ =&gt; $_[0]-&gt;$meth()
        } @FormatLengths
    };
}

sub format_for {
    my $self = shift;
    my $for  = shift;

    my $meth = '_format_for_' . $for;

    return unless $self-&gt;can($meth);

    return $self-&gt;$meth();
}

sub available_formats {
    my $self = shift;

    # The various parens seem to be necessary to force uniq() to see
    # the caller's list context. Go figure.
    my @uniq
        = List::Util::uniq( map { keys %{ $_-&gt;_available_formats() || {} } }
            _self_and_super_path( ref $self ) );

    # Doing the sort in the same expression doesn't work under 5.6.x.
    return sort @uniq;
}

# Copied wholesale from Class::ISA, because said module warns as deprecated
# with perl 5.11.0+, which is kind of annoying.
sub _self_and_super_path {

    # Assumption: searching is depth-first.
    # Assumption: '' (empty string) can't be a class package name.
    # Note: 'UNIVERSAL' is not given any special treatment.
    return () unless @_;

    my @out = ();

    my @in_stack = ( $_[0] );
    my %seen     = ( $_[0] =&gt; 1 );

    my $current;
    while (@in_stack) {
        next unless defined( $current = shift @in_stack ) &amp;&amp; length($current);
        push @out, $current;
        no strict 'refs';
        unshift @in_stack, map {
            my $c = $_;    # copy, to avoid being destructive
            substr( $c, 0, 2 ) = "main::" if substr( $c, 0, 2 ) eq '::';

            # Canonize the :: -&gt; main::, ::foo -&gt; main::foo thing.
            # Should I ever canonize the Foo'Bar = Foo::Bar thing?
            $seen{$c}++ ? () : $c;
        } @{"$current\::ISA"};

        # I.e., if this class has any parents (at least, ones I've never seen
        # before), push them, in order, onto the stack of classes I need to
        # explore.
    }

    return @out;
}

# Just needed for the above method.
sub _available_formats { }

sub default_date_format_length { $_[0]-&gt;{default_date_format_length} }

my $length    = enum( values =&gt; [qw( full long medium short )] );
my $validator = validation_for(
    name             =&gt; '_check_length_parameter',
    name_is_optional =&gt; 1,
    params           =&gt; [ { type =&gt; $length } ],
);

sub set_default_date_format_length {
    my $self = shift;
    my ($l) = $validator-&gt;(@_);

    $self-&gt;{default_date_format_length} = lc $l;
}

sub default_time_format_length { $_[0]-&gt;{default_time_format_length} }

sub set_default_time_format_length {
    my $self = shift;
    my ($l) = $validator-&gt;(@_);

    $self-&gt;{default_time_format_length} = lc $l;
}

for my $length (qw( full long medium short )) {
    my $key = 'datetime_format_' . $length;

    my $sub = sub {
        my $self = shift;

        return $self-&gt;{$key} if exists $self-&gt;{$key};

        my $date_meth = 'date_format_' . $length;
        my $time_meth = 'time_format_' . $length;

        return $self-&gt;{$key}
            = $self-&gt;_make_datetime_format( $date_meth, $time_meth );
    };

    no strict 'refs';
    *{$key} = $sub;
}

sub datetime_format_default {
    my $self = shift;

    my $date_meth = 'date_format_' . $self-&gt;default_date_format_length();
    my $time_meth = 'time_format_' . $self-&gt;default_time_format_length();

    return $self-&gt;_make_datetime_format( $date_meth, $time_meth );
}

sub _make_datetime_format {
    my $self      = shift;
    my $date_meth = shift;
    my $time_meth = shift;

    my $dt_format = $self-&gt;datetime_format();

    my $time = $self-&gt;$time_meth();
    my $date = $self-&gt;$date_meth();

    $dt_format =~ s/\{0\}/$time/g;
    $dt_format =~ s/\{1\}/$date/g;

    return $dt_format;
}

sub prefers_24_hour_time {
    my $self = shift;

    return $self-&gt;{prefers_24_hour_time}
        if exists $self-&gt;{prefers_24_hour_time};

    $self-&gt;{prefers_24_hour_time}
        = $self-&gt;time_format_short() =~ /h|K/ ? 0 : 1;
}

# Backwards compat for DateTime.pm version &lt;= 0.42
{
    my %subs = (
        month_name =&gt; sub { $_[0]-&gt;month_format_wide()-&gt;[ $_[1]-&gt;month_0 ] },

        month_abbreviation =&gt; sub {
            $_[0]-&gt;month_format_abbreviated()-&gt;[ $_[1]-&gt;month_0 ];
        },
        month_narrow =&gt;
            sub { $_[0]-&gt;month_format_narrow()-&gt;[ $_[1]-&gt;month_0 ]; },

        month_names         =&gt; sub { $_[0]-&gt;month_format_wide() },
        month_abbreviations =&gt; sub { $_[0]-&gt;month_format_abbreviated() },
        month_narrows       =&gt; sub { $_[0]-&gt;month_format_narrow() },

        day_name =&gt;
            sub { $_[0]-&gt;day_format_wide()-&gt;[ $_[1]-&gt;day_of_week_0 ] },

        day_abbreviation =&gt; sub {
            $_[0]-&gt;day_format_abbreviated()-&gt;[ $_[1]-&gt;day_of_week_0 ];
        },
        day_narrow =&gt;
            sub { $_[0]-&gt;day_format_narrow()-&gt;[ $_[1]-&gt;day_of_week_0 ]; },

        day_names         =&gt; sub { $_[0]-&gt;day_format_wide() },
        day_abbreviations =&gt; sub { $_[0]-&gt;day_format_abbreviated() },
        day_narrows       =&gt; sub { $_[0]-&gt;day_format_narrow() },

        quarter_name =&gt;
            sub { $_[0]-&gt;quarter_format_wide()-&gt;[ $_[1]-&gt;quarter - 1 ] },

        quarter_abbreviation =&gt; sub {
            $_[0]-&gt;quarter_format_abbreviated()-&gt;[ $_[1]-&gt;quarter - 1 ];
        },
        quarter_narrow =&gt;
            sub { $_[0]-&gt;quarter_format_narrow()-&gt;[ $_[1]-&gt;quarter - 1 ] },

        quarter_names         =&gt; sub { $_[0]-&gt;quarter_format_wide() },
        quarter_abbreviations =&gt; sub { $_[0]-&gt;quarter_format_abbreviated() },

        am_pm =&gt;
            sub { $_[0]-&gt;am_pm_abbreviated()-&gt;[ $_[1]-&gt;hour &lt; 12 ? 0 : 1 ] },
        am_pms =&gt; sub { $_[0]-&gt;am_pm_abbreviated() },

        era_name =&gt; sub { $_[0]-&gt;era_wide()-&gt;[ $_[1]-&gt;ce_year &lt; 0 ? 0 : 1 ] },

        era_abbreviation =&gt; sub {
            $_[0]-&gt;era_abbreviated()-&gt;[ $_[1]-&gt;ce_year &lt; 0 ? 0 : 1 ];
        },
        era_narrow =&gt;
            sub { $_[0]-&gt;era_narrow()-&gt;[ $_[1]-&gt;ce_year &lt; 0 ? 0 : 1 ] },

        era_names         =&gt; sub { $_[0]-&gt;era_wide() },
        era_abbreviations =&gt; sub { $_[0]-&gt;era_abbreviated() },

        # ancient backwards compat
        era  =&gt; sub { $_[0]-&gt;era_abbreviation },
        eras =&gt; sub { $_[0]-&gt;era_abbreviations },

        date_before_time =&gt; sub {
            my $self = shift;

            my $dt_format = $self-&gt;datetime_format();

            return $dt_format =~ /\{1\}.*\{0\}/ ? 1 : 0;
        },

        date_parts_order =&gt; sub {
            my $self = shift;

            my $short = $self-&gt;date_format_short();

            $short =~ tr{dmyDMY}{}cd;
            $short =~ tr{dmyDMY}{dmydmy}s;

            return $short;
        },

        full_date_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;date_format_full() );
        },

        long_date_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;date_format_long() );
        },

        medium_date_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;date_format_medium() );
        },

        short_date_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;date_format_short() );
        },

        default_date_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;date_format_default() );
        },

        full_time_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;time_format_full() );
        },

        long_time_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;time_format_long() );
        },

        medium_time_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;time_format_medium() );
        },

        short_time_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;time_format_short() );
        },

        default_time_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;time_format_default() );
        },

        full_datetime_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;datetime_format_full() );
        },

        long_datetime_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;datetime_format_long() );
        },

        medium_datetime_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;datetime_format_medium() );
        },

        short_datetime_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;datetime_format_short() );
        },

        default_datetime_format =&gt; sub {
            $_[0]-&gt;_convert_to_strftime( $_[0]-&gt;datetime_format_default() );
        },
    );

    for my $name ( keys %subs ) {
        my $real_sub = $subs{$name};

        my $sub = sub {
            carp
                "The $name method in DateTime::Locale::Base has been deprecated. Please see the DateTime::Locale distribution's Changes file for details";
            return shift-&gt;$real_sub(@_);
        };

        no strict 'refs';
        *{$name} = $sub;
    }
}

# Older versions of DateTime.pm will not pass in the $cldr_ok flag, so
# we will give them the converted-to-strftime pattern (bugs and all).
sub _convert_to_strftime {
    my $self    = shift;
    my $pattern = shift;
    my $cldr_ok = shift;

    return $pattern if $cldr_ok;

    return $self-&gt;{_converted_patterns}{$pattern}
        if exists $self-&gt;{_converted_patterns}{$pattern};

    return $self-&gt;{_converted_patterns}{$pattern}
        = $self-&gt;_cldr_to_strftime($pattern);
}

{
    my @JavaPatterns = (
        qr/G/    =&gt; '{era}',
        qr/yyyy/ =&gt; '{ce_year}',
        qr/y/    =&gt; 'y',
        qr/u/    =&gt; 'Y',
        qr/MMMM/ =&gt; 'B',
        qr/MMM/  =&gt; 'b',
        qr/MM/   =&gt; 'm',
        qr/M/    =&gt; '{month}',
        qr/dd/   =&gt; 'd',
        qr/d/    =&gt; '{day}',
        qr/hh/   =&gt; 'l',
        qr/h/    =&gt; '{hour_12}',
        qr/HH/   =&gt; 'H',
        qr/H/    =&gt; '{hour}',
        qr/mm/   =&gt; 'M',
        qr/m/    =&gt; '{minute}',
        qr/ss/   =&gt; 'S',
        qr/s/    =&gt; '{second}',
        qr/S/    =&gt; 'N',
        qr/EEEE/ =&gt; 'A',
        qr/E/    =&gt; 'a',
        qr/D/    =&gt; 'j',
        qr/F/    =&gt; '{weekday_of_month}',
        qr/w/    =&gt; 'V',
        qr/W/    =&gt; '{week_month}',
        qr/a/    =&gt; 'p',
        qr/k/    =&gt; '{hour_1}',
        qr/K/    =&gt; '{hour_12_0}',
        qr/z/    =&gt; '{time_zone_long_name}',
    );

    sub _cldr_to_strftime {
        shift;
        my $simple = shift;

        $simple
            =~ s/(G+|y+|u+|M+|d+|h+|H+|m+|s+|S+|E+|D+|F+|w+|W+|a+|k+|K+|z+)|'((?:[^']|'')*)'/
                $2 ? _stringify($2) : $1 ? _convert($1) : "'"/eg;

        return $simple;
    }

    sub _convert {
        my $simple = shift;

        for ( my $x = 0; $x &lt; @JavaPatterns; $x += 2 ) {
            return '%' . $JavaPatterns[ $x + 1 ]
                if $simple =~ /$JavaPatterns[$x]/;
        }

        die "**Dont know $simple***";
    }

    sub _stringify {
        my $string = shift;

        $string =~ s/%(?:[^%])/%%/g;
        $string =~ s/\'\'/\'/g;

        return $string;
    }
}

# end backwards compat

sub STORABLE_freeze {
    my $self    = shift;
    my $cloning = shift;

    return if $cloning;

    return $self-&gt;id();
}

sub STORABLE_thaw {
    my $self = shift;
    shift;
    my $serialized = shift;

    my $obj = DateTime::Locale-&gt;load($serialized);

    %$self = %$obj;

    return $self;
}

1;

# ABSTRACT: Base class for individual locale objects

__END__

=pod

=encoding UTF-8

=head1 NAME

DateTime::Locale::Base - Base class for individual locale objects

=head1 VERSION

version 1.26

=head1 SYNOPSIS

  use base 'DateTime::Locale::Base';

=head1 DESCRIPTION

B&lt;This module is no longer used by the code in the distribution.&gt; It is still
included for the sake of any code out in the wild that may subclass this
class. This class will be removed in a future release.

=head1 DEFAULT FORMATS

Each locale has a set of four default date and time formats.  They are
distinguished by length, and are called "full", "long", "medium", and
"short". Each locale may have a different default length which it uses
when its C&lt;&lt; $locale-&gt;date_format_default() &gt;&gt;, C&lt;&lt;
$locale-&gt;time_format_default() &gt;&gt;, or C&lt;&lt;
$locale-&gt;datetime_format_default() &gt;&gt; methods are called.

This can be changed by calling the C&lt;&lt;
$locale-&gt;set_default_date_format() &gt;&gt; or C&lt;&lt;
$locale-&gt;set_default_time_format() &gt;&gt; methods.  These methods accept a
string which must be one of "full", "long", "medium", or "short".

=head1 NAME FORMS

Most names come in a number of variations. First, they may vary based
on length, with wide, abbreviated, and narrow forms. The wide form is
typically the full name, while the narrow form is often a single
character. The narrow forms may not be unique. For example, "T" may be
used for Tuesday and Thursday in the English narrow forms.

Many names also distinguish between "format" and "stand-alone" forms
of a pattern. The format pattern is used when the thing in question is
being placed into a larger string. The stand-alone form is used when
displaying that item by itself, for example in a calendar.

=head1 METHODS

All locales provide the following methods:

=over 4

=item * $locale-&gt;id()

The locale's id.

=item * $locale-&gt;language_id()

The language portion of the id.

=item * $locale-&gt;script_id()

The script portion of the id, if any.

=item * $locale-&gt;territory_id()

The territory portion of the id, if any.

=item * $locale-&gt;variant_id()

The variant portion of the id, if any.

=item * $locale-&gt;name()

The full name for the locale in English.

=item * $locale-&gt;language()

The language name for the locale in English.

=item * $locale-&gt;script()

The script name for the locale in English, if any.

=item * $locale-&gt;territory()

The territory name for the locale in English, if any.

=item * $locale-&gt;variant()

The variant name for the locale in English, if any.

=item * $locale-&gt;native_name()

The full name for the locale in its native language, if any.

=item * $locale-&gt;native_language()

The language name for the locale in its native language, if any.

=item * $locale-&gt;native_script()

The script name for the locale in its native language, if any.

=item * $locale-&gt;native_territory()

The territory name for the locale in its native language, if any.

=item * $locale-&gt;native_variant()

The variant name for the locale in its native language, if any.

=item * $locale-&gt;month_format_wide()

Returns an array reference containing the wide format names of the
months, with January as the first month.

=item * $locale-&gt;month_format_abbreviated()

Returns an array reference containing the abbreviated format names of
the months, with January as the first month.

=item * $locale-&gt;month_format_narrow()

Returns an array reference containing the narrow format names of the
months, with January as the first month.

=item * $locale-&gt;month_stand_alone_wide()

Returns an array reference containing the wide stand-alone names of
the months, with January as the first month.

=item * $locale-&gt;month_stand_alone_abbreviated()

Returns an array reference containing the abbreviated stand-alone
names of the months, with January as the first month.

=item * $locale-&gt;month_stand_alone_narrow()

Returns an array reference containing the narrow stand-alone names of the
months, with January as the first month.

=item * $locale-&gt;day_format_wide()

Returns an array reference containing the wide format names of the
days, with Monday as the first day.

=item * $locale-&gt;day_format_abbreviated()

Returns an array reference containing the abbreviated format names of
the days, with Monday as the first day.

=item * $locale-&gt;day_format_narrow()

Returns an array reference containing the narrow format names of the
days, with Monday as the first day.

=item * $locale-&gt;day_stand_alone_wide()

Returns an array reference containing the wide stand-alone names of
the days, with Monday as the first day.

=item * $locale-&gt;day_stand_alone_abbreviated()

Returns an array reference containing the abbreviated stand-alone
names of the days, with Monday as the first day.

=item * $locale-&gt;day_stand_alone_narrow()

Returns an array reference containing the narrow stand-alone names of
the days, with Monday as the first day.

=item * $locale-&gt;quarter_format_wide()

Returns an array reference containing the wide format names of the
quarters.

=item * $locale-&gt;quarter_format_abbreviated()

Returns an array reference containing the abbreviated format names of
the quarters.

=item * $locale-&gt;quarter_format_narrow()

Returns an array reference containing the narrow format names of the
quarters.

=item * $locale-&gt;quarter_stand_alone_wide()

Returns an array reference containing the wide stand-alone names of
the quarters.

=item * $locale-&gt;quarter_stand_alone_abbreviated()

Returns an array reference containing the abbreviated stand-alone
names of the quarters.

=item * $locale-&gt;quarter_stand_alone_narrow()

Returns an array reference containing the narrow stand-alone names of the
quarters.

=item * $locale-&gt;era_wide()

Returns an array reference containing the wide names of the eras, with
"BCE" first.

=item * $locale-&gt;era_abbreviated()

Returns an array reference containing the abbreviated names of the
eras, with "BCE" first.

=item * $locale-&gt;era_narrow()

Returns an array reference containing the abbreviated names of the
eras, with "BCE" first. However, most locales do not differ between
the narrow and abbreviated length of the era.

=item * $locale-&gt;am_pm_abbreviated()

Returns an array reference containing the abbreviated names of "AM"
and "PM".

=item * $locale-&gt;date_format_long()

=item * $locale-&gt;date_format_full()

=item * $locale-&gt;date_format_medium()

=item * $locale-&gt;date_format_short()

Returns the CLDR date pattern of the appropriate length.

=item * $locale-&gt;date_formats()

Returns a hash reference of CLDR date patterns for the date formats,
where the keys are "full", "long", "medium", and "short".

=item * $locale-&gt;time_format_long()

=item * $locale-&gt;time_format_full()

=item * $locale-&gt;time_format_medium()

=item * $locale-&gt;time_format_short()

Returns the CLDR date pattern of the appropriate length.

=item * $locale-&gt;time_formats()

Returns a hash reference of CLDR date patterns for the time formats,
where the keys are "full", "long", "medium", and "short".

=item * $locale-&gt;datetime_format_long()

=item * $locale-&gt;datetime_format_full()

=item * $locale-&gt;datetime_format_medium()

=item * $locale-&gt;datetime_format_short()

Returns the CLDR date pattern of the appropriate length.

=item * $locale-&gt;datetime_formats()

Returns a hash reference of CLDR date patterns for the datetime
formats, where the keys are "full", "long", "medium", and "short".

=item * $locale-&gt;date_format_default()

=item * $locale-&gt;time_format_default()

=item * $locale-&gt;datetime_format_default()

Returns the default CLDR date pattern. The length of this format is
based on the value of C&lt;&lt; $locale-&gt;default_date_format_length() &gt;&gt;
and/or C&lt;&lt; $locale-&gt;default_time_format_length() &gt;&gt;.

=item * $locale-&gt;default_date_format_length()

=item * $locale-&gt;default_time_format_length()

Returns the default length for the format, one of "full", "long",
"medium", or "short".

=item * $locale-&gt;set_default_date_format_length()

=item * $locale-&gt;set_default_time_format_length()

Sets the default length for the format. This must be one of "full",
"long", "medium", or "short".

=item * $locale-&gt;prefers_24_hour_time()

Returns a boolean indicating the preferred hour format for this
locale.

=item * $locale-&gt;first_day_of_week()

Returns a number from 1 to 7 indicating the I&lt;local&gt; first day of the week,
with Monday being 1 and Sunday being 7. For example, for a US locale this
returns 7.

=item * $locale-&gt;available_formats()

A list of format names, like "MMdd" or "yyyyMM". This should be the
list directly supported by the subclass, not its parents.

=item * $locale-&gt;format_for($key)

Given a valid name, returns the CLDR date pattern for that thing, if
one exists.

=back

=head1 SUPPORT

See L&lt;DateTime::Locale&gt;.

Bugs may be submitted at L&lt;https://github.com/houseabsolute/DateTime-Locale/issues&gt;.

There is a mailing list available for users of this distribution,
L&lt;mailto:datetime@perl.org&gt;.

I am also usually active on IRC as 'autarch' on C&lt;irc://irc.perl.org&gt;.

=head1 SOURCE

The source code repository for DateTime-Locale can be found at L&lt;https://github.com/houseabsolute/DateTime-Locale&gt;.

=head1 AUTHOR

Dave Rolsky &lt;autarch@urth.org&gt;

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2003 - 2020 by Dave Rolsky.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

The full text of the license can be found in the
F&lt;LICENSE&gt; file included with this distribution.

=cut
</pre></body></html>