| Filename | /usr/share/perl5/DateTime/Format/Builder/Parser/Regex.pm |
| Statements | Executed 75 statements in 1.21ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 1.20ms | 1.32ms | DateTime::Format::Builder::Parser::Regex::BEGIN@12 |
| 10 | 1 | 1 | 85µs | 286µs | DateTime::Format::Builder::Parser::Regex::create_parser |
| 20 | 2 | 1 | 20µs | 20µs | DateTime::Format::Builder::Parser::Regex::__ANON__[:24] |
| 1 | 1 | 1 | 11µs | 22µs | DateTime::Format::Builder::Parser::Regex::BEGIN@7 |
| 1 | 1 | 1 | 7µs | 39µs | DateTime::Format::Builder::Parser::Regex::BEGIN@10 |
| 1 | 1 | 1 | 7µs | 12µs | DateTime::Format::Builder::Parser::Regex::BEGIN@8 |
| 1 | 1 | 1 | 6µs | 24µs | DateTime::Format::Builder::Parser::Regex::BEGIN@9 |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Regex::__ANON__[:39] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Regex::do_match |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Regex::make |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Regex::post_match |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::Format::Builder::Parser::Regex; | ||||
| 2 | { | ||||
| 3 | 2 | 800ns | $DateTime::Format::Builder::Parser::Regex::VERSION = '0.81'; | ||
| 4 | } | ||||
| 5 | |||||
| 6 | |||||
| 7 | 2 | 22µs | 2 | 32µs | # spent 22µs (11+10) within DateTime::Format::Builder::Parser::Regex::BEGIN@7 which was called:
# once (11µs+10µs) by DateTime::Format::Builder::Parser::BEGIN@1.2 at line 7 # spent 22µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@7
# spent 10µs making 1 call to strict::import |
| 8 | 2 | 21µs | 2 | 18µs | # spent 12µs (7+6) within DateTime::Format::Builder::Parser::Regex::BEGIN@8 which was called:
# once (7µs+6µs) by DateTime::Format::Builder::Parser::BEGIN@1.2 at line 8 # spent 12µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@8
# spent 6µs making 1 call to warnings::import |
| 9 | 2 | 24µs | 2 | 41µs | # spent 24µs (6+17) within DateTime::Format::Builder::Parser::Regex::BEGIN@9 which was called:
# once (6µs+17µs) by DateTime::Format::Builder::Parser::BEGIN@1.2 at line 9 # spent 24µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@9
# spent 17µs making 1 call to vars::import |
| 10 | 2 | 22µs | 2 | 71µs | # spent 39µs (7+32) within DateTime::Format::Builder::Parser::Regex::BEGIN@10 which was called:
# once (7µs+32µs) by DateTime::Format::Builder::Parser::BEGIN@1.2 at line 10 # spent 39µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@10
# spent 32µs making 1 call to Exporter::import |
| 11 | |||||
| 12 | 2 | 988µs | 1 | 1.32ms | # spent 1.32ms (1.20+119µs) within DateTime::Format::Builder::Parser::Regex::BEGIN@12 which was called:
# once (1.20ms+119µs) by DateTime::Format::Builder::Parser::BEGIN@1.2 at line 12 # spent 1.32ms making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@12 |
| 13 | 1 | 6µs | @ISA = qw( DateTime::Format::Builder::Parser::generic ); | ||
| 14 | |||||
| 15 | __PACKAGE__->valid_params( | ||||
| 16 | |||||
| 17 | # How to match | ||||
| 18 | params => { | ||||
| 19 | type => ARRAYREF, # mapping $1,$2,... to new() args | ||||
| 20 | }, | ||||
| 21 | regex => { | ||||
| 22 | type => SCALARREF, | ||||
| 23 | callbacks => { | ||||
| 24 | 20 | 39µs | # spent 20µs within DateTime::Format::Builder::Parser::Regex::__ANON__[/usr/share/perl5/DateTime/Format/Builder/Parser/Regex.pm:24] which was called 20 times, avg 980ns/call:
# 10 times (10µs+0s) by Params::Validate::XS::validate at line 164 of DateTime/Format/Builder/Parser.pm, avg 1µs/call
# 10 times (9µs+0s) by Params::Validate::XS::validate at line 185 of DateTime/Format/Builder/Parser.pm, avg 940ns/call | ||
| 25 | } | ||||
| 26 | }, | ||||
| 27 | |||||
| 28 | # How to create | ||||
| 29 | extra => { | ||||
| 30 | type => HASHREF, | ||||
| 31 | optional => 1, | ||||
| 32 | }, | ||||
| 33 | constructor => { | ||||
| 34 | type => CODEREF | ARRAYREF, | ||||
| 35 | optional => 1, | ||||
| 36 | callbacks => { | ||||
| 37 | 'array has 2 elements' => sub { | ||||
| 38 | ref( $_[0] ) eq 'ARRAY' ? ( @{ $_[0] } == 2 ) : 1; | ||||
| 39 | } | ||||
| 40 | } | ||||
| 41 | }, | ||||
| 42 | 1 | 12µs | 1 | 9µs | ); # spent 9µs making 1 call to DateTime::Format::Builder::Parser::valid_params |
| 43 | |||||
| 44 | sub do_match { | ||||
| 45 | my $self = shift; | ||||
| 46 | my $date = shift; | ||||
| 47 | my @matches = $date =~ $self->{regex}; | ||||
| 48 | return @matches ? \@matches : undef; | ||||
| 49 | } | ||||
| 50 | |||||
| 51 | sub post_match { | ||||
| 52 | my $self = shift; | ||||
| 53 | my ( $date, $matches, $p ) = @_; | ||||
| 54 | |||||
| 55 | # Fill %p from match | ||||
| 56 | @{$p}{ @{ $self->{params} } } = @$matches; | ||||
| 57 | return; | ||||
| 58 | } | ||||
| 59 | |||||
| 60 | sub make { | ||||
| 61 | my $self = shift; | ||||
| 62 | my ( $date, $dt, $p ) = @_; | ||||
| 63 | my @args = ( %$p, %{ $self->{extra} } ); | ||||
| 64 | if ( my $cons = $self->{constructor} ) { | ||||
| 65 | if ( ref $cons eq 'ARRAY' ) { | ||||
| 66 | my ( $class, $method ) = @$cons; | ||||
| 67 | return $class->$method(@args); | ||||
| 68 | } | ||||
| 69 | elsif ( ref $cons eq 'CODE' ) { | ||||
| 70 | return $self->$cons(@args); | ||||
| 71 | } | ||||
| 72 | } | ||||
| 73 | else { | ||||
| 74 | return DateTime->new(@args); | ||||
| 75 | } | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | # spent 286µs (85+200) within DateTime::Format::Builder::Parser::Regex::create_parser which was called 10 times, avg 29µs/call:
# 10 times (85µs+200µs) by DateTime::Format::Builder::Parser::create_single_parser at line 186 of DateTime/Format/Builder/Parser.pm, avg 29µs/call | ||||
| 79 | 10 | 8µs | my ( $self, %args ) = @_; | ||
| 80 | 10 | 3µs | $args{extra} ||= {}; | ||
| 81 | 10 | 17µs | 10 | 22µs | unless ( ref $self ) { # spent 22µs making 10 calls to DateTime::Format::Builder::Parser::generic::new, avg 2µs/call |
| 82 | $self = $self->new(%args); | ||||
| 83 | } | ||||
| 84 | |||||
| 85 | # Create our parser | ||||
| 86 | return $self->generic_parser( | ||||
| 87 | ( | ||||
| 88 | 10 | 39µs | 10 | 178µs | map { exists $args{$_} ? ( $_ => $args{$_} ) : () } # spent 178µs making 10 calls to DateTime::Format::Builder::Parser::generic::generic_parser, avg 18µs/call |
| 89 | qw( | ||||
| 90 | on_match on_fail preprocess postprocess | ||||
| 91 | ) | ||||
| 92 | ), | ||||
| 93 | label => $args{label}, | ||||
| 94 | ); | ||||
| 95 | } | ||||
| 96 | |||||
| 97 | 1 | 4µs | 1; | ||
| 98 | |||||
| 99 | # ABSTRACT: Regex based date parsing | ||||
| 100 | |||||
| 101 | __END__ |