| Filename | /usr/share/perl5/DateTime/Locale/Base.pm |
| Statements | Executed 205 statements in 3.49ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 999µs | 1.70ms | DateTime::Locale::Base::BEGIN@8 |
| 1 | 1 | 1 | 149µs | 161µs | DateTime::Locale::Base::BEGIN@11 |
| 1 | 1 | 1 | 18µs | 19µs | DateTime::Locale::Base::new |
| 29 | 1 | 1 | 15µs | 15µs | DateTime::Locale::Base::CORE:qr (opcode) |
| 22 | 2 | 1 | 12µs | 12µs | DateTime::Locale::Base::CORE:subst (opcode) |
| 1 | 1 | 1 | 11µs | 22µs | DateTime::Locale::Base::BEGIN@3 |
| 1 | 1 | 1 | 9µs | 18µs | DateTime::Locale::Base::BEGIN@119 |
| 1 | 1 | 1 | 8µs | 32µs | DateTime::Locale::Base::BEGIN@9 |
| 1 | 1 | 1 | 7µs | 36µs | DateTime::Locale::Base::BEGIN@6 |
| 1 | 1 | 1 | 7µs | 16µs | DateTime::Locale::Base::BEGIN@363 |
| 1 | 1 | 1 | 7µs | 10µs | DateTime::Locale::Base::BEGIN@4 |
| 1 | 1 | 1 | 6µs | 15µs | DateTime::Locale::Base::BEGIN@176 |
| 1 | 1 | 1 | 6µs | 6µs | DateTime::Locale::Base::BEGIN@7 |
| 1 | 1 | 1 | 6µs | 16µs | DateTime::Locale::Base::BEGIN@25 |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::STORABLE_freeze |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::STORABLE_thaw |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:174] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:218] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:222] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:224] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:226] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:227] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:228] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:231] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:235] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:237] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:239] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:240] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:241] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:244] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:248] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:250] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:252] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:253] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:256] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:257] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:259] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:263] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:265] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:267] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:268] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:26] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:271] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:272] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:280] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:291] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:295] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:299] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:303] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:307] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:311] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:315] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:319] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:323] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:327] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:331] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:335] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:339] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:343] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:347] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:351] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::__ANON__[:361] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::_available_formats |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::_cldr_to_strftime |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::_convert |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::_convert_to_strftime |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::_make_datetime_format |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::_self_and_super_path |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::_stringify |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::available_formats |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::date_format_default |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::date_formats |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::datetime_format_default |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::default_date_format_length |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::default_time_format_length |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::format_for |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::language_id |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::prefers_24_hour_time |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::script_id |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::set_default_date_format_length |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::set_default_time_format_length |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::territory_id |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::time_format_default |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::time_formats |
| 0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::variant_id |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::Locale::Base; | ||||
| 2 | |||||
| 3 | 2 | 22µs | 2 | 32µs | # spent 22µs (11+11) within DateTime::Locale::Base::BEGIN@3 which was called:
# once (11µs+11µs) by DateTime::Locale::BEGIN@10 at line 3 # spent 22µs making 1 call to DateTime::Locale::Base::BEGIN@3
# spent 10µs making 1 call to strict::import |
| 4 | 2 | 22µs | 2 | 14µs | # spent 10µs (7+4) within DateTime::Locale::Base::BEGIN@4 which was called:
# once (7µs+4µs) by DateTime::Locale::BEGIN@10 at line 4 # spent 10µs making 1 call to DateTime::Locale::Base::BEGIN@4
# spent 4µs making 1 call to warnings::import |
| 5 | |||||
| 6 | 2 | 21µs | 2 | 64µs | # spent 36µs (7+28) within DateTime::Locale::Base::BEGIN@6 which was called:
# once (7µs+28µs) by DateTime::Locale::BEGIN@10 at line 6 # spent 36µs making 1 call to DateTime::Locale::Base::BEGIN@6
# spent 28µs making 1 call to Exporter::import |
| 7 | 2 | 24µs | 1 | 6µs | # spent 6µs within DateTime::Locale::Base::BEGIN@7 which was called:
# once (6µs+0s) by DateTime::Locale::BEGIN@10 at line 7 # spent 6µs making 1 call to DateTime::Locale::Base::BEGIN@7 |
| 8 | 2 | 647µs | 1 | 1.70ms | # spent 1.70ms (999µs+703µs) within DateTime::Locale::Base::BEGIN@8 which was called:
# once (999µs+703µs) by DateTime::Locale::BEGIN@10 at line 8 # spent 1.70ms making 1 call to DateTime::Locale::Base::BEGIN@8 |
| 9 | 2 | 66µs | 2 | 55µs | # spent 32µs (8+24) within DateTime::Locale::Base::BEGIN@9 which was called:
# once (8µs+24µs) by DateTime::Locale::BEGIN@10 at line 9 # spent 32µs making 1 call to DateTime::Locale::Base::BEGIN@9
# spent 24µs making 1 call to Exporter::import |
| 10 | |||||
| 11 | # spent 161µs (149+12) within DateTime::Locale::Base::BEGIN@11 which was called:
# once (149µs+12µs) by DateTime::Locale::BEGIN@10 at line 28 | ||||
| 12 | 1 | 3µs | foreach my $field ( | ||
| 13 | qw( id en_complete_name native_complete_name | ||||
| 14 | en_language en_script en_territory en_variant | ||||
| 15 | native_language native_script native_territory native_variant | ||||
| 16 | ) | ||||
| 17 | ) { | ||||
| 18 | |||||
| 19 | # remove leading 'en_' for method name | ||||
| 20 | 11 | 113µs | 11 | 8µs | ( my $meth_name = $field ) =~ s/^en_//; # spent 8µs making 11 calls to DateTime::Locale::Base::CORE:subst, avg 773ns/call |
| 21 | |||||
| 22 | # also remove 'complete_' | ||||
| 23 | 11 | 14µs | 11 | 4µs | $meth_name =~ s/complete_//; # spent 4µs making 11 calls to DateTime::Locale::Base::CORE:subst, avg 355ns/call |
| 24 | |||||
| 25 | 2 | 44µs | 2 | 26µs | # spent 16µs (6+10) within DateTime::Locale::Base::BEGIN@25 which was called:
# once (6µs+10µs) by DateTime::Locale::BEGIN@10 at line 25 # spent 16µs making 1 call to DateTime::Locale::Base::BEGIN@25
# spent 10µs making 1 call to strict::unimport |
| 26 | 11 | 31µs | *{$meth_name} = sub { $_[0]->{$field} }; | ||
| 27 | } | ||||
| 28 | 1 | 382µs | 1 | 161µs | } # spent 161µs making 1 call to DateTime::Locale::Base::BEGIN@11 |
| 29 | |||||
| 30 | # spent 19µs (18+1) within DateTime::Locale::Base::new which was called:
# once (18µs+1µs) by DateTime::Locale::_load_class_from_id at line 286 of DateTime/Locale.pm | ||||
| 31 | 1 | 500ns | my $class = shift; | ||
| 32 | |||||
| 33 | # By making the default format lengths part of the object's hash | ||||
| 34 | # key, it allows them to be settable. | ||||
| 35 | 1 | 13µs | 2 | 2µs | return bless { # spent 900ns making 1 call to DateTime::Locale::root::_default_date_format_length
# spent 600ns making 1 call to DateTime::Locale::root::_default_time_format_length |
| 36 | @_, | ||||
| 37 | default_date_format_length => $class->_default_date_format_length(), | ||||
| 38 | default_time_format_length => $class->_default_time_format_length(), | ||||
| 39 | }, $class; | ||||
| 40 | } | ||||
| 41 | |||||
| 42 | sub language_id { ( DateTime::Locale::_parse_id( $_[0]->id ) )[0] } | ||||
| 43 | sub script_id { ( DateTime::Locale::_parse_id( $_[0]->id ) )[1] } | ||||
| 44 | sub territory_id { ( DateTime::Locale::_parse_id( $_[0]->id ) )[2] } | ||||
| 45 | sub variant_id { ( DateTime::Locale::_parse_id( $_[0]->id ) )[3] } | ||||
| 46 | |||||
| 47 | 1 | 1µs | my @FormatLengths = qw( short medium long full ); | ||
| 48 | |||||
| 49 | sub date_format_default { | ||||
| 50 | my $meth = 'date_format_' . $_[0]->default_date_format_length(); | ||||
| 51 | $_[0]->$meth(); | ||||
| 52 | } | ||||
| 53 | |||||
| 54 | sub date_formats { | ||||
| 55 | return { | ||||
| 56 | map { | ||||
| 57 | my $meth = 'date_format_' . $_; | ||||
| 58 | $_ => $_[0]->$meth() | ||||
| 59 | } @FormatLengths | ||||
| 60 | }; | ||||
| 61 | } | ||||
| 62 | |||||
| 63 | sub time_format_default { | ||||
| 64 | my $meth = 'time_format_' . $_[0]->default_time_format_length(); | ||||
| 65 | $_[0]->$meth(); | ||||
| 66 | } | ||||
| 67 | |||||
| 68 | sub time_formats { | ||||
| 69 | return { | ||||
| 70 | map { | ||||
| 71 | my $meth = 'time_format_' . $_; | ||||
| 72 | $_ => $_[0]->$meth() | ||||
| 73 | } @FormatLengths | ||||
| 74 | }; | ||||
| 75 | } | ||||
| 76 | |||||
| 77 | sub format_for { | ||||
| 78 | my $self = shift; | ||||
| 79 | my $for = shift; | ||||
| 80 | |||||
| 81 | my $meth = '_format_for_' . $for; | ||||
| 82 | |||||
| 83 | return unless $self->can($meth); | ||||
| 84 | |||||
| 85 | return $self->$meth(); | ||||
| 86 | } | ||||
| 87 | |||||
| 88 | sub available_formats { | ||||
| 89 | my $self = shift; | ||||
| 90 | |||||
| 91 | # The various parens seem to be necessary to force uniq() to see | ||||
| 92 | # the caller's list context. Go figure. | ||||
| 93 | my @uniq | ||||
| 94 | = List::MoreUtils::uniq( | ||||
| 95 | map { keys %{ $_->_available_formats() || {} } } | ||||
| 96 | _self_and_super_path( ref $self ) ); | ||||
| 97 | |||||
| 98 | # Doing the sort in the same expression doesn't work under 5.6.x. | ||||
| 99 | return sort @uniq; | ||||
| 100 | } | ||||
| 101 | |||||
| 102 | # Copied wholesale from Class::ISA, because said module warns as deprecated | ||||
| 103 | # with perl 5.11.0+, which is kind of annoying. | ||||
| 104 | sub _self_and_super_path { | ||||
| 105 | # Assumption: searching is depth-first. | ||||
| 106 | # Assumption: '' (empty string) can't be a class package name. | ||||
| 107 | # Note: 'UNIVERSAL' is not given any special treatment. | ||||
| 108 | return () unless @_; | ||||
| 109 | |||||
| 110 | my @out = (); | ||||
| 111 | |||||
| 112 | my @in_stack = ($_[0]); | ||||
| 113 | my %seen = ($_[0] => 1); | ||||
| 114 | |||||
| 115 | my $current; | ||||
| 116 | while(@in_stack) { | ||||
| 117 | next unless defined($current = shift @in_stack) && length($current); | ||||
| 118 | push @out, $current; | ||||
| 119 | 2 | 299µs | 2 | 27µs | # spent 18µs (9+9) within DateTime::Locale::Base::BEGIN@119 which was called:
# once (9µs+9µs) by DateTime::Locale::BEGIN@10 at line 119 # spent 18µs making 1 call to DateTime::Locale::Base::BEGIN@119
# spent 9µs making 1 call to strict::unimport |
| 120 | unshift @in_stack, | ||||
| 121 | map | ||||
| 122 | { my $c = $_; # copy, to avoid being destructive | ||||
| 123 | substr($c,0,2) = "main::" if substr($c,0,2) eq '::'; | ||||
| 124 | # Canonize the :: -> main::, ::foo -> main::foo thing. | ||||
| 125 | # Should I ever canonize the Foo'Bar = Foo::Bar thing? | ||||
| 126 | $seen{$c}++ ? () : $c; | ||||
| 127 | } | ||||
| 128 | @{"$current\::ISA"} | ||||
| 129 | ; | ||||
| 130 | # I.e., if this class has any parents (at least, ones I've never seen | ||||
| 131 | # before), push them, in order, onto the stack of classes I need to | ||||
| 132 | # explore. | ||||
| 133 | } | ||||
| 134 | |||||
| 135 | return @out; | ||||
| 136 | } | ||||
| 137 | |||||
| 138 | # Just needed for the above method. | ||||
| 139 | sub _available_formats { } | ||||
| 140 | |||||
| 141 | sub default_date_format_length { $_[0]->{default_date_format_length} } | ||||
| 142 | |||||
| 143 | sub set_default_date_format_length { | ||||
| 144 | my $self = shift; | ||||
| 145 | my ($l) | ||||
| 146 | = validate_pos( @_, { regex => qr/^(?:full|long|medium|short)$/i } ); | ||||
| 147 | |||||
| 148 | $self->{default_date_format_length} = lc $l; | ||||
| 149 | } | ||||
| 150 | |||||
| 151 | sub default_time_format_length { $_[0]->{default_time_format_length} } | ||||
| 152 | |||||
| 153 | sub set_default_time_format_length { | ||||
| 154 | my $self = shift; | ||||
| 155 | my ($l) | ||||
| 156 | = validate_pos( @_, { regex => qr/^(?:full|long|medium|short)/i } ); | ||||
| 157 | |||||
| 158 | $self->{default_time_format_length} = lc $l; | ||||
| 159 | } | ||||
| 160 | |||||
| 161 | 1 | 600ns | for my $length (qw( full long medium short )) { | ||
| 162 | 4 | 2µs | my $key = 'datetime_format_' . $length; | ||
| 163 | |||||
| 164 | my $sub = sub { | ||||
| 165 | my $self = shift; | ||||
| 166 | |||||
| 167 | return $self->{$key} if exists $self->{$key}; | ||||
| 168 | |||||
| 169 | my $date_meth = 'date_format_' . $length; | ||||
| 170 | my $time_meth = 'time_format_' . $length; | ||||
| 171 | |||||
| 172 | return $self->{$key} | ||||
| 173 | = $self->_make_datetime_format( $date_meth, $time_meth ); | ||||
| 174 | 4 | 5µs | }; | ||
| 175 | |||||
| 176 | 2 | 1.05ms | 2 | 23µs | # spent 15µs (6+8) within DateTime::Locale::Base::BEGIN@176 which was called:
# once (6µs+8µs) by DateTime::Locale::BEGIN@10 at line 176 # spent 15µs making 1 call to DateTime::Locale::Base::BEGIN@176
# spent 8µs making 1 call to strict::unimport |
| 177 | 4 | 10µs | *{$key} = $sub; | ||
| 178 | } | ||||
| 179 | |||||
| 180 | sub datetime_format_default { | ||||
| 181 | my $self = shift; | ||||
| 182 | |||||
| 183 | my $date_meth = 'date_format_' . $self->default_date_format_length(); | ||||
| 184 | my $time_meth = 'time_format_' . $self->default_time_format_length(); | ||||
| 185 | |||||
| 186 | return $self->_make_datetime_format( $date_meth, $time_meth ); | ||||
| 187 | } | ||||
| 188 | |||||
| 189 | sub _make_datetime_format { | ||||
| 190 | my $self = shift; | ||||
| 191 | my $date_meth = shift; | ||||
| 192 | my $time_meth = shift; | ||||
| 193 | |||||
| 194 | my $dt_format = $self->datetime_format(); | ||||
| 195 | |||||
| 196 | my $time = $self->$time_meth(); | ||||
| 197 | my $date = $self->$date_meth(); | ||||
| 198 | |||||
| 199 | $dt_format =~ s/\{0\}/$time/g; | ||||
| 200 | $dt_format =~ s/\{1\}/$date/g; | ||||
| 201 | |||||
| 202 | return $dt_format; | ||||
| 203 | } | ||||
| 204 | |||||
| 205 | sub prefers_24_hour_time { | ||||
| 206 | my $self = shift; | ||||
| 207 | |||||
| 208 | return $self->{prefers_24_hour_time} | ||||
| 209 | if exists $self->{prefers_24_hour_time}; | ||||
| 210 | |||||
| 211 | $self->{prefers_24_hour_time} | ||||
| 212 | = $self->time_format_short() =~ /h|K/ ? 0 : 1; | ||||
| 213 | } | ||||
| 214 | |||||
| 215 | # Backwards compat for DateTime.pm version <= 0.42 | ||||
| 216 | { | ||||
| 217 | 1 | 400ns | my %subs = ( | ||
| 218 | month_name => sub { $_[0]->month_format_wide()->[ $_[1]->month_0 ] }, | ||||
| 219 | |||||
| 220 | month_abbreviation => sub { | ||||
| 221 | $_[0]->month_format_abbreviated()->[ $_[1]->month_0 ]; | ||||
| 222 | }, | ||||
| 223 | month_narrow => | ||||
| 224 | sub { $_[0]->month_format_narrow()->[ $_[1]->month_0 ]; }, | ||||
| 225 | |||||
| 226 | month_names => sub { $_[0]->month_format_wide() }, | ||||
| 227 | month_abbreviations => sub { $_[0]->month_format_abbreviated() }, | ||||
| 228 | month_narrows => sub { $_[0]->month_format_narrow() }, | ||||
| 229 | |||||
| 230 | day_name => | ||||
| 231 | sub { $_[0]->day_format_wide()->[ $_[1]->day_of_week_0 ] }, | ||||
| 232 | |||||
| 233 | day_abbreviation => sub { | ||||
| 234 | $_[0]->day_format_abbreviated()->[ $_[1]->day_of_week_0 ]; | ||||
| 235 | }, | ||||
| 236 | day_narrow => | ||||
| 237 | sub { $_[0]->day_format_narrow()->[ $_[1]->day_of_week_0 ]; }, | ||||
| 238 | |||||
| 239 | day_names => sub { $_[0]->day_format_wide() }, | ||||
| 240 | day_abbreviations => sub { $_[0]->day_format_abbreviated() }, | ||||
| 241 | day_narrows => sub { $_[0]->day_format_narrow() }, | ||||
| 242 | |||||
| 243 | quarter_name => | ||||
| 244 | sub { $_[0]->quarter_format_wide()->[ $_[1]->quarter - 1 ] }, | ||||
| 245 | |||||
| 246 | quarter_abbreviation => sub { | ||||
| 247 | $_[0]->quarter_format_abbreviated()->[ $_[1]->quarter - 1 ]; | ||||
| 248 | }, | ||||
| 249 | quarter_narrow => | ||||
| 250 | sub { $_[0]->quarter_format_narrow()->[ $_[1]->quarter - 1 ] }, | ||||
| 251 | |||||
| 252 | quarter_names => sub { $_[0]->quarter_format_wide() }, | ||||
| 253 | quarter_abbreviations => sub { $_[0]->quarter_format_abbreviated() }, | ||||
| 254 | |||||
| 255 | am_pm => | ||||
| 256 | sub { $_[0]->am_pm_abbreviated()->[ $_[1]->hour < 12 ? 0 : 1 ] }, | ||||
| 257 | am_pms => sub { $_[0]->am_pm_abbreviated() }, | ||||
| 258 | |||||
| 259 | era_name => sub { $_[0]->era_wide()->[ $_[1]->ce_year < 0 ? 0 : 1 ] }, | ||||
| 260 | |||||
| 261 | era_abbreviation => sub { | ||||
| 262 | $_[0]->era_abbreviated()->[ $_[1]->ce_year < 0 ? 0 : 1 ]; | ||||
| 263 | }, | ||||
| 264 | era_narrow => | ||||
| 265 | sub { $_[0]->era_narrow()->[ $_[1]->ce_year < 0 ? 0 : 1 ] }, | ||||
| 266 | |||||
| 267 | era_names => sub { $_[0]->era_wide() }, | ||||
| 268 | era_abbreviations => sub { $_[0]->era_abbreviated() }, | ||||
| 269 | |||||
| 270 | # ancient backwards compat | ||||
| 271 | era => sub { $_[0]->era_abbreviation }, | ||||
| 272 | eras => sub { $_[0]->era_abbreviations }, | ||||
| 273 | |||||
| 274 | date_before_time => sub { | ||||
| 275 | my $self = shift; | ||||
| 276 | |||||
| 277 | my $dt_format = $self->datetime_format(); | ||||
| 278 | |||||
| 279 | return $dt_format =~ /\{1\}.*\{0\}/ ? 1 : 0; | ||||
| 280 | }, | ||||
| 281 | |||||
| 282 | date_parts_order => sub { | ||||
| 283 | my $self = shift; | ||||
| 284 | |||||
| 285 | my $short = $self->date_format_short(); | ||||
| 286 | |||||
| 287 | $short =~ tr{dmyDMY}{}cd; | ||||
| 288 | $short =~ tr{dmyDMY}{dmydmy}s; | ||||
| 289 | |||||
| 290 | return $short; | ||||
| 291 | }, | ||||
| 292 | |||||
| 293 | full_date_format => sub { | ||||
| 294 | $_[0]->_convert_to_strftime( $_[0]->date_format_full() ); | ||||
| 295 | }, | ||||
| 296 | |||||
| 297 | long_date_format => sub { | ||||
| 298 | $_[0]->_convert_to_strftime( $_[0]->date_format_long() ); | ||||
| 299 | }, | ||||
| 300 | |||||
| 301 | medium_date_format => sub { | ||||
| 302 | $_[0]->_convert_to_strftime( $_[0]->date_format_medium() ); | ||||
| 303 | }, | ||||
| 304 | |||||
| 305 | short_date_format => sub { | ||||
| 306 | $_[0]->_convert_to_strftime( $_[0]->date_format_short() ); | ||||
| 307 | }, | ||||
| 308 | |||||
| 309 | default_date_format => sub { | ||||
| 310 | $_[0]->_convert_to_strftime( $_[0]->date_format_default() ); | ||||
| 311 | }, | ||||
| 312 | |||||
| 313 | full_time_format => sub { | ||||
| 314 | $_[0]->_convert_to_strftime( $_[0]->time_format_full() ); | ||||
| 315 | }, | ||||
| 316 | |||||
| 317 | long_time_format => sub { | ||||
| 318 | $_[0]->_convert_to_strftime( $_[0]->time_format_long() ); | ||||
| 319 | }, | ||||
| 320 | |||||
| 321 | medium_time_format => sub { | ||||
| 322 | $_[0]->_convert_to_strftime( $_[0]->time_format_medium() ); | ||||
| 323 | }, | ||||
| 324 | |||||
| 325 | short_time_format => sub { | ||||
| 326 | $_[0]->_convert_to_strftime( $_[0]->time_format_short() ); | ||||
| 327 | }, | ||||
| 328 | |||||
| 329 | default_time_format => sub { | ||||
| 330 | $_[0]->_convert_to_strftime( $_[0]->time_format_default() ); | ||||
| 331 | }, | ||||
| 332 | |||||
| 333 | full_datetime_format => sub { | ||||
| 334 | $_[0]->_convert_to_strftime( $_[0]->datetime_format_full() ); | ||||
| 335 | }, | ||||
| 336 | |||||
| 337 | long_datetime_format => sub { | ||||
| 338 | $_[0]->_convert_to_strftime( $_[0]->datetime_format_long() ); | ||||
| 339 | }, | ||||
| 340 | |||||
| 341 | medium_datetime_format => sub { | ||||
| 342 | $_[0]->_convert_to_strftime( $_[0]->datetime_format_medium() ); | ||||
| 343 | }, | ||||
| 344 | |||||
| 345 | short_datetime_format => sub { | ||||
| 346 | $_[0]->_convert_to_strftime( $_[0]->datetime_format_short() ); | ||||
| 347 | }, | ||||
| 348 | |||||
| 349 | default_datetime_format => sub { | ||||
| 350 | $_[0]->_convert_to_strftime( $_[0]->datetime_format_default() ); | ||||
| 351 | }, | ||||
| 352 | 1 | 40µs | ); | ||
| 353 | |||||
| 354 | 1 | 5µs | for my $name ( keys %subs ) { | ||
| 355 | 43 | 6µs | my $real_sub = $subs{$name}; | ||
| 356 | |||||
| 357 | my $sub = sub { | ||||
| 358 | carp | ||||
| 359 | "The $name method in DateTime::Locale::Base has been deprecated. Please see the DateTime::Locale distribution's Changes file for details"; | ||||
| 360 | return shift->$real_sub(@_); | ||||
| 361 | 43 | 42µs | }; | ||
| 362 | |||||
| 363 | 2 | 526µs | 2 | 24µs | # spent 16µs (7+9) within DateTime::Locale::Base::BEGIN@363 which was called:
# once (7µs+9µs) by DateTime::Locale::BEGIN@10 at line 363 # spent 16µs making 1 call to DateTime::Locale::Base::BEGIN@363
# spent 9µs making 1 call to strict::unimport |
| 364 | 43 | 42µs | *{$name} = $sub; | ||
| 365 | } | ||||
| 366 | } | ||||
| 367 | |||||
| 368 | # Older versions of DateTime.pm will not pass in the $cldr_ok flag, so | ||||
| 369 | # we will give them the converted-to-strftime pattern (bugs and all). | ||||
| 370 | sub _convert_to_strftime { | ||||
| 371 | my $self = shift; | ||||
| 372 | my $pattern = shift; | ||||
| 373 | my $cldr_ok = shift; | ||||
| 374 | |||||
| 375 | return $pattern if $cldr_ok; | ||||
| 376 | |||||
| 377 | return $self->{_converted_patterns}{$pattern} | ||||
| 378 | if exists $self->{_converted_patterns}{$pattern}; | ||||
| 379 | |||||
| 380 | return $self->{_converted_patterns}{$pattern} | ||||
| 381 | = $self->_cldr_to_strftime($pattern); | ||||
| 382 | } | ||||
| 383 | |||||
| 384 | { | ||||
| 385 | 2 | 45µs | 29 | 15µs | my @JavaPatterns = ( # spent 15µs making 29 calls to DateTime::Locale::Base::CORE:qr, avg 528ns/call |
| 386 | qr/G/ => '{era}', | ||||
| 387 | qr/yyyy/ => '{ce_year}', | ||||
| 388 | qr/y/ => 'y', | ||||
| 389 | qr/u/ => 'Y', | ||||
| 390 | qr/MMMM/ => 'B', | ||||
| 391 | qr/MMM/ => 'b', | ||||
| 392 | qr/MM/ => 'm', | ||||
| 393 | qr/M/ => '{month}', | ||||
| 394 | qr/dd/ => 'd', | ||||
| 395 | qr/d/ => '{day}', | ||||
| 396 | qr/hh/ => 'l', | ||||
| 397 | qr/h/ => '{hour_12}', | ||||
| 398 | qr/HH/ => 'H', | ||||
| 399 | qr/H/ => '{hour}', | ||||
| 400 | qr/mm/ => 'M', | ||||
| 401 | qr/m/ => '{minute}', | ||||
| 402 | qr/ss/ => 'S', | ||||
| 403 | qr/s/ => '{second}', | ||||
| 404 | qr/S/ => 'N', | ||||
| 405 | qr/EEEE/ => 'A', | ||||
| 406 | qr/E/ => 'a', | ||||
| 407 | qr/D/ => 'j', | ||||
| 408 | qr/F/ => '{weekday_of_month}', | ||||
| 409 | qr/w/ => 'V', | ||||
| 410 | qr/W/ => '{week_month}', | ||||
| 411 | qr/a/ => 'p', | ||||
| 412 | qr/k/ => '{hour_1}', | ||||
| 413 | qr/K/ => '{hour_12_0}', | ||||
| 414 | qr/z/ => '{time_zone_long_name}', | ||||
| 415 | ); | ||||
| 416 | |||||
| 417 | sub _cldr_to_strftime { | ||||
| 418 | shift; | ||||
| 419 | my $simple = shift; | ||||
| 420 | |||||
| 421 | $simple | ||||
| 422 | =~ s/(G+|y+|u+|M+|d+|h+|H+|m+|s+|S+|E+|D+|F+|w+|W+|a+|k+|K+|z+)|'((?:[^']|'')*)'/ | ||||
| 423 | $2 ? _stringify($2) : $1 ? _convert($1) : "'"/eg; | ||||
| 424 | |||||
| 425 | return $simple; | ||||
| 426 | } | ||||
| 427 | |||||
| 428 | sub _convert { | ||||
| 429 | my $simple = shift; | ||||
| 430 | |||||
| 431 | for ( my $x = 0; $x < @JavaPatterns; $x += 2 ) { | ||||
| 432 | return '%' . $JavaPatterns[ $x + 1 ] | ||||
| 433 | if $simple =~ /$JavaPatterns[$x]/; | ||||
| 434 | } | ||||
| 435 | |||||
| 436 | die "**Dont know $simple***"; | ||||
| 437 | } | ||||
| 438 | |||||
| 439 | sub _stringify { | ||||
| 440 | my $string = shift; | ||||
| 441 | |||||
| 442 | $string =~ s/%(?:[^%])/%%/g; | ||||
| 443 | $string =~ s/\'\'/\'/g; | ||||
| 444 | |||||
| 445 | return $string; | ||||
| 446 | } | ||||
| 447 | } | ||||
| 448 | |||||
| 449 | # end backwards compat | ||||
| 450 | |||||
| 451 | sub STORABLE_freeze { | ||||
| 452 | my $self = shift; | ||||
| 453 | my $cloning = shift; | ||||
| 454 | |||||
| 455 | return if $cloning; | ||||
| 456 | |||||
| 457 | return $self->id(); | ||||
| 458 | } | ||||
| 459 | |||||
| 460 | sub STORABLE_thaw { | ||||
| 461 | my $self = shift; | ||||
| 462 | my $cloning = shift; | ||||
| 463 | my $serialized = shift; | ||||
| 464 | |||||
| 465 | my $obj = DateTime::Locale->load($serialized); | ||||
| 466 | |||||
| 467 | %$self = %$obj; | ||||
| 468 | |||||
| 469 | return $self; | ||||
| 470 | } | ||||
| 471 | |||||
| 472 | 1 | 12µs | 1; | ||
| 473 | |||||
| 474 | __END__ | ||||
# spent 15µs within DateTime::Locale::Base::CORE:qr which was called 29 times, avg 528ns/call:
# 29 times (15µs+0s) by DateTime::Locale::BEGIN@10 at line 385, avg 528ns/call | |||||
sub DateTime::Locale::Base::CORE:subst; # opcode |