← 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:22:38 2012

Filename/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DateTime/Format/Builder/Parser/Regex.pm
StatementsExecuted 62 statements in 578µs
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111490µs636µsDateTime::Format::Builder::Parser::Regex::::BEGIN@73DateTime::Format::Builder::Parser::Regex::BEGIN@73
71178µs404µsDateTime::Format::Builder::Parser::Regex::::create_parserDateTime::Format::Builder::Parser::Regex::create_parser
142123µs23µsDateTime::Format::Builder::Parser::Regex::::__ANON__[:84]DateTime::Format::Builder::Parser::Regex::__ANON__[:84]
11114µs16µsDateTime::Format::Builder::Parser::Regex::::BEGIN@68DateTime::Format::Builder::Parser::Regex::BEGIN@68
1117µs36µsDateTime::Format::Builder::Parser::Regex::::BEGIN@69DateTime::Format::Builder::Parser::Regex::BEGIN@69
1117µs48µsDateTime::Format::Builder::Parser::Regex::::BEGIN@70DateTime::Format::Builder::Parser::Regex::BEGIN@70
4216µs6µsDateTime::Format::Builder::Parser::Regex::::__ANON__[:98]DateTime::Format::Builder::Parser::Regex::__ANON__[:98]
0000s0sDateTime::Format::Builder::Parser::Regex::::do_matchDateTime::Format::Builder::Parser::Regex::do_match
0000s0sDateTime::Format::Builder::Parser::Regex::::makeDateTime::Format::Builder::Parser::Regex::make
0000s0sDateTime::Format::Builder::Parser::Regex::::post_matchDateTime::Format::Builder::Parser::Regex::post_match
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::Regex;
2
3=head1 NAME
4
5DateTime::Format::Builder::Parser::Regex - Regex based date parsing
6
7=head1 SYNOPSIS
8
9 my $parser = DateTime::Format::Builder->create_parser(
10 regex => qr/^(\d\d\d\d)(\d\d)(\d\d)T(\d\d)(\d\d)(\d\d)$/,
11 params => [ qw( year month day hour minute second ) ],
12 );
13
14=head1 SPECIFICATION
15
16In addition to the
17L<common keys|DateTime::Format::Builder/"SINGLE SPECIFICATIONS">,
18C<Regex> supports:
19
20=over 4
21
22=item *
23
24B<regex> is a regular expression that should capture
25elements of the datetime string.
26This is a required element. This is the key whose presence
27indicates it's a specification that belongs to this class.
28
29=item *
30
31B<params> is an arrayref of key names. The captures from the
32regex are mapped to these (C<$1> to the first element, C<$2>
33to the second, and so on) and handed to
34C<< DateTime->new() >>.
35This is a required element.
36
37=item *
38
39B<extra> is a hashref of extra arguments you wish to give to
40C<< DateTime->new() >>. For example, you could set the
41C<year> or C<time_zone> to defaults:
42
43 extra => { year => 2004, time_zone => "Australia/Sydney" },
44
45=item *
46
47B<constructor> is either an arrayref or a coderef. If an arrayref
48then the first element is a class name or object, and the second
49element is a method name (or coderef since Perl allows that sort of
50thing). The arguments to the call are anything in C<$p> and
51anything given in the C<extra> option above.
52
53If only a coderef is supplied, then it is called with arguments of
54C<$self>, C<$p> and C<extra>.
55
56In short:
57
58 $self->$coderef( %$p, %{ $self->{extra} } );
59
60The method is expected to return a valid L<DateTime> object,
61or undef in event of failure, but can conceivably return anything
62it likes. So long as it's 'true'.
63
64=back
65
66=cut
67
68328µs218µs
# spent 16µs (14+2) within DateTime::Format::Builder::Parser::Regex::BEGIN@68 which was called: # once (14µs+2µs) by DateTime::Format::Builder::Parser::BEGIN@1.40 at line 68
use strict;
# spent 16µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@68 # spent 2µs making 1 call to strict::import
69321µs265µs
# spent 36µs (7+29) within DateTime::Format::Builder::Parser::Regex::BEGIN@69 which was called: # once (7µs+29µs) by DateTime::Format::Builder::Parser::BEGIN@1.40 at line 69
use vars qw( $VERSION @ISA );
# spent 36µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@69 # spent 29µs making 1 call to vars::import
70327µs289µs
# spent 48µs (7+41) within DateTime::Format::Builder::Parser::Regex::BEGIN@70 which was called: # once (7µs+41µs) by DateTime::Format::Builder::Parser::BEGIN@1.40 at line 70
use Params::Validate qw( validate ARRAYREF SCALARREF HASHREF CODEREF );
# spent 48µs making 1 call to DateTime::Format::Builder::Parser::Regex::BEGIN@70 # spent 41µs making 1 call to Exporter::import
71
721500ns$VERSION = '0.77';
733352µs1636µs
# spent 636µs (490+146) within DateTime::Format::Builder::Parser::Regex::BEGIN@73 which was called: # once (490µs+146µs) by DateTime::Format::Builder::Parser::BEGIN@1.40 at line 73
use DateTime::Format::Builder::Parser::generic;
7419µs@ISA = qw( DateTime::Format::Builder::Parser::generic );
75
76__PACKAGE__->valid_params(
77# How to match
78 params => {
79 type => ARRAYREF, # mapping $1,$2,... to new() args
80 },
81 regex => {
82 type => SCALARREF,
83 callbacks => {
841443µs
# spent 23µs within DateTime::Format::Builder::Parser::Regex::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DateTime/Format/Builder/Parser/Regex.pm:84] which was called 14 times, avg 2µs/call: # 7 times (12µs+0s) by Params::Validate::XS::validate at line 311 of DateTime/Format/Builder/Parser.pm, avg 2µs/call # 7 times (11µs+0s) by Params::Validate::XS::validate at line 333 of DateTime/Format/Builder/Parser.pm, avg 2µs/call
'is a regex' => sub { ref(shift) eq 'Regexp' }
85 }
86 },
87# How to create
88 extra => {
89 type => HASHREF,
90 optional => 1,
91 },
92 constructor => {
93 type => CODEREF|ARRAYREF,
94 optional => 1,
95 callbacks => {
96
# spent 6µs within DateTime::Format::Builder::Parser::Regex::__ANON__[/2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DateTime/Format/Builder/Parser/Regex.pm:98] which was called 4 times, avg 2µs/call: # 2 times (4µs+0s) by Params::Validate::XS::validate at line 311 of DateTime/Format/Builder/Parser.pm, avg 2µs/call # 2 times (3µs+0s) by Params::Validate::XS::validate at line 333 of DateTime/Format/Builder/Parser.pm, avg 1µs/call
'array has 2 elements' => sub {
97414µs ref($_[0]) eq 'ARRAY' ? (@{$_[0]} == 2) : 1
98 }
99 }
100 },
101112µs113µs);
102
103sub do_match
104{
105 my $self = shift;
106 my $date = shift;
107 my @matches = $date =~ $self->{regex};
108 return @matches ? \@matches : undef;
109}
110
111sub post_match
112{
113 my $self = shift;
114 my ( $date, $matches, $p ) = @_;
115 # Fill %p from match
116 @{$p}{ @{ $self->{params} } } = @$matches;
117 return;
118}
119
120sub make {
121 my $self = shift;
122 my ( $date, $dt, $p ) = @_;
123 my @args = ( %$p, %{ $self->{extra} } );
124 if (my $cons = $self->{constructor})
125 {
126 if (ref $cons eq 'ARRAY') {
127 my ($class, $method) = @$cons;
128 return $class->$method(@args);
129 } elsif (ref $cons eq 'CODE') {
130 return $self->$cons( @args );
131 }
132 }
133 else
134 {
135 return DateTime->new(@args);
136 }
137}
138
139sub create_parser
140
# spent 404µs (78+326) within DateTime::Format::Builder::Parser::Regex::create_parser which was called 7 times, avg 58µs/call: # 7 times (78µs+326µs) by DateTime::Format::Builder::Parser::create_single_parser at line 334 of DateTime/Format/Builder/Parser.pm, avg 58µs/call
{
1412866µs my ($self, %args) = @_;
142 $args{extra} ||= {};
143727µs unless (ref $self)
# spent 27µs making 7 calls to DateTime::Format::Builder::Parser::generic::new, avg 4µs/call
144 {
145 $self = $self->new( %args );
146 }
147
148 # Create our parser
149 return $self->generic_parser(
1507299µs ( map { exists $args{$_} ? ( $_ => $args{$_} ) : () } qw(
# spent 299µs making 7 calls to DateTime::Format::Builder::Parser::generic::generic_parser, avg 43µs/call
151 on_match on_fail preprocess postprocess
152 ) ),
153 label => $args{label},
154 );
155}
156
157
15816µs1;
159
160__END__