Filename | /usr/share/perl5/DateTime/Format/Builder/Parser/generic.pm |
Statements | Executed 87 statements in 788µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
10 | 1 | 1 | 113µs | 178µs | generic_parser | DateTime::Format::Builder::Parser::generic::
10 | 1 | 1 | 22µs | 22µs | new | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 12µs | 22µs | BEGIN@5 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 7µs | 12µs | BEGIN@6 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 7µs | 35µs | BEGIN@7 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 7µs | 16µs | BEGIN@89 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 6µs | 34µs | BEGIN@8 | DateTime::Format::Builder::Parser::generic::
0 | 0 | 0 | 0s | 0s | __ANON__[:84] | DateTime::Format::Builder::Parser::generic::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package DateTime::Format::Builder::Parser::generic; | ||||
2 | { | ||||
3 | 2 | 800ns | $DateTime::Format::Builder::Parser::generic::VERSION = '0.81'; | ||
4 | } | ||||
5 | 2 | 27µs | 2 | 32µs | # spent 22µs (12+10) within DateTime::Format::Builder::Parser::generic::BEGIN@5 which was called:
# once (12µs+10µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@12 at line 5 # spent 22µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@5
# spent 10µs making 1 call to strict::import |
6 | 2 | 18µs | 2 | 16µs | # spent 12µs (7+4) within DateTime::Format::Builder::Parser::generic::BEGIN@6 which was called:
# once (7µs+4µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@12 at line 6 # spent 12µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@6
# spent 4µs making 1 call to warnings::import |
7 | 2 | 30µs | 2 | 62µs | # spent 35µs (7+27) within DateTime::Format::Builder::Parser::generic::BEGIN@7 which was called:
# once (7µs+27µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@12 at line 7 # spent 35µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@7
# spent 27µs making 1 call to Exporter::import |
8 | 1 | 3µs | 1 | 28µs | # spent 34µs (6+28) within DateTime::Format::Builder::Parser::generic::BEGIN@8 which was called:
# once (6µs+28µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@12 at line 10 # spent 28µs making 1 call to Exporter::import |
9 | validate SCALAR CODEREF UNDEF | ||||
10 | 1 | 429µs | 1 | 34µs | ); # spent 34µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@8 |
11 | |||||
- - | |||||
14 | # spent 22µs within DateTime::Format::Builder::Parser::generic::new which was called 10 times, avg 2µs/call:
# 10 times (22µs+0s) by DateTime::Format::Builder::Parser::Regex::create_parser at line 81 of DateTime/Format/Builder/Parser/Regex.pm, avg 2µs/call | ||||
15 | 10 | 2µs | my $class = shift; | ||
16 | 10 | 33µs | bless {@_}, $class; | ||
17 | } | ||||
18 | |||||
19 | |||||
20 | # spent 178µs (113+65) within DateTime::Format::Builder::Parser::generic::generic_parser which was called 10 times, avg 18µs/call:
# 10 times (113µs+65µs) by DateTime::Format::Builder::Parser::Regex::create_parser at line 88 of DateTime/Format/Builder/Parser/Regex.pm, avg 18µs/call | ||||
21 | 10 | 2µs | my $class = shift; | ||
22 | my %args = validate( | ||||
23 | @_, | ||||
24 | { | ||||
25 | ( | ||||
26 | 10 | 140µs | 10 | 65µs | map { $_ => { type => CODEREF, optional => 1 } } # spent 65µs making 10 calls to Params::Validate::XS::validate, avg 7µs/call |
27 | qw( | ||||
28 | on_match on_fail preprocess postprocess | ||||
29 | ) | ||||
30 | ), | ||||
31 | label => { type => SCALAR | UNDEF, optional => 1 }, | ||||
32 | } | ||||
33 | ); | ||||
34 | 10 | 2µs | my $label = $args{label}; | ||
35 | |||||
36 | 10 | 4µs | my $callback | ||
37 | = ( exists $args{on_match} or exists $args{on_fail} ) ? 1 : undef; | ||||
38 | |||||
39 | return sub { | ||||
40 | my ( $self, $date, $p, @args ) = @_; | ||||
41 | return unless defined $date; | ||||
42 | my %p; | ||||
43 | %p = %$p if $p; # Look! A Copy! | ||||
44 | |||||
45 | my %param = ( | ||||
46 | self => $self, | ||||
47 | ( defined $label ? ( label => $label ) : () ), | ||||
48 | ( @args ? ( args => \@args ) : () ), | ||||
49 | ); | ||||
50 | |||||
51 | # Preprocess - can modify $date and fill %p | ||||
52 | if ( $args{preprocess} ) { | ||||
53 | $date = $args{preprocess} | ||||
54 | ->( input => $date, parsed => \%p, %param ); | ||||
55 | } | ||||
56 | |||||
57 | my $rv = $class->do_match( $date, @args ) if $class->can('do_match'); | ||||
58 | |||||
59 | # Funky callback thing | ||||
60 | if ($callback) { | ||||
61 | my $type = defined $rv ? "on_match" : "on_fail"; | ||||
62 | $args{$type}->( input => $date, %param ) if $args{$type}; | ||||
63 | } | ||||
64 | return unless defined $rv; | ||||
65 | |||||
66 | my $dt; | ||||
67 | $dt = $class->post_match( $date, $rv, \%p ) | ||||
68 | if $class->can('post_match'); | ||||
69 | |||||
70 | # Allow post processing. Return undef if regarded as failure | ||||
71 | if ( $args{postprocess} ) { | ||||
72 | my $rv = $args{postprocess}->( | ||||
73 | parsed => \%p, | ||||
74 | input => $date, | ||||
75 | post => $dt, | ||||
76 | %param, | ||||
77 | ); | ||||
78 | return unless $rv; | ||||
79 | } | ||||
80 | |||||
81 | # A successful match! | ||||
82 | $dt = $class->make( $date, $dt, \%p ) if $class->can('make'); | ||||
83 | return $dt; | ||||
84 | 10 | 42µs | }; | ||
85 | } | ||||
86 | |||||
87 | |||||
88 | { | ||||
89 | 3 | 46µs | 2 | 25µs | # spent 16µs (7+9) within DateTime::Format::Builder::Parser::generic::BEGIN@89 which was called:
# once (7µs+9µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@12 at line 89 # spent 16µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@89
# spent 9µs making 1 call to strict::unimport |
90 | 1 | 400ns | for (qw( valid_params params )) { | ||
91 | 2 | 6µs | *$_ = *{"DateTime::Format::Builder::Parser::$_"}; | ||
92 | } | ||||
93 | } | ||||
94 | |||||
95 | 1 | 3µs | 1; | ||
96 | |||||
97 | # ABSTRACT: Useful routines | ||||
98 | |||||
99 | __END__ |