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 | 236µs | 670µs | generic_parser | DateTime::Format::Builder::Parser::generic::
10 | 1 | 1 | 54µs | 54µs | new | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 20µs | 120µs | BEGIN@5 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 19µs | 23µs | BEGIN@2 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 19µs | 101µs | BEGIN@4 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 18µs | 64µs | BEGIN@3 | DateTime::Format::Builder::Parser::generic::
1 | 1 | 1 | 14µs | 32µs | BEGIN@171 | 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 | 32µs | 2 | 28µ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 | 41µs | 2 | 111µs | # spent 64µs (18+47) within DateTime::Format::Builder::Parser::generic::BEGIN@3 which was called:
# once (18µs+47µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 3 # spent 64µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@3
# spent 47µs making 1 call to vars::import |
4 | 3 | 66µs | 2 | 183µs | # spent 101µs (19+82) within DateTime::Format::Builder::Parser::generic::BEGIN@4 which was called:
# once (19µs+82µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 4 # spent 101µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@4
# spent 82µs making 1 call to Exporter::import |
5 | 1 | 10µs | 1 | 100µs | # spent 120µs (20+100) within DateTime::Format::Builder::Parser::generic::BEGIN@5 which was called:
# once (20µs+100µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 7 # spent 100µs making 1 call to Exporter::import |
6 | validate SCALAR CODEREF UNDEF | ||||
7 | 2 | 442µs | 1 | 120µs | ); # spent 120µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@5 |
8 | |||||
9 | 1 | 2µs | $VERSION = '0.77'; | ||
10 | |||||
11 | =head1 NAME | ||||
12 | |||||
- - | |||||
26 | sub new | ||||
27 | # spent 54µs within DateTime::Format::Builder::Parser::generic::new which was called 10 times, avg 5µs/call:
# 10 times (54µs+0s) by DateTime::Format::Builder::Parser::Regex::create_parser at line 143 of DateTime/Format/Builder/Parser/Regex.pm, avg 5µs/call | ||||
28 | 10 | 5µs | my $class = shift; | ||
29 | 10 | 63µs | bless { @_ }, $class; | ||
30 | } | ||||
31 | |||||
32 | =head3 generic_parser | ||||
33 | |||||
- - | |||||
66 | # spent 670µs (236+434) within DateTime::Format::Builder::Parser::generic::generic_parser which was called 10 times, avg 67µs/call:
# 10 times (236µs+434µs) by DateTime::Format::Builder::Parser::Regex::create_parser at line 150 of DateTime/Format/Builder/Parser/Regex.pm, avg 67µs/call | ||||
67 | 10 | 5µs | my $class = shift; | ||
68 | my %args = validate( @_, { | ||||
69 | 10 | 547µs | 10 | 434µs | ( map { $_ => { type => CODEREF, optional => 1 } } qw( # spent 434µs making 10 calls to Params::Validate::_validate, avg 43µs/call # spent 42µ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 | 10 | 7µs | my $label = $args{label}; | ||
75 | |||||
76 | 10 | 8µs | 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 | 10 | 77µs | }; | ||
126 | } | ||||
127 | |||||
128 | =head2 Methods for subclassing | ||||
129 | |||||
- - | |||||
170 | { | ||||
171 | 4 | 74µs | 2 | 52µs | # spent 32µs (14+19) within DateTime::Format::Builder::Parser::generic::BEGIN@171 which was called:
# once (14µs+19µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 171 # spent 32µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@171
# spent 19µs making 1 call to strict::unimport |
172 | 1 | 2µs | for (qw( valid_params params )) | ||
173 | { | ||||
174 | 2 | 16µs | *$_ = *{"DateTime::Format::Builder::Parser::$_"}; | ||
175 | } | ||||
176 | } | ||||
177 | |||||
178 | 1 | 6µs | 1; | ||
179 | |||||
180 | __END__ |