Filename | /usr/share/perl5/DateTime/Format/Builder/Parser/generic.pm |
Statements | Executed 91 statements in 1.40ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
10 | 1 | 1 | 264µs | 744µs | generic_parser | DateTime::Format::Builder::Parser::generic::
10 | 1 | 1 | 56µs | 56µs | new | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 19µs | 23µs | BEGIN@2 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 19µs | 90µs | BEGIN@4 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 12µs | 29µs | BEGIN@171 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 11µs | 63µs | BEGIN@5 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 9µs | 34µs | BEGIN@3 | DateTime::Format::Builder::Parser::generic::
0 | 0 | 0 | 0s | 0s | __ANON__[:125] | 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 | 34µs | 2 | 27µs | # spent 23µs (19+4) within DateTime::Format::Builder::Parser::generic::BEGIN@2 which was called:
# once (19µs+4µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 2 # spent 23µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@2
# spent 4µs making 1 call to strict::import |
3 | 3 | 39µs | 2 | 60µs | # spent 34µs (9+26) within DateTime::Format::Builder::Parser::generic::BEGIN@3 which was called:
# once (9µs+26µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 3 # spent 34µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@3
# spent 25µs making 1 call to vars::import |
4 | 3 | 50µs | 2 | 161µs | # spent 90µs (19+71) within DateTime::Format::Builder::Parser::generic::BEGIN@4 which was called:
# once (19µs+71µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 4 # spent 90µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@4
# spent 71µs making 1 call to Exporter::import |
5 | 1 | 52µs | # spent 63µs (11+52) within DateTime::Format::Builder::Parser::generic::BEGIN@5 which was called:
# once (11µs+52µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 7 # spent 52µs making 1 call to Exporter::import | ||
6 | validate SCALAR CODEREF UNDEF | ||||
7 | 3 | 416µs | 1 | 63µs | ); # spent 63µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@5 |
8 | |||||
9 | 1 | 1µs | $VERSION = '0.77'; | ||
10 | |||||
11 | =head1 NAME | ||||
12 | |||||
- - | |||||
26 | sub new | ||||
27 | # spent 56µs within DateTime::Format::Builder::Parser::generic::new which was called 10 times, avg 6µs/call:
# 10 times (56µs+0s) by DateTime::Format::Builder::Parser::Regex::create_parser at line 143 of DateTime/Format/Builder/Parser/Regex.pm, avg 6µs/call | ||||
28 | 20 | 71µs | my $class = shift; | ||
29 | bless { @_ }, $class; | ||||
30 | } | ||||
31 | |||||
32 | =head3 generic_parser | ||||
33 | |||||
- - | |||||
66 | # spent 744µs (264+480) within DateTime::Format::Builder::Parser::generic::generic_parser which was called 10 times, avg 74µs/call:
# 10 times (264µs+480µs) by DateTime::Format::Builder::Parser::Regex::create_parser at line 150 of DateTime/Format/Builder/Parser/Regex.pm, avg 74µs/call | ||||
67 | 50 | 451µs | my $class = shift; | ||
68 | my %args = validate( @_, { | ||||
69 | 1 | 258µs | 10 | 480µs | ( map { $_ => { type => CODEREF, optional => 1 } } qw( # spent 480µs making 10 calls to Params::Validate::_validate, avg 48µs/call # spent 54µs executing statements in 10 string evals (merged) |
70 | on_match on_fail preprocess postprocess | ||||
71 | ) ), | ||||
72 | label => { type => SCALAR|UNDEF, optional => 1 }, | ||||
73 | }); | ||||
74 | my $label = $args{label}; | ||||
75 | |||||
76 | my $callback = (exists $args{on_match} or exists $args{on_fail}) ? 1 : undef; | ||||
77 | |||||
78 | return sub | ||||
79 | { | ||||
80 | my ($self, $date, $p, @args) = @_; | ||||
81 | return unless defined $date; | ||||
82 | my %p; | ||||
83 | %p = %$p if $p; # Look! A Copy! | ||||
84 | |||||
85 | my %param = ( | ||||
86 | self => $self, | ||||
87 | ( defined $label ? ( label => $label ) : ()), | ||||
88 | (@args ? (args => \@args) : ()), | ||||
89 | ); | ||||
90 | |||||
91 | # Preprocess - can modify $date and fill %p | ||||
92 | if ($args{preprocess}) | ||||
93 | { | ||||
94 | $date = $args{preprocess}->( input => $date, parsed => \%p, %param ); | ||||
95 | } | ||||
96 | |||||
97 | my $rv = $class->do_match( $date, @args ) if $class->can('do_match'); | ||||
98 | |||||
99 | # Funky callback thing | ||||
100 | if ($callback) | ||||
101 | { | ||||
102 | my $type = defined $rv ? "on_match" : "on_fail"; | ||||
103 | $args{$type}->( input => $date, %param ) if $args{$type}; | ||||
104 | } | ||||
105 | return unless defined $rv; | ||||
106 | |||||
107 | my $dt; | ||||
108 | $dt = $class->post_match( $date, $rv, \%p ) if $class->can('post_match'); | ||||
109 | |||||
110 | # Allow post processing. Return undef if regarded as failure | ||||
111 | if ($args{postprocess}) | ||||
112 | { | ||||
113 | my $rv = $args{postprocess}->( | ||||
114 | parsed => \%p, | ||||
115 | input => $date, | ||||
116 | post => $dt, | ||||
117 | %param, | ||||
118 | ); | ||||
119 | return unless $rv; | ||||
120 | } | ||||
121 | |||||
122 | # A successful match! | ||||
123 | $dt = $class->make( $date, $dt, \%p ) if $class->can('make'); | ||||
124 | return $dt; | ||||
125 | }; | ||||
126 | } | ||||
127 | |||||
128 | =head2 Methods for subclassing | ||||
129 | |||||
- - | |||||
170 | { | ||||
171 | 4 | 61µs | 2 | 46µs | # spent 29µs (12+17) within DateTime::Format::Builder::Parser::generic::BEGIN@171 which was called:
# once (12µs+17µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 171 # spent 29µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@171
# spent 17µs making 1 call to strict::unimport |
172 | 1 | 1µs | for (qw( valid_params params )) | ||
173 | { | ||||
174 | 2 | 12µs | *$_ = *{"DateTime::Format::Builder::Parser::$_"}; | ||
175 | } | ||||
176 | } | ||||
177 | |||||
178 | 1 | 5µs | 1; | ||
179 | |||||
180 | __END__ |