Filename | /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/DateTime/Locale/FromData.pm |
Statements | Executed 138 statements in 1.37ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 386µs | 486µs | BEGIN@6 | DateTime::Locale::FromData::
1 | 1 | 1 | 122µs | 122µs | BEGIN@13 | DateTime::Locale::FromData::
1 | 1 | 1 | 26µs | 26µs | new | DateTime::Locale::FromData::
1 | 1 | 1 | 21µs | 26µs | BEGIN@3 | DateTime::Locale::FromData::
1 | 1 | 1 | 9µs | 20µs | BEGIN@4 | DateTime::Locale::FromData::
1 | 1 | 1 | 9µs | 30µs | BEGIN@7 | DateTime::Locale::FromData::
1 | 1 | 1 | 8µs | 17µs | BEGIN@89 | DateTime::Locale::FromData::
1 | 1 | 1 | 7µs | 21µs | BEGIN@70 | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | STORABLE_freeze | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | STORABLE_thaw | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | __ANON__[:68] | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | __ANON__[:86] | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | _available_formats | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | _make_datetime_format | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | available_formats | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | date_format_default | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | date_formats | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | datetime_format | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | datetime_format_default | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | format_for | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | id | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | language_code | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | language_id | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | prefers_24_hour_time | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | script_code | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | script_id | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | set_default_date_format_length | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | set_default_time_format_length | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | territory_code | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | territory_id | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | time_format_default | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | time_formats | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | variant_code | DateTime::Locale::FromData::
0 | 0 | 0 | 0s | 0s | variant_id | DateTime::Locale::FromData::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DateTime::Locale::FromData; | ||||
2 | |||||
3 | 2 | 27µs | 2 | 31µs | # spent 26µs (21+5) within DateTime::Locale::FromData::BEGIN@3 which was called:
# once (21µs+5µs) by DateTime::Locale::BEGIN@11 at line 3 # spent 26µs making 1 call to DateTime::Locale::FromData::BEGIN@3
# spent 5µs making 1 call to strict::import |
4 | 2 | 28µs | 2 | 31µs | # spent 20µs (9+11) within DateTime::Locale::FromData::BEGIN@4 which was called:
# once (9µs+11µs) by DateTime::Locale::BEGIN@11 at line 4 # spent 20µs making 1 call to DateTime::Locale::FromData::BEGIN@4
# spent 11µs making 1 call to warnings::import |
5 | |||||
6 | 2 | 135µs | 2 | 534µs | # spent 486µs (386+101) within DateTime::Locale::FromData::BEGIN@6 which was called:
# once (386µs+101µs) by DateTime::Locale::BEGIN@11 at line 6 # spent 486µs making 1 call to DateTime::Locale::FromData::BEGIN@6
# spent 48µs making 1 call to Exporter::import |
7 | 2 | 114µs | 2 | 51µs | # spent 30µs (9+21) within DateTime::Locale::FromData::BEGIN@7 which was called:
# once (9µs+21µs) by DateTime::Locale::BEGIN@11 at line 7 # spent 30µs making 1 call to DateTime::Locale::FromData::BEGIN@7
# spent 21µs making 1 call to Exporter::import |
8 | |||||
9 | 1 | 500ns | our $VERSION = '1.03'; | ||
10 | |||||
11 | 1 | 200ns | my @FormatLengths; | ||
12 | |||||
13 | # spent 122µs within DateTime::Locale::FromData::BEGIN@13 which was called:
# once (122µs+0s) by DateTime::Locale::BEGIN@11 at line 92 | ||||
14 | 1 | 4µs | my @methods = qw( | ||
15 | code | ||||
16 | name | ||||
17 | language | ||||
18 | script | ||||
19 | territory | ||||
20 | variant | ||||
21 | native_name | ||||
22 | native_language | ||||
23 | native_script | ||||
24 | native_territory | ||||
25 | native_variant | ||||
26 | am_pm_abbreviated | ||||
27 | date_format_full | ||||
28 | date_format_long | ||||
29 | date_format_medium | ||||
30 | date_format_short | ||||
31 | time_format_full | ||||
32 | time_format_long | ||||
33 | time_format_medium | ||||
34 | time_format_short | ||||
35 | day_format_abbreviated | ||||
36 | day_format_narrow | ||||
37 | day_format_wide | ||||
38 | day_stand_alone_abbreviated | ||||
39 | day_stand_alone_narrow | ||||
40 | day_stand_alone_wide | ||||
41 | month_format_abbreviated | ||||
42 | month_format_narrow | ||||
43 | month_format_wide | ||||
44 | month_stand_alone_abbreviated | ||||
45 | month_stand_alone_narrow | ||||
46 | month_stand_alone_wide | ||||
47 | quarter_format_abbreviated | ||||
48 | quarter_format_narrow | ||||
49 | quarter_format_wide | ||||
50 | quarter_stand_alone_abbreviated | ||||
51 | quarter_stand_alone_narrow | ||||
52 | quarter_stand_alone_wide | ||||
53 | era_abbreviated | ||||
54 | era_narrow | ||||
55 | era_wide | ||||
56 | default_date_format_length | ||||
57 | default_time_format_length | ||||
58 | first_day_of_week | ||||
59 | version | ||||
60 | glibc_datetime_format | ||||
61 | glibc_date_format | ||||
62 | glibc_date_1_format | ||||
63 | glibc_time_format | ||||
64 | glibc_time_12_format | ||||
65 | ); | ||||
66 | |||||
67 | 1 | 600ns | for my $meth (@methods) { | ||
68 | 50 | 39µs | my $sub = sub { $_[0]->{$meth} }; | ||
69 | ## no critic (TestingAndDebugging::ProhibitNoStrict) | ||||
70 | 2 | 98µs | 2 | 36µs | # spent 21µs (7+14) within DateTime::Locale::FromData::BEGIN@70 which was called:
# once (7µs+14µs) by DateTime::Locale::BEGIN@11 at line 70 # spent 21µs making 1 call to DateTime::Locale::FromData::BEGIN@70
# spent 14µs making 1 call to strict::unimport |
71 | 50 | 61µs | *{$meth} = $sub; | ||
72 | } | ||||
73 | |||||
74 | 1 | 900ns | @FormatLengths = qw( short medium long full ); | ||
75 | |||||
76 | 1 | 4µs | for my $length (@FormatLengths) { | ||
77 | 4 | 2µs | my $meth = 'datetime_format_' . $length; | ||
78 | 4 | 2µs | my $key = 'computed_' . $meth; | ||
79 | |||||
80 | my $sub = sub { | ||||
81 | my $self = shift; | ||||
82 | |||||
83 | return $self->{$key} if exists $self->{$key}; | ||||
84 | |||||
85 | return $self->{$key} = $self->_make_datetime_format($length); | ||||
86 | 4 | 4µs | }; | ||
87 | |||||
88 | ## no critic (TestingAndDebugging::ProhibitNoStrict) | ||||
89 | 2 | 35µs | 2 | 25µs | # spent 17µs (8+9) within DateTime::Locale::FromData::BEGIN@89 which was called:
# once (8µs+9µs) by DateTime::Locale::BEGIN@11 at line 89 # spent 17µs making 1 call to DateTime::Locale::FromData::BEGIN@89
# spent 9µs making 1 call to strict::unimport |
90 | 4 | 5µs | *{$meth} = $sub; | ||
91 | } | ||||
92 | 1 | 782µs | 1 | 122µs | } # spent 122µs making 1 call to DateTime::Locale::FromData::BEGIN@13 |
93 | |||||
94 | # spent 26µs within DateTime::Locale::FromData::new which was called:
# once (26µs+0s) by DateTime::Locale::_locale_object_for at line 282 of DateTime/Locale.pm | ||||
95 | 1 | 400ns | my $class = shift; | ||
96 | 1 | 300ns | my $data = shift; | ||
97 | |||||
98 | return bless { | ||||
99 | 1 | 27µs | %{$data}, | ||
100 | default_date_format_length => 'medium', | ||||
101 | default_time_format_length => 'medium', | ||||
102 | }, $class; | ||||
103 | } | ||||
104 | |||||
105 | sub date_format_default { | ||||
106 | return $_[0]->date_format_medium; | ||||
107 | } | ||||
108 | |||||
109 | sub time_format_default { | ||||
110 | return $_[0]->time_format_medium; | ||||
111 | } | ||||
112 | |||||
113 | sub datetime_format { | ||||
114 | return $_[0]->{datetime_format_medium}; | ||||
115 | } | ||||
116 | |||||
117 | sub datetime_format_default { | ||||
118 | return $_[0]->datetime_format_medium; | ||||
119 | } | ||||
120 | |||||
121 | sub _make_datetime_format { | ||||
122 | my $self = shift; | ||||
123 | my $length = shift; | ||||
124 | |||||
125 | my $dt_key = 'datetime_format_' . $length; | ||||
126 | my $date_meth = 'date_format_' . $length; | ||||
127 | my $time_meth = 'time_format_' . $length; | ||||
128 | |||||
129 | my $dt_format = $self->{$dt_key}; | ||||
130 | $dt_format =~ s/\{0\}/$self->$time_meth/eg; | ||||
131 | $dt_format =~ s/\{1\}/$self->$date_meth/eg; | ||||
132 | |||||
133 | return $dt_format; | ||||
134 | } | ||||
135 | |||||
136 | sub set_default_date_format_length { | ||||
137 | my $self = shift; | ||||
138 | my ($l) | ||||
139 | = validate_pos( @_, { regex => qr/^(?:full|long|medium|short)$/i } ); | ||||
140 | |||||
141 | $self->{default_date_format_length} = lc $l; | ||||
142 | } | ||||
143 | |||||
144 | sub set_default_time_format_length { | ||||
145 | my $self = shift; | ||||
146 | my ($l) | ||||
147 | = validate_pos( @_, { regex => qr/^(?:full|long|medium|short)/i } ); | ||||
148 | |||||
149 | $self->{default_time_format_length} = lc $l; | ||||
150 | } | ||||
151 | |||||
152 | sub date_formats { | ||||
153 | my %formats; | ||||
154 | for my $length (@FormatLengths) { | ||||
155 | my $meth = 'date_format_' . $length; | ||||
156 | $formats{$length} = $_[0]->$meth; | ||||
157 | } | ||||
158 | return \%formats; | ||||
159 | } | ||||
160 | |||||
161 | sub time_formats { | ||||
162 | my %formats; | ||||
163 | for my $length (@FormatLengths) { | ||||
164 | my $meth = 'time_format_' . $length; | ||||
165 | $formats{$length} = $_[0]->$meth; | ||||
166 | } | ||||
167 | return \%formats; | ||||
168 | } | ||||
169 | |||||
170 | sub available_formats { | ||||
171 | my $self = shift; | ||||
172 | |||||
173 | $self->{computed_available_formats} | ||||
174 | ||= [ sort keys %{ $self->_available_formats } ]; | ||||
175 | |||||
176 | return @{ $self->{computed_available_formats} }; | ||||
177 | } | ||||
178 | |||||
179 | sub format_for { | ||||
180 | my $self = shift; | ||||
181 | my $for = shift; | ||||
182 | |||||
183 | return $self->_available_formats->{$for}; | ||||
184 | } | ||||
185 | |||||
186 | sub _available_formats { $_[0]->{available_formats} } | ||||
187 | |||||
188 | sub prefers_24_hour_time { | ||||
189 | my $self = shift; | ||||
190 | |||||
191 | return $self->{prefers_24_hour_time} | ||||
192 | if exists $self->{prefers_24_hour_time}; | ||||
193 | |||||
194 | $self->{prefers_24_hour_time} = $self->time_format_short =~ /h|K/ ? 0 : 1; | ||||
195 | } | ||||
196 | |||||
197 | sub language_code { | ||||
198 | my $self = shift; | ||||
199 | return ( $self->{parsed_code} ||= { parse_locale_code( $self->code ) } ) | ||||
200 | ->{language}; | ||||
201 | } | ||||
202 | |||||
203 | sub script_code { | ||||
204 | my $self = shift; | ||||
205 | return ( $self->{parsed_code} ||= { parse_locale_code( $self->code ) } ) | ||||
206 | ->{script}; | ||||
207 | } | ||||
208 | |||||
209 | sub territory_code { | ||||
210 | my $self = shift; | ||||
211 | return ( $self->{parsed_code} ||= { parse_locale_code( $self->code ) } ) | ||||
212 | ->{territory}; | ||||
213 | } | ||||
214 | |||||
215 | sub variant_code { | ||||
216 | my $self = shift; | ||||
217 | return ( $self->{parsed_code} ||= { parse_locale_code( $self->code ) } ) | ||||
218 | ->{variant}; | ||||
219 | } | ||||
220 | |||||
221 | sub id { | ||||
222 | $_[0]->code; | ||||
223 | } | ||||
224 | |||||
225 | sub language_id { | ||||
226 | $_[0]->language_code; | ||||
227 | } | ||||
228 | |||||
229 | sub script_id { | ||||
230 | $_[0]->script_code; | ||||
231 | } | ||||
232 | |||||
233 | sub territory_id { | ||||
234 | $_[0]->territory_code; | ||||
235 | } | ||||
236 | |||||
237 | sub variant_id { | ||||
238 | $_[0]->variant_code; | ||||
239 | } | ||||
240 | |||||
241 | sub STORABLE_freeze { | ||||
242 | my $self = shift; | ||||
243 | my $cloning = shift; | ||||
244 | |||||
245 | return if $cloning; | ||||
246 | |||||
247 | return $self->code; | ||||
248 | } | ||||
249 | |||||
250 | sub STORABLE_thaw { | ||||
251 | my $self = shift; | ||||
252 | shift; | ||||
253 | my $serialized = shift; | ||||
254 | |||||
255 | my $obj = DateTime::Locale->load($serialized); | ||||
256 | |||||
257 | %{$self} = %{$obj}; | ||||
258 | |||||
259 | return $self; | ||||
260 | } | ||||
261 | |||||
262 | 1 | 3µs | 1; | ||
263 | |||||
264 | # ABSTRACT: Class for locale objects instantiated from pre-defined data | ||||
265 | |||||
266 | __END__ |