| Filename | /usr/share/perl5/DateTime/Format/Builder/Parser.pm |
| Statements | Executed 562 statements in 3.29ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.09ms | 1.21ms | DateTime::Format::Builder::Parser::BEGIN@375 |
| 10 | 2 | 1 | 332µs | 1.15ms | DateTime::Format::Builder::Parser::create_single_parser |
| 3 | 1 | 1 | 96µs | 1.25ms | DateTime::Format::Builder::Parser::sort_parsers |
| 3 | 2 | 1 | 53µs | 1.33ms | DateTime::Format::Builder::Parser::create_multiple_parsers |
| 10 | 1 | 1 | 44µs | 44µs | DateTime::Format::Builder::Parser::params |
| 4 | 4 | 4 | 33µs | 33µs | DateTime::Format::Builder::Parser::valid_params |
| 14 | 2 | 1 | 33µs | 40µs | DateTime::Format::Builder::Parser::__ANON__[:92] |
| 3 | 1 | 1 | 22µs | 1.35ms | DateTime::Format::Builder::Parser::create_parser |
| 10 | 1 | 1 | 20µs | 20µs | DateTime::Format::Builder::Parser::params_all |
| 5 | 1 | 1 | 13µs | 13µs | DateTime::Format::Builder::Parser::merge_callbacks |
| 1 | 1 | 1 | 12µs | 23µs | DateTime::Format::Builder::Parser::BEGIN@5 |
| 14 | 2 | 1 | 11µs | 11µs | DateTime::Format::Builder::Parser::__ANON__[:93] |
| 3 | 1 | 1 | 11µs | 11µs | DateTime::Format::Builder::Parser::new |
| 11 | 1 | 1 | 11µs | 11µs | DateTime::Format::Builder::Parser::whose_params |
| 3 | 1 | 1 | 9µs | 9µs | DateTime::Format::Builder::Parser::set_maker |
| 1 | 1 | 1 | 8µs | 41µs | DateTime::Format::Builder::Parser::BEGIN@8 |
| 1 | 1 | 1 | 8µs | 15µs | DateTime::Format::Builder::Parser::BEGIN@6 |
| 14 | 1 | 1 | 8µs | 8µs | DateTime::Format::Builder::Parser::CORE:match (opcode) |
| 1 | 1 | 1 | 7µs | 28µs | DateTime::Format::Builder::Parser::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 28µs | DateTime::Format::Builder::Parser::BEGIN@7 |
| 7 | 1 | 1 | 7µs | 7µs | DateTime::Format::Builder::Parser::chain_parsers |
| 3 | 1 | 1 | 5µs | 5µs | DateTime::Format::Builder::Parser::set_parser |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::__ANON__[:217] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::__ANON__[:285] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::__ANON__[:342] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::create_single_object |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::fail |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::maker |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::no_parser |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::on_fail |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::parse |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::set_fail |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::Format::Builder::Parser; | ||||
| 2 | { | ||||
| 3 | 2 | 900ns | $DateTime::Format::Builder::Parser::VERSION = '0.81'; | ||
| 4 | } | ||||
| 5 | 2 | 23µs | 2 | 34µs | # spent 23µs (12+11) within DateTime::Format::Builder::Parser::BEGIN@5 which was called:
# once (12µs+11µs) by DateTime::Format::MySQL::BEGIN@11 at line 5 # spent 23µs making 1 call to DateTime::Format::Builder::Parser::BEGIN@5
# spent 11µs making 1 call to strict::import |
| 6 | 2 | 22µs | 2 | 22µs | # spent 15µs (8+7) within DateTime::Format::Builder::Parser::BEGIN@6 which was called:
# once (8µs+7µs) by DateTime::Format::MySQL::BEGIN@11 at line 6 # spent 15µs making 1 call to DateTime::Format::Builder::Parser::BEGIN@6
# spent 7µs making 1 call to warnings::import |
| 7 | 2 | 31µs | 2 | 50µs | # spent 28µs (7+22) within DateTime::Format::Builder::Parser::BEGIN@7 which was called:
# once (7µs+22µs) by DateTime::Format::MySQL::BEGIN@11 at line 7 # spent 28µs making 1 call to DateTime::Format::Builder::Parser::BEGIN@7
# spent 22µs making 1 call to Exporter::import |
| 8 | 1 | 4µs | 1 | 33µs | # spent 41µs (8+33) within DateTime::Format::Builder::Parser::BEGIN@8 which was called:
# once (8µs+33µs) by DateTime::Format::MySQL::BEGIN@11 at line 10 # spent 33µs making 1 call to Exporter::import |
| 9 | validate SCALAR CODEREF UNDEF ARRAYREF | ||||
| 10 | 1 | 20µs | 1 | 41µs | ); # spent 41µs making 1 call to DateTime::Format::Builder::Parser::BEGIN@8 |
| 11 | 2 | 1.15ms | 2 | 48µs | # spent 28µs (7+20) within DateTime::Format::Builder::Parser::BEGIN@11 which was called:
# once (7µs+20µs) by DateTime::Format::MySQL::BEGIN@11 at line 11 # spent 28µs making 1 call to DateTime::Format::Builder::Parser::BEGIN@11
# spent 20µs making 1 call to Exporter::import |
| 12 | |||||
| - - | |||||
| 16 | sub on_fail { | ||||
| 17 | my ( $self, $input, $parent ) = @_; | ||||
| 18 | my $maker = $self->maker; | ||||
| 19 | if ( $maker and $maker->can('on_fail') ) { | ||||
| 20 | $maker->on_fail($input); | ||||
| 21 | } | ||||
| 22 | else { | ||||
| 23 | croak __PACKAGE__ . ": Invalid date format: $input"; | ||||
| 24 | } | ||||
| 25 | } | ||||
| 26 | |||||
| 27 | sub no_parser { | ||||
| 28 | croak "No parser set for this parser object."; | ||||
| 29 | } | ||||
| 30 | |||||
| 31 | # spent 11µs within DateTime::Format::Builder::Parser::new which was called 3 times, avg 4µs/call:
# 3 times (11µs+0s) by DateTime::Format::Builder::Parser::create_multiple_parsers at line 225, avg 4µs/call | ||||
| 32 | 3 | 600ns | my $class = shift; | ||
| 33 | 3 | 1µs | $class = ref($class) || $class; | ||
| 34 | 3 | 700ns | my $i = 0; | ||
| 35 | 3 | 6µs | my $self = bless { | ||
| 36 | on_fail => \&on_fail, | ||||
| 37 | parser => \&no_parser, | ||||
| 38 | }, $class; | ||||
| 39 | |||||
| 40 | 3 | 8µs | return $self; | ||
| 41 | } | ||||
| 42 | |||||
| 43 | sub maker { $_[0]->{maker} } | ||||
| 44 | |||||
| 45 | # spent 9µs within DateTime::Format::Builder::Parser::set_maker which was called 3 times, avg 3µs/call:
# 3 times (9µs+0s) by DateTime::Format::Builder::Parser::create_multiple_parsers at line 240, avg 3µs/call | ||||
| 46 | 3 | 600ns | my $self = shift; | ||
| 47 | 3 | 600ns | my $maker = shift; | ||
| 48 | |||||
| 49 | 3 | 4µs | $self->{maker} = $maker; | ||
| 50 | 3 | 1µs | weaken $self->{maker} | ||
| 51 | if ref $self->{maker}; | ||||
| 52 | |||||
| 53 | 3 | 7µs | return $self; | ||
| 54 | } | ||||
| 55 | |||||
| 56 | sub fail { | ||||
| 57 | my ( $self, $parent, $input ) = @_; | ||||
| 58 | $self->{on_fail}->( $self, $input, $parent ); | ||||
| 59 | } | ||||
| 60 | |||||
| 61 | sub parse { | ||||
| 62 | my ( $self, $parent, $input, @args ) = @_; | ||||
| 63 | my $r = $self->{parser}->( $parent, $input, @args ); | ||||
| 64 | $self->fail( $parent, $input ) unless defined $r; | ||||
| 65 | $r; | ||||
| 66 | } | ||||
| 67 | |||||
| 68 | # spent 5µs within DateTime::Format::Builder::Parser::set_parser which was called 3 times, avg 2µs/call:
# 3 times (5µs+0s) by DateTime::Format::Builder::Parser::create_multiple_parsers at line 286, avg 2µs/call | ||||
| 69 | 3 | 1µs | my ( $self, $parser ) = @_; | ||
| 70 | 3 | 1µs | $self->{parser} = $parser; | ||
| 71 | 3 | 6µs | $self; | ||
| 72 | } | ||||
| 73 | |||||
| 74 | sub set_fail { | ||||
| 75 | my ( $self, $fail ) = @_; | ||||
| 76 | $self->{on_fail} = $fail; | ||||
| 77 | $self; | ||||
| 78 | } | ||||
| 79 | |||||
| 80 | |||||
| 81 | 1 | 900ns | my @callbacks = qw( on_match on_fail postprocess preprocess ); | ||
| 82 | |||||
| 83 | { | ||||
| 84 | |||||
| 85 | |||||
| 86 | 1 | 200ns | my %params = ( | ||
| 87 | common => { | ||||
| 88 | length => { | ||||
| 89 | type => SCALAR | ARRAYREF, | ||||
| 90 | optional => 1, | ||||
| 91 | callbacks => { | ||||
| 92 | 14 | 49µs | 14 | 8µs | # spent 40µs (33+8) within DateTime::Format::Builder::Parser::__ANON__[/usr/share/perl5/DateTime/Format/Builder/Parser.pm:92] which was called 14 times, avg 3µs/call:
# 7 times (19µs+4µs) by Params::Validate::XS::validate at line 164, avg 3µs/call
# 7 times (14µs+4µs) by Params::Validate::XS::validate at line 185, avg 2µs/call # spent 8µs making 14 calls to DateTime::Format::Builder::Parser::CORE:match, avg 550ns/call |
| 93 | 14 | 25µs | # spent 11µs within DateTime::Format::Builder::Parser::__ANON__[/usr/share/perl5/DateTime/Format/Builder/Parser.pm:93] which was called 14 times, avg 814ns/call:
# 7 times (6µs+0s) by Params::Validate::XS::validate at line 164, avg 886ns/call
# 7 times (5µs+0s) by Params::Validate::XS::validate at line 185, avg 743ns/call | ||
| 94 | } | ||||
| 95 | }, | ||||
| 96 | |||||
| 97 | # Stuff used by callbacks | ||||
| 98 | label => { type => SCALAR, optional => 1 }, | ||||
| 99 | ( | ||||
| 100 | 1 | 14µs | map { $_ => { type => CODEREF | ARRAYREF, optional => 1 } } | ||
| 101 | @callbacks | ||||
| 102 | ), | ||||
| 103 | }, | ||||
| 104 | ); | ||||
| 105 | |||||
| 106 | |||||
| 107 | # spent 44µs within DateTime::Format::Builder::Parser::params which was called 10 times, avg 4µs/call:
# 10 times (44µs+0s) by DateTime::Format::Builder::Parser::create_single_parser at line 185, avg 4µs/call | ||||
| 108 | 10 | 2µs | my $self = shift; | ||
| 109 | 10 | 2µs | my $caller = ref $self || $self; | ||
| 110 | 10 | 51µs | return { map { %$_ } @params{ $caller, 'common' } }; | ||
| 111 | } | ||||
| 112 | |||||
| 113 | |||||
| 114 | 1 | 200ns | my $all_params; | ||
| 115 | |||||
| 116 | # spent 20µs within DateTime::Format::Builder::Parser::params_all which was called 10 times, avg 2µs/call:
# 10 times (20µs+0s) by DateTime::Format::Builder::Parser::create_single_parser at line 164, avg 2µs/call | ||||
| 117 | 10 | 16µs | return $all_params if defined $all_params; | ||
| 118 | 1 | 8µs | my %all_params = map { %$_ } values %params; | ||
| 119 | 1 | 5µs | $_->{optional} = 1 for values %all_params; | ||
| 120 | 1 | 3µs | $all_params = \%all_params; | ||
| 121 | } | ||||
| 122 | |||||
| 123 | |||||
| 124 | 1 | 500ns | my %inverse; | ||
| 125 | |||||
| 126 | # spent 33µs within DateTime::Format::Builder::Parser::valid_params which was called 4 times, avg 8µs/call:
# once (9µs+0s) by DateTime::Format::Builder::Parser::BEGIN@1.2 at line 42 of DateTime/Format/Builder/Parser/Regex.pm
# once (8µs+0s) by DateTime::Format::Builder::Parser::BEGIN@1 at line 20 of DateTime/Format/Builder/Parser/Dispatch.pm
# once (8µs+0s) by DateTime::Format::Builder::Parser::BEGIN@1.3 at line 16 of DateTime/Format/Builder/Parser/Strptime.pm
# once (8µs+0s) by DateTime::Format::Builder::Parser::BEGIN@1.1 at line 22 of DateTime/Format/Builder/Parser/Quick.pm | ||||
| 127 | 4 | 2µs | my $self = shift; | ||
| 128 | 4 | 4µs | my $from = (caller)[0]; | ||
| 129 | 4 | 5µs | my %args = @_; | ||
| 130 | 4 | 2µs | $params{$from} = \%args; | ||
| 131 | 4 | 6µs | for ( keys %args ) { | ||
| 132 | |||||
| 133 | # %inverse contains keys matching all the | ||||
| 134 | # possible params; values are the class if and | ||||
| 135 | # only if that class is the only one that uses | ||||
| 136 | # the given param. | ||||
| 137 | 8 | 6µs | $inverse{$_} = exists $inverse{$_} ? undef : $from; | ||
| 138 | } | ||||
| 139 | 4 | 1µs | undef $all_params; | ||
| 140 | 4 | 17µs | 1; | ||
| 141 | } | ||||
| 142 | |||||
| 143 | |||||
| 144 | # spent 11µs within DateTime::Format::Builder::Parser::whose_params which was called 11 times, avg 973ns/call:
# 11 times (11µs+0s) by DateTime::Format::Builder::Parser::create_single_parser at line 174, avg 973ns/call | ||||
| 145 | 11 | 2µs | my $param = shift; | ||
| 146 | 11 | 19µs | return $inverse{$param}; | ||
| 147 | } | ||||
| 148 | } | ||||
| 149 | |||||
| 150 | |||||
| 151 | sub create_single_object { | ||||
| 152 | my ($self) = shift; | ||||
| 153 | my $obj = $self->new; | ||||
| 154 | my $parser = $self->create_single_parser(@_); | ||||
| 155 | |||||
| 156 | $obj->set_parser($parser); | ||||
| 157 | } | ||||
| 158 | |||||
| 159 | # spent 1.15ms (332µs+814µs) within DateTime::Format::Builder::Parser::create_single_parser which was called 10 times, avg 115µs/call:
# 7 times (244µs+592µs) by DateTime::Format::Builder::Parser::sort_parsers at line 305, avg 119µs/call
# 3 times (88µs+222µs) by DateTime::Format::Builder::Parser::sort_parsers at line 315, avg 103µs/call | ||||
| 160 | 10 | 2µs | my $class = shift; | ||
| 161 | 10 | 2µs | return $_[0] if ref $_[0] eq 'CODE'; # already code | ||
| 162 | 10 | 1µs | @_ = %{ $_[0] } if ref $_[0] eq 'HASH'; # turn hashref into hash | ||
| 163 | # ordinary boring sort | ||||
| 164 | 10 | 217µs | 44 | 287µs | my %args = validate( @_, params_all() ); # spent 228µs making 10 calls to Params::Validate::XS::validate, avg 23µs/call
# spent 23µs making 7 calls to DateTime::Format::Builder::Parser::__ANON__[DateTime/Format/Builder/Parser.pm:92], avg 3µs/call
# spent 20µs making 10 calls to DateTime::Format::Builder::Parser::params_all, avg 2µs/call
# spent 10µs making 10 calls to DateTime::Format::Builder::Parser::Regex::__ANON__[DateTime/Format/Builder/Parser/Regex.pm:24], avg 1µs/call
# spent 6µs making 7 calls to DateTime::Format::Builder::Parser::__ANON__[DateTime/Format/Builder/Parser.pm:93], avg 886ns/call |
| 165 | |||||
| 166 | # Determine variables for ease of reference. | ||||
| 167 | 10 | 5µs | for (@callbacks) { | ||
| 168 | 40 | 22µs | 5 | 13µs | $args{$_} = $class->merge_callbacks( $args{$_} ) if $args{$_}; # spent 13µs making 5 calls to DateTime::Format::Builder::Parser::merge_callbacks, avg 3µs/call |
| 169 | } | ||||
| 170 | |||||
| 171 | # Determine parser class | ||||
| 172 | 10 | 1µs | my $from; | ||
| 173 | 10 | 7µs | for ( keys %args ) { | ||
| 174 | 11 | 8µs | 11 | 11µs | $from = whose_params($_); # spent 11µs making 11 calls to DateTime::Format::Builder::Parser::whose_params, avg 973ns/call |
| 175 | 11 | 4µs | next if ( not defined $from ) or ( $from eq 'common' ); | ||
| 176 | 10 | 4µs | last; | ||
| 177 | } | ||||
| 178 | 10 | 900ns | croak "Could not identify a parsing module to use." unless $from; | ||
| 179 | |||||
| 180 | # Find and call parser creation method | ||||
| 181 | 10 | 83µs | 10 | 18µs | my $method = $from->can("create_parser") # spent 18µs making 10 calls to UNIVERSAL::can, avg 2µs/call |
| 182 | or croak | ||||
| 183 | "Can't create a $_ parser (no appropriate create_parser method)"; | ||||
| 184 | 10 | 16µs | my @args = %args; | ||
| 185 | 10 | 212µs | 44 | 270µs | %args = validate( @args, $from->params() ); # spent 194µs making 10 calls to Params::Validate::XS::validate, avg 19µs/call
# spent 44µs making 10 calls to DateTime::Format::Builder::Parser::params, avg 4µs/call
# spent 18µs making 7 calls to DateTime::Format::Builder::Parser::__ANON__[DateTime/Format/Builder/Parser.pm:92], avg 2µs/call
# spent 9µs making 10 calls to DateTime::Format::Builder::Parser::Regex::__ANON__[DateTime/Format/Builder/Parser/Regex.pm:24], avg 940ns/call
# spent 5µs making 7 calls to DateTime::Format::Builder::Parser::__ANON__[DateTime/Format/Builder/Parser.pm:93], avg 743ns/call |
| 186 | 10 | 38µs | 10 | 286µs | $from->$method(%args); # spent 286µs making 10 calls to DateTime::Format::Builder::Parser::Regex::create_parser, avg 29µs/call |
| 187 | } | ||||
| 188 | |||||
| 189 | |||||
| 190 | # spent 13µs within DateTime::Format::Builder::Parser::merge_callbacks which was called 5 times, avg 3µs/call:
# 5 times (13µs+0s) by DateTime::Format::Builder::Parser::create_single_parser at line 168, avg 3µs/call | ||||
| 191 | 5 | 1µs | my $self = shift; | ||
| 192 | |||||
| 193 | 5 | 1µs | return unless @_; # No arguments | ||
| 194 | 5 | 700ns | return unless $_[0]; # Irrelevant argument | ||
| 195 | 5 | 2µs | my @callbacks = @_; | ||
| 196 | 5 | 1µs | if ( @_ == 1 ) { | ||
| 197 | 5 | 11µs | return $_[0] if ref $_[0] eq 'CODE'; | ||
| 198 | @callbacks = @{ $_[0] } if ref $_[0] eq 'ARRAY'; | ||||
| 199 | } | ||||
| 200 | return unless @callbacks; | ||||
| 201 | |||||
| 202 | for (@callbacks) { | ||||
| 203 | croak "All callbacks must be coderefs!" unless ref $_ eq 'CODE'; | ||||
| 204 | } | ||||
| 205 | |||||
| 206 | return sub { | ||||
| 207 | my $rv; | ||||
| 208 | my %args = @_; | ||||
| 209 | for my $cb (@callbacks) { | ||||
| 210 | $rv = $cb->(%args); | ||||
| 211 | return $rv unless $rv; | ||||
| 212 | |||||
| 213 | # Ugh. Symbiotic. All but postprocessor return the date. | ||||
| 214 | $args{input} = $rv unless $args{parsed}; | ||||
| 215 | } | ||||
| 216 | $rv; | ||||
| 217 | }; | ||||
| 218 | } | ||||
| 219 | |||||
| 220 | |||||
| 221 | # spent 1.33ms (53µs+1.27) within DateTime::Format::Builder::Parser::create_multiple_parsers which was called 3 times, avg 442µs/call:
# 2 times (36µs+257µs) by DateTime::Format::Builder::Parser::create_parser at line 368, avg 147µs/call
# once (16µs+1.02ms) by DateTime::Format::Builder::Parser::create_parser at line 362 | ||||
| 222 | 3 | 500ns | my $class = shift; | ||
| 223 | 3 | 1µs | my ( $options, @specs ) = @_; | ||
| 224 | |||||
| 225 | 3 | 3µs | 3 | 11µs | my $obj = $class->new; # spent 11µs making 3 calls to DateTime::Format::Builder::Parser::new, avg 4µs/call |
| 226 | |||||
| 227 | # Organise the specs, and transform them into parsers. | ||||
| 228 | 3 | 5µs | 3 | 1.25ms | my ( $lengths, $others ) = $class->sort_parsers( $options, \@specs ); # spent 1.25ms making 3 calls to DateTime::Format::Builder::Parser::sort_parsers, avg 416µs/call |
| 229 | |||||
| 230 | # Merge callbacks if any. | ||||
| 231 | 3 | 2µs | for ('preprocess') { | ||
| 232 | 3 | 2µs | $options->{$_} = $class->merge_callbacks( $options->{$_} ) | ||
| 233 | if $options->{$_}; | ||||
| 234 | } | ||||
| 235 | |||||
| 236 | # Custom fail method? | ||||
| 237 | 3 | 1µs | $obj->set_fail( $options->{on_fail} ) if exists $options->{on_fail}; | ||
| 238 | |||||
| 239 | # Who's our maker? | ||||
| 240 | 3 | 5µs | 3 | 9µs | $obj->set_maker( $options->{maker} ) if exists $options->{maker}; # spent 9µs making 3 calls to DateTime::Format::Builder::Parser::set_maker, avg 3µs/call |
| 241 | |||||
| 242 | # We don't want to save the whole options hash as a closure, since | ||||
| 243 | # that can cause a circular reference when $options->{maker} is | ||||
| 244 | # set. | ||||
| 245 | 3 | 1µs | my $preprocess = $options->{preprocess}; | ||
| 246 | |||||
| 247 | # These are the innards of a multi-parser. | ||||
| 248 | my $parser = sub { | ||||
| 249 | my ( $self, $date, @args ) = @_; | ||||
| 250 | return unless defined $date; | ||||
| 251 | |||||
| 252 | # Parameters common to the callbacks. Pre-prepared. | ||||
| 253 | my %param = ( | ||||
| 254 | self => $self, | ||||
| 255 | ( @args ? ( args => \@args ) : () ), | ||||
| 256 | ); | ||||
| 257 | |||||
| 258 | my %p; | ||||
| 259 | |||||
| 260 | # Preprocess and potentially fill %p | ||||
| 261 | if ($preprocess) { | ||||
| 262 | $date = $preprocess->( input => $date, parsed => \%p, %param ); | ||||
| 263 | } | ||||
| 264 | |||||
| 265 | # Find length parser | ||||
| 266 | if (%$lengths) { | ||||
| 267 | my $length = length $date; | ||||
| 268 | my $parser = $lengths->{$length}; | ||||
| 269 | if ($parser) { | ||||
| 270 | |||||
| 271 | # Found one, call it with _copy_ of %p | ||||
| 272 | my $dt = $parser->( $self, $date, {%p}, @args ); | ||||
| 273 | return $dt if defined $dt; | ||||
| 274 | } | ||||
| 275 | } | ||||
| 276 | |||||
| 277 | # Or calls all others, with _copy_ of %p | ||||
| 278 | for my $parser (@$others) { | ||||
| 279 | my $dt = $parser->( $self, $date, {%p}, @args ); | ||||
| 280 | return $dt if defined $dt; | ||||
| 281 | } | ||||
| 282 | |||||
| 283 | # Failed, return undef. | ||||
| 284 | return; | ||||
| 285 | 3 | 8µs | }; | ||
| 286 | 3 | 11µs | 3 | 5µs | $obj->set_parser($parser); # spent 5µs making 3 calls to DateTime::Format::Builder::Parser::set_parser, avg 2µs/call |
| 287 | } | ||||
| 288 | |||||
| 289 | |||||
| 290 | # spent 1.25ms (96µs+1.15) within DateTime::Format::Builder::Parser::sort_parsers which was called 3 times, avg 416µs/call:
# 3 times (96µs+1.15ms) by DateTime::Format::Builder::Parser::create_multiple_parsers at line 228, avg 416µs/call | ||||
| 291 | 3 | 600ns | my $class = shift; | ||
| 292 | 3 | 800ns | my ( $options, $specs ) = @_; | ||
| 293 | 3 | 200ns | my ( %lengths, @others ); | ||
| 294 | |||||
| 295 | 3 | 2µs | for my $spec (@$specs) { | ||
| 296 | |||||
| 297 | # Put coderefs straight into the 'other' heap. | ||||
| 298 | 10 | 11µs | if ( ref $spec eq 'CODE' ) { | ||
| 299 | push @others, $spec; | ||||
| 300 | } | ||||
| 301 | |||||
| 302 | # Specifications... | ||||
| 303 | elsif ( ref $spec eq 'HASH' ) { | ||||
| 304 | 10 | 3µs | if ( exists $spec->{length} ) { | ||
| 305 | 7 | 18µs | 7 | 835µs | my $code = $class->create_single_parser(%$spec); # spent 835µs making 7 calls to DateTime::Format::Builder::Parser::create_single_parser, avg 119µs/call |
| 306 | my @lengths | ||||
| 307 | = ref $spec->{length} | ||||
| 308 | 7 | 6µs | ? @{ $spec->{length} } | ||
| 309 | : ( $spec->{length} ); | ||||
| 310 | 7 | 4µs | for my $length (@lengths) { | ||
| 311 | 7 | 11µs | push @{ $lengths{$length} }, $code; | ||
| 312 | } | ||||
| 313 | } | ||||
| 314 | else { | ||||
| 315 | 3 | 6µs | 3 | 310µs | push @others, $class->create_single_parser(%$spec); # spent 310µs making 3 calls to DateTime::Format::Builder::Parser::create_single_parser, avg 103µs/call |
| 316 | } | ||||
| 317 | } | ||||
| 318 | |||||
| 319 | # Something else | ||||
| 320 | else { | ||||
| 321 | croak "Invalid specification in list."; | ||||
| 322 | } | ||||
| 323 | } | ||||
| 324 | |||||
| 325 | 3 | 13µs | 7 | 7µs | while ( my ( $length, $parsers ) = each %lengths ) { # spent 7µs making 7 calls to DateTime::Format::Builder::Parser::chain_parsers, avg 986ns/call |
| 326 | $lengths{$length} = $class->chain_parsers($parsers); | ||||
| 327 | } | ||||
| 328 | |||||
| 329 | 3 | 8µs | return ( \%lengths, \@others ); | ||
| 330 | } | ||||
| 331 | |||||
| 332 | # spent 7µs within DateTime::Format::Builder::Parser::chain_parsers which was called 7 times, avg 986ns/call:
# 7 times (7µs+0s) by DateTime::Format::Builder::Parser::sort_parsers at line 325, avg 986ns/call | ||||
| 333 | 7 | 1µs | my ( $self, $parsers ) = @_; | ||
| 334 | 7 | 13µs | return $parsers->[0] if @$parsers == 1; | ||
| 335 | return sub { | ||||
| 336 | my $self = shift; | ||||
| 337 | for my $parser (@$parsers) { | ||||
| 338 | my $rv = $self->$parser(@_); | ||||
| 339 | return $rv if defined $rv; | ||||
| 340 | } | ||||
| 341 | return undef; | ||||
| 342 | }; | ||||
| 343 | } | ||||
| 344 | |||||
| 345 | |||||
| 346 | # spent 1.35ms (22µs+1.33) within DateTime::Format::Builder::Parser::create_parser which was called 3 times, avg 450µs/call:
# 3 times (22µs+1.33ms) by DateTime::Format::Builder::create_parser at line 122 of DateTime/Format/Builder.pm, avg 450µs/call | ||||
| 347 | 3 | 700ns | my $class = shift; | ||
| 348 | 3 | 1µs | if ( not ref $_[0] ) { | ||
| 349 | |||||
| 350 | # Simple case of single specification as a hash | ||||
| 351 | return $class->create_single_object(@_); | ||||
| 352 | } | ||||
| 353 | |||||
| 354 | # Let's see if we were given an options block | ||||
| 355 | 3 | 500ns | my %options; | ||
| 356 | 3 | 2µs | while ( ref $_[0] eq 'ARRAY' ) { | ||
| 357 | 3 | 600ns | my $options = shift; | ||
| 358 | 3 | 4µs | %options = ( %options, @$options ); | ||
| 359 | } | ||||
| 360 | |||||
| 361 | # Now, can we create a multi-parser out of the remaining arguments? | ||||
| 362 | 3 | 4µs | 1 | 1.03ms | if ( ref $_[0] eq 'HASH' or ref $_[0] eq 'CODE' ) { # spent 1.03ms making 1 call to DateTime::Format::Builder::Parser::create_multiple_parsers |
| 363 | return $class->create_multiple_parsers( \%options, @_ ); | ||||
| 364 | } | ||||
| 365 | else { | ||||
| 366 | # If it wasn't a HASH or CODE, then it was (ideally) | ||||
| 367 | # a list of pairs describing a single specification. | ||||
| 368 | 2 | 9µs | 2 | 294µs | return $class->create_multiple_parsers( \%options, {@_} ); # spent 294µs making 2 calls to DateTime::Format::Builder::Parser::create_multiple_parsers, avg 147µs/call |
| 369 | } | ||||
| 370 | } | ||||
| 371 | |||||
| 372 | |||||
| 373 | # Find all our workers | ||||
| 374 | { | ||||
| 375 | 4 | 793µs | 3 | 1.22ms | # spent 1.21ms (1.09+115µs) within DateTime::Format::Builder::Parser::BEGIN@375 which was called:
# once (1.09ms+115µs) by DateTime::Format::MySQL::BEGIN@11 at line 375 # spent 1.21ms making 1 call to DateTime::Format::Builder::Parser::BEGIN@375
# spent 9µs making 1 call to version::_VERSION
# spent 5µs making 1 call to Class::Factory::Util::import |
| 376 | |||||
| 377 | 1 | 4µs | 1 | 713µs | foreach my $worker ( __PACKAGE__->subclasses ) { # spent 713µs making 1 call to Class::Factory::Util::_subclasses |
| 378 | 5 | 150µs | eval "use DateTime::Format::Builder::Parser::$worker;"; # spent 829µs executing statements in string eval # includes 1.28ms spent executing 1 call to 1 sub defined therein. # spent 679µs executing statements in string eval # includes 957µs spent executing 1 call to 1 sub defined therein. # spent 653µs executing statements in string eval # includes 938µs spent executing 1 call to 1 sub defined therein. # spent 646µs executing statements in string eval # includes 1.06ms spent executing 1 call to 1 sub defined therein. # spent 9µs executing statements in string eval # includes 7µs spent executing 1 call to 1 sub defined therein. | ||
| 379 | 5 | 2µs | die $@ if $@; | ||
| 380 | } | ||||
| 381 | } | ||||
| 382 | |||||
| 383 | 1 | 7µs | 1; | ||
| 384 | |||||
| 385 | # ABSTRACT: Parser creation | ||||
| 386 | |||||
| 387 | __END__ | ||||
# spent 8µs within DateTime::Format::Builder::Parser::CORE:match which was called 14 times, avg 550ns/call:
# 14 times (8µs+0s) by DateTime::Format::Builder::Parser::__ANON__[/usr/share/perl5/DateTime/Format/Builder/Parser.pm:92] at line 92, avg 550ns/call |