← Index
NYTProf Performance Profile   « block view • line view • sub view »
For xt/tapper-mcp-scheduler-with-db-longrun.t
  Run on Tue May 22 17:18:39 2012
Reported on Tue May 22 17:23:22 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DateTime/Format/Builder/Parser/generic.pm
StatementsExecuted 70 statements in 781µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
711110µs299µsDateTime::Format::Builder::Parser::generic::::generic_parserDateTime::Format::Builder::Parser::generic::generic_parser
71127µs27µsDateTime::Format::Builder::Parser::generic::::newDateTime::Format::Builder::Parser::generic::new
11115µs17µsDateTime::Format::Builder::Parser::generic::::BEGIN@2DateTime::Format::Builder::Parser::generic::BEGIN@2
1118µs46µsDateTime::Format::Builder::Parser::generic::::BEGIN@4DateTime::Format::Builder::Parser::generic::BEGIN@4
1117µs19µsDateTime::Format::Builder::Parser::generic::::BEGIN@171DateTime::Format::Builder::Parser::generic::BEGIN@171
1117µs43µsDateTime::Format::Builder::Parser::generic::::BEGIN@5DateTime::Format::Builder::Parser::generic::BEGIN@5
1116µs22µsDateTime::Format::Builder::Parser::generic::::BEGIN@3DateTime::Format::Builder::Parser::generic::BEGIN@3
0000s0sDateTime::Format::Builder::Parser::generic::::__ANON__[:125]DateTime::Format::Builder::Parser::generic::__ANON__[:125]
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package DateTime::Format::Builder::Parser::generic;
2320µs219µs
# spent 17µs (15+2) within DateTime::Format::Builder::Parser::generic::BEGIN@2 which was called: # once (15µs+2µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 2
use strict;
# spent 17µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@2 # spent 2µs making 1 call to strict::import
3318µs238µs
# spent 22µs (6+16) within DateTime::Format::Builder::Parser::generic::BEGIN@3 which was called: # once (6µs+16µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 3
use vars qw( $VERSION );
# spent 22µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@3 # spent 16µs making 1 call to vars::import
4323µs283µs
# spent 46µs (8+37) within DateTime::Format::Builder::Parser::generic::BEGIN@4 which was called: # once (8µs+37µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 4
use Carp;
# spent 46µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@4 # spent 37µs making 1 call to Exporter::import
5136µs
# spent 43µs (7+36) within DateTime::Format::Builder::Parser::generic::BEGIN@5 which was called: # once (7µs+36µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 7
use Params::Validate qw(
# spent 36µs making 1 call to Exporter::import
6 validate SCALAR CODEREF UNDEF
73338µs143µs);
8
91600ns$VERSION = '0.77';
10
11=head1 NAME
12
13DateTime::Format::Builder::Parser::generic - Useful routines
14
15=head1 METHODS
16
17=head2 Useful
18
19=head3 new
20
21Standard constructor. Returns a blessed hash; any arguments are placed
22in the hash. This is useful for storing information between methods.
23
24=cut
25
26sub new
27
# spent 27µs within DateTime::Format::Builder::Parser::generic::new which was called 7 times, avg 4µs/call: # 7 times (27µs+0s) by DateTime::Format::Builder::Parser::Regex::create_parser at line 143 of DateTime/Format/Builder/Parser/Regex.pm, avg 4µs/call
{
281435µs my $class = shift;
29 bless { @_ }, $class;
30}
31
32=head3 generic_parser
33
34This is a method provided solely for the benefit of
35C<Parser> implementations. It semi-neatly abstracts
36a lot of the work involved.
37
38Basically, it takes parameters matching the assorted
39callbacks from the parser declarations and makes a coderef
40out of it all.
41
42Currently recognized callbacks are:
43
44=over 4
45
46=item *
47
48on_match
49
50=item *
51
52on_fail
53
54=item *
55
56preprocess
57
58=item *
59
60postprocess
61
62=back
63
64=cut
65
66
# spent 299µs (110+188) within DateTime::Format::Builder::Parser::generic::generic_parser which was called 7 times, avg 43µs/call: # 7 times (110µs+188µs) by DateTime::Format::Builder::Parser::Regex::create_parser at line 150 of DateTime/Format/Builder/Parser/Regex.pm, avg 43µs/call
sub generic_parser {
6735191µs my $class = shift;
68 my %args = validate( @_, {
691104µs7188µs ( map { $_ => { type => CODEREF, optional => 1 } } qw(
# spent 188µs making 7 calls to Params::Validate::XS::validate, avg 27µs/call
# spent 13µs executing statements in 7 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
130These are methods you should define when writing your own subclass.
131
132B<Note>: these methods do not exist in this class. There is no point
133trying to call C<< $self->SUPER::do_match( ... ) >>.
134
135=head3 do_match
136
137C<do_match> is the first phase. Arguments are the date and @args.
138C<self>, C<label>, C<args>. Return value must be defined if you match
139successfully.
140
141=head3 post_match
142
143C<post_match> is called after the appropriate callback out of
144C<on_match>/C<on_fail> is done. It's passed the date, the return
145value from C<do_match> and the parsing hash.
146
147Its return value is used as the C<post> argument to the C<postprocess>
148callback, and as the second argument to C<make>.
149
150=head3 make
151
152C<make> takes the original input, the return value from C<post_match>
153and the parsing hash and should return a C<DateTime> object or
154undefined.
155
156=head2 Delegations
157
158For use of C<Parser>, this module also delegates C<valid_params> and
159C<params>. This is just convenience to save typing the following:
160
161 DateTime::Format::Builder::Parser->valid_params( blah )
162
163Instead we get to type:
164
165 $self->valid_params( blah );
166 __PACKAGE__->valid_params( blah );
167
168=cut
169
170{
171440µs231µs
# spent 19µs (7+12) within DateTime::Format::Builder::Parser::generic::BEGIN@171 which was called: # once (7µs+12µs) by DateTime::Format::Builder::Parser::Regex::BEGIN@73 at line 171
no strict 'refs';
# spent 19µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@171 # spent 12µs making 1 call to strict::unimport
1721600ns for (qw( valid_params params ))
173 {
17427µs *$_ = *{"DateTime::Format::Builder::Parser::$_"};
175 }
176}
177
17814µs1;
179
180__END__