Filename | /usr/share/perl5/DateTime/Locale/Base.pm |
Statements | Executed 215 statements in 4.40ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 109µs | 124µs | BEGIN@11 | DateTime::Locale::Base::
29 | 1 | 1 | 53µs | 53µs | CORE:qr (opcode) | DateTime::Locale::Base::
1 | 1 | 1 | 41µs | 45µs | new | DateTime::Locale::Base::
1 | 1 | 1 | 20µs | 24µs | BEGIN@3 | DateTime::Locale::Base::
1 | 1 | 1 | 19µs | 19µs | BEGIN@7 | DateTime::Locale::Base::
1 | 1 | 1 | 15µs | 69µs | BEGIN@6 | DateTime::Locale::Base::
22 | 2 | 1 | 14µs | 14µs | CORE:subst (opcode) | DateTime::Locale::Base::
1 | 1 | 1 | 12µs | 37µs | BEGIN@363 | DateTime::Locale::Base::
1 | 1 | 1 | 12µs | 26µs | BEGIN@119 | DateTime::Locale::Base::
1 | 1 | 1 | 11µs | 26µs | BEGIN@176 | DateTime::Locale::Base::
1 | 1 | 1 | 11µs | 30µs | BEGIN@25 | DateTime::Locale::Base::
1 | 1 | 1 | 9µs | 52µs | BEGIN@9 | DateTime::Locale::Base::
1 | 1 | 1 | 9µs | 22µs | BEGIN@4 | DateTime::Locale::Base::
1 | 1 | 1 | 6µs | 6µs | BEGIN@8 | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | STORABLE_freeze | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | STORABLE_thaw | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:174] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:218] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:222] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:224] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:226] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:227] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:228] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:231] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:235] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:237] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:239] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:240] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:241] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:244] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:248] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:250] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:252] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:253] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:256] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:257] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:259] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:263] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:265] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:267] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:268] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:26] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:271] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:272] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:280] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:291] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:295] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:299] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:303] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:307] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:311] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:315] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:319] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:323] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:327] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:331] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:335] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:339] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:343] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:347] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:351] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | __ANON__[:361] | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | _available_formats | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | _cldr_to_strftime | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | _convert | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | _convert_to_strftime | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | _make_datetime_format | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | _self_and_super_path | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | _stringify | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | available_formats | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | date_format_default | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | date_formats | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | datetime_format_default | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | default_date_format_length | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | default_time_format_length | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | format_for | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | language_id | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | prefers_24_hour_time | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | script_id | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | set_default_date_format_length | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | set_default_time_format_length | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | territory_id | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | time_format_default | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | time_formats | DateTime::Locale::Base::
0 | 0 | 0 | 0s | 0s | variant_id | DateTime::Locale::Base::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DateTime::Locale::Base; | ||||
2 | |||||
3 | 3 | 29µs | 2 | 28µs | # spent 24µs (20+4) within DateTime::Locale::Base::BEGIN@3 which was called:
# once (20µs+4µs) by DateTime::Locale::BEGIN@10 at line 3 # spent 24µs making 1 call to DateTime::Locale::Base::BEGIN@3
# spent 4µs making 1 call to strict::import |
4 | 3 | 35µs | 2 | 34µs | # spent 22µs (9+13) within DateTime::Locale::Base::BEGIN@4 which was called:
# once (9µs+13µs) by DateTime::Locale::BEGIN@10 at line 4 # spent 22µs making 1 call to DateTime::Locale::Base::BEGIN@4
# spent 13µs making 1 call to warnings::import |
5 | |||||
6 | 3 | 38µs | 2 | 124µs | # spent 69µs (15+54) within DateTime::Locale::Base::BEGIN@6 which was called:
# once (15µs+54µs) by DateTime::Locale::BEGIN@10 at line 6 # spent 69µs making 1 call to DateTime::Locale::Base::BEGIN@6
# spent 54µs making 1 call to Exporter::import |
7 | 3 | 52µs | 1 | 19µs | # spent 19µs within DateTime::Locale::Base::BEGIN@7 which was called:
# once (19µs+0s) by DateTime::Locale::BEGIN@10 at line 7 # spent 19µs making 1 call to DateTime::Locale::Base::BEGIN@7 |
8 | 3 | 26µs | 1 | 6µs | # spent 6µs within DateTime::Locale::Base::BEGIN@8 which was called:
# once (6µs+0s) by DateTime::Locale::BEGIN@10 at line 8 # spent 6µs making 1 call to DateTime::Locale::Base::BEGIN@8 |
9 | 3 | 86µs | 2 | 94µs | # spent 52µs (9+42) within DateTime::Locale::Base::BEGIN@9 which was called:
# once (9µs+42µs) by DateTime::Locale::BEGIN@10 at line 9 # spent 52µs making 1 call to DateTime::Locale::Base::BEGIN@9
# spent 42µs making 1 call to Exporter::import |
10 | |||||
11 | # spent 124µs (109+14) within DateTime::Locale::Base::BEGIN@11 which was called:
# once (109µs+14µs) by DateTime::Locale::BEGIN@10 at line 28 | ||||
12 | 1 | 4µ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 | 37µs | 11 | 9µs | ( my $meth_name = $field ) =~ s/^en_//; # spent 9µs making 11 calls to DateTime::Locale::Base::CORE:subst, avg 818ns/call |
21 | |||||
22 | # also remove 'complete_' | ||||
23 | 11 | 22µs | 11 | 5µs | $meth_name =~ s/complete_//; # spent 5µs making 11 calls to DateTime::Locale::Base::CORE:subst, avg 491ns/call |
24 | |||||
25 | 3 | 59µs | 2 | 49µs | # spent 30µs (11+19) within DateTime::Locale::Base::BEGIN@25 which was called:
# once (11µs+19µs) by DateTime::Locale::BEGIN@10 at line 25 # spent 30µs making 1 call to DateTime::Locale::Base::BEGIN@25
# spent 19µs making 1 call to strict::unimport |
26 | 11 | 60µs | *{$meth_name} = sub { $_[0]->{$field} }; | ||
27 | } | ||||
28 | 1 | 528µs | 1 | 124µs | } # spent 124µs making 1 call to DateTime::Locale::Base::BEGIN@11 |
29 | |||||
30 | # spent 45µs (41+4) within DateTime::Locale::Base::new which was called:
# once (41µs+4µs) by DateTime::Locale::_load_class_from_id at line 286 of DateTime/Locale.pm | ||||
31 | 1 | 1µs | 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 | 33µs | 2 | 4µs | return bless { # spent 2µs making 1 call to DateTime::Locale::root::_default_date_format_length
# spent 2µs 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 | 2µ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 | 3 | 395µs | 2 | 41µs | # spent 26µs (12+15) within DateTime::Locale::Base::BEGIN@119 which was called:
# once (12µs+15µs) by DateTime::Locale::BEGIN@10 at line 119 # spent 26µs making 1 call to DateTime::Locale::Base::BEGIN@119
# spent 15µ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 | 2µs | for my $length (qw( full long medium short )) { | ||
162 | 4 | 3µ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 | 9µs | }; | ||
175 | |||||
176 | 3 | 1.76ms | 2 | 41µs | # spent 26µs (11+15) within DateTime::Locale::Base::BEGIN@176 which was called:
# once (11µs+15µs) by DateTime::Locale::BEGIN@10 at line 176 # spent 26µs making 1 call to DateTime::Locale::Base::BEGIN@176
# spent 15µs making 1 call to strict::unimport |
177 | 4 | 12µ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 | 1µs | 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 | 87µs | ); | ||
353 | |||||
354 | 1 | 9µs | for my $name ( keys %subs ) { | ||
355 | 43 | 18µ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 | 123µs | }; | ||
362 | |||||
363 | 3 | 693µs | 2 | 61µs | # spent 37µs (12+24) within DateTime::Locale::Base::BEGIN@363 which was called:
# once (12µs+24µs) by DateTime::Locale::BEGIN@10 at line 363 # spent 37µs making 1 call to DateTime::Locale::Base::BEGIN@363
# spent 24µs making 1 call to strict::unimport |
364 | 43 | 127µ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 | 124µs | 29 | 53µs | my @JavaPatterns = ( # spent 53µs making 29 calls to DateTime::Locale::Base::CORE:qr, avg 2µs/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 | 29µs | 1; | ||
473 | |||||
474 | __END__ | ||||
# spent 53µs within DateTime::Locale::Base::CORE:qr which was called 29 times, avg 2µs/call:
# 29 times (53µs+0s) by DateTime::Locale::BEGIN@10 at line 385, avg 2µs/call | |||||
sub DateTime::Locale::Base::CORE:subst; # opcode |