Profile of DateTime/Locale/Base.pm

← Index
NYTProf Performance Profile «block view•line view•sub view»
For xt/tapper-mcp-scheduler-with-db-longrun.t
Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:10 2012

Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DateTime/Locale/Base.pm
Statements | Executed 215 statements in 3.02ms

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 78µs | 91µs | DateTime::Locale::Base::::BEGIN@11DateTime::Locale::Base::BEGIN@11
29 | 1 | 1 | 35µs | 35µs | DateTime::Locale::Base::::CORE:qrDateTime::Locale::Base::CORE:qr (opcode)
1 | 1 | 1 | 33µs | 36µs | DateTime::Locale::Base::::newDateTime::Locale::Base::new
1 | 1 | 1 | 15µs | 23µs | DateTime::Locale::Base::::BEGIN@4DateTime::Locale::Base::BEGIN@4
22 | 2 | 1 | 13µs | 13µs | DateTime::Locale::Base::::CORE:substDateTime::Locale::Base::CORE:subst (opcode)
1 | 1 | 1 | 11µs | 13µs | DateTime::Locale::Base::::BEGIN@3DateTime::Locale::Base::BEGIN@3
1 | 1 | 1 | 9µs | 17µs | DateTime::Locale::Base::::BEGIN@176DateTime::Locale::Base::BEGIN@176
1 | 1 | 1 | 7µs | 7µs | DateTime::Locale::Base::::BEGIN@7DateTime::Locale::Base::BEGIN@7
1 | 1 | 1 | 7µs | 43µs | DateTime::Locale::Base::::BEGIN@6DateTime::Locale::Base::BEGIN@6
1 | 1 | 1 | 7µs | 16µs | DateTime::Locale::Base::::BEGIN@119DateTime::Locale::Base::BEGIN@119
1 | 1 | 1 | 7µs | 22µs | DateTime::Locale::Base::::BEGIN@25DateTime::Locale::Base::BEGIN@25
1 | 1 | 1 | 7µs | 16µs | DateTime::Locale::Base::::BEGIN@363DateTime::Locale::Base::BEGIN@363
1 | 1 | 1 | 7µs | 28µs | DateTime::Locale::Base::::BEGIN@9DateTime::Locale::Base::BEGIN@9
1 | 1 | 1 | 4µs | 4µs | DateTime::Locale::Base::::BEGIN@8DateTime::Locale::Base::BEGIN@8
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::STORABLE_freezeDateTime::Locale::Base::STORABLE_freeze
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::STORABLE_thawDateTime::Locale::Base::STORABLE_thaw
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:174]DateTime::Locale::Base::__ANON__[:174]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:218]DateTime::Locale::Base::__ANON__[:218]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:222]DateTime::Locale::Base::__ANON__[:222]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:224]DateTime::Locale::Base::__ANON__[:224]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:226]DateTime::Locale::Base::__ANON__[:226]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:227]DateTime::Locale::Base::__ANON__[:227]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:228]DateTime::Locale::Base::__ANON__[:228]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:231]DateTime::Locale::Base::__ANON__[:231]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:235]DateTime::Locale::Base::__ANON__[:235]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:237]DateTime::Locale::Base::__ANON__[:237]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:239]DateTime::Locale::Base::__ANON__[:239]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:240]DateTime::Locale::Base::__ANON__[:240]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:241]DateTime::Locale::Base::__ANON__[:241]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:244]DateTime::Locale::Base::__ANON__[:244]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:248]DateTime::Locale::Base::__ANON__[:248]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:250]DateTime::Locale::Base::__ANON__[:250]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:252]DateTime::Locale::Base::__ANON__[:252]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:253]DateTime::Locale::Base::__ANON__[:253]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:256]DateTime::Locale::Base::__ANON__[:256]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:257]DateTime::Locale::Base::__ANON__[:257]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:259]DateTime::Locale::Base::__ANON__[:259]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:263]DateTime::Locale::Base::__ANON__[:263]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:265]DateTime::Locale::Base::__ANON__[:265]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:267]DateTime::Locale::Base::__ANON__[:267]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:268]DateTime::Locale::Base::__ANON__[:268]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:26]DateTime::Locale::Base::__ANON__[:26]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:271]DateTime::Locale::Base::__ANON__[:271]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:272]DateTime::Locale::Base::__ANON__[:272]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:280]DateTime::Locale::Base::__ANON__[:280]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:291]DateTime::Locale::Base::__ANON__[:291]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:295]DateTime::Locale::Base::__ANON__[:295]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:299]DateTime::Locale::Base::__ANON__[:299]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:303]DateTime::Locale::Base::__ANON__[:303]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:307]DateTime::Locale::Base::__ANON__[:307]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:311]DateTime::Locale::Base::__ANON__[:311]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:315]DateTime::Locale::Base::__ANON__[:315]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:319]DateTime::Locale::Base::__ANON__[:319]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:323]DateTime::Locale::Base::__ANON__[:323]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:327]DateTime::Locale::Base::__ANON__[:327]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:331]DateTime::Locale::Base::__ANON__[:331]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:335]DateTime::Locale::Base::__ANON__[:335]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:339]DateTime::Locale::Base::__ANON__[:339]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:343]DateTime::Locale::Base::__ANON__[:343]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:347]DateTime::Locale::Base::__ANON__[:347]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:351]DateTime::Locale::Base::__ANON__[:351]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::__ANON__[:361]DateTime::Locale::Base::__ANON__[:361]
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::_available_formatsDateTime::Locale::Base::_available_formats
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::_cldr_to_strftimeDateTime::Locale::Base::_cldr_to_strftime
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::_convertDateTime::Locale::Base::_convert
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::_convert_to_strftimeDateTime::Locale::Base::_convert_to_strftime
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::_make_datetime_formatDateTime::Locale::Base::_make_datetime_format
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::_self_and_super_pathDateTime::Locale::Base::_self_and_super_path
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::_stringifyDateTime::Locale::Base::_stringify
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::available_formatsDateTime::Locale::Base::available_formats
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::date_format_defaultDateTime::Locale::Base::date_format_default
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::date_formatsDateTime::Locale::Base::date_formats
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::datetime_format_defaultDateTime::Locale::Base::datetime_format_default
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::default_date_format_lengthDateTime::Locale::Base::default_date_format_length
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::default_time_format_lengthDateTime::Locale::Base::default_time_format_length
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::format_forDateTime::Locale::Base::format_for
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::language_idDateTime::Locale::Base::language_id
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::prefers_24_hour_timeDateTime::Locale::Base::prefers_24_hour_time
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::script_idDateTime::Locale::Base::script_id
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::set_default_date_format_lengthDateTime::Locale::Base::set_default_date_format_length
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::set_default_time_format_lengthDateTime::Locale::Base::set_default_time_format_length
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::territory_idDateTime::Locale::Base::territory_id
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::time_format_defaultDateTime::Locale::Base::time_format_default
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::time_formatsDateTime::Locale::Base::time_formats
0 | 0 | 0 | 0s | 0s | DateTime::Locale::Base::::variant_idDateTime::Locale::Base::variant_id

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package DateTime::Locale::Base;
2 |  |  |  |  |
3 | 3 | 22µs | 2 | 15µs | # spent 13µs (11+2) within DateTime::Locale::Base::BEGIN@3 which was called: # once (11µs+2µs) by DateTime::Locale::BEGIN@10 at line 3 use strict; # spent 13µs making 1 call to DateTime::Locale::Base::BEGIN@3 # spent 2µs making 1 call to strict::import
4 | 3 | 19µs | 2 | 31µs | # spent 23µs (15+8) within DateTime::Locale::Base::BEGIN@4 which was called: # once (15µs+8µs) by DateTime::Locale::BEGIN@10 at line 4 use warnings; # spent 23µs making 1 call to DateTime::Locale::Base::BEGIN@4 # spent 8µs making 1 call to warnings::import
5 |  |  |  |  |
6 | 3 | 18µs | 2 | 80µs | # spent 43µs (7+36) within DateTime::Locale::Base::BEGIN@6 which was called: # once (7µs+36µs) by DateTime::Locale::BEGIN@10 at line 6 use Carp qw( carp ); # spent 43µs making 1 call to DateTime::Locale::Base::BEGIN@6 # spent 36µs making 1 call to Exporter::import
7 | 3 | 21µs | 1 | 7µs | # spent 7µs within DateTime::Locale::Base::BEGIN@7 which was called: # once (7µs+0s) by DateTime::Locale::BEGIN@10 at line 7 use DateTime::Locale; # spent 7µs making 1 call to DateTime::Locale::Base::BEGIN@7
8 | 3 | 21µs | 1 | 4µs | # spent 4µs within DateTime::Locale::Base::BEGIN@8 which was called: # once (4µs+0s) by DateTime::Locale::BEGIN@10 at line 8 use List::MoreUtils (); # spent 4µs making 1 call to DateTime::Locale::Base::BEGIN@8
9 | 3 | 66µs | 2 | 50µs | # spent 28µs (7+22) within DateTime::Locale::Base::BEGIN@9 which was called: # once (7µs+22µs) by DateTime::Locale::BEGIN@10 at line 9 use Params::Validate qw( validate_pos ); # spent 28µs making 1 call to DateTime::Locale::Base::BEGIN@9 # spent 22µs making 1 call to Exporter::import
10 |  |  |  |  |
11 |  |  |  |  | # spent 91µs (78+13) within DateTime::Locale::Base::BEGIN@11 which was called: # once (78µs+13µs) by DateTime::Locale::BEGIN@10 at line 28 BEGIN {
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 | 33 | 88µs | 11 | 8µs | ( my $meth_name = $field ) =~ s/^en_//; # spent 8µs making 11 calls to DateTime::Locale::Base::CORE:subst, avg 718ns/call
21 |  |  |  |  |
22 |  |  |  |  | # also remove 'complete_'
23 |  |  | 11 | 5µs | $meth_name =~ s/complete_//; # spent 5µs making 11 calls to DateTime::Locale::Base::CORE:subst, avg 464ns/call
24 |  |  |  |  |
25 | 3 | 42µs | 2 | 37µs | # spent 22µs (7+15) within DateTime::Locale::Base::BEGIN@25 which was called: # once (7µs+15µs) by DateTime::Locale::BEGIN@10 at line 25 no strict 'refs'; # spent 22µs making 1 call to DateTime::Locale::Base::BEGIN@25 # spent 15µs making 1 call to strict::unimport
26 |  |  |  |  | *{$meth_name} = sub { $_[0]->{$field} };
27 |  |  |  |  | }
28 | 1 | 372µs | 1 | 91µs | } # spent 91µs making 1 call to DateTime::Locale::Base::BEGIN@11
29 |  |  |  |  |
30 |  |  |  |  | # spent 36µs (33+2) within DateTime::Locale::Base::new which was called: # once (33µs+2µs) by DateTime::Locale::_load_class_from_id at line 286 of DateTime/Locale.pm sub new {
31 | 2 | 33µ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 |  |  | 2 | 2µs | return bless { # spent 1µs making 1 call to DateTime::Locale::root::_default_date_format_length # spent 1µ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 | 283µs | 2 | 24µs | # spent 16µs (7+9) within DateTime::Locale::Base::BEGIN@119 which was called: # once (7µs+9µs) by DateTime::Locale::BEGIN@10 at line 119 no strict 'refs'; # spent 16µ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 | 1µs |  |  | for my $length (qw( full long medium short )) {
162 | 12 | 22µ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 |  |  |  |  | };
175 |  |  |  |  |
176 | 3 | 1.12ms | 2 | 25µs | # spent 17µs (9+8) within DateTime::Locale::Base::BEGIN@176 which was called: # once (9µs+8µs) by DateTime::Locale::BEGIN@10 at line 176 no strict 'refs'; # spent 17µs making 1 call to DateTime::Locale::Base::BEGIN@176 # spent 8µs making 1 call to strict::unimport
177 |  |  |  |  | *{$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 | 700ns |  |  | 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 | 2 | 110µs |  |  | );
353 |  |  |  |  |
354 |  |  |  |  | for my $name ( keys %subs ) {
355 | 129 | 160µ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 |  |  |  |  | };
362 |  |  |  |  |
363 | 3 | 509µs | 2 | 25µ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 no strict 'refs'; # spent 16µs making 1 call to DateTime::Locale::Base::BEGIN@363 # spent 9µs making 1 call to strict::unimport
364 |  |  |  |  | *{$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 | 79µs | 29 | 35µs | my @JavaPatterns = ( # spent 35µs making 29 calls to DateTime::Locale::Base::CORE:qr, avg 1µ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 | 23µs |  |  | 1;
473 |  |  |  |  |
474 |  |  |  |  | __END__
|  |  |  |  | # spent 35µs within DateTime::Locale::Base::CORE:qr which was called 29 times, avg 1µs/call: # 29 times (35µs+0s) by DateTime::Locale::BEGIN@10 at line 385, avg 1µs/call sub DateTime::Locale::Base::CORE:qr; # opcode
|  |  |  |  | # spent 13µs within DateTime::Locale::Base::CORE:subst which was called 22 times, avg 591ns/call: # 11 times (8µs+0s) by DateTime::Locale::Base::BEGIN@11 at line 20, avg 718ns/call # 11 times (5µs+0s) by DateTime::Locale::Base::BEGIN@11 at line 23, avg 464ns/call sub DateTime::Locale::Base::CORE:subst; # opcode