Profile of DateTime/Format/Builder/Parser/Dispatch.pm

← 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/Dispatch.pm
Statements | Executed 21 statements in 302µs

Subroutines
Calls | P | F | Exclusive Time | Inclusive Time | Subroutine
--- | --- | --- | --- | --- | ---
1 | 1 | 1 | 14µs | 17µs | DateTime::Format::Builder::Parser::Dispatch::::BEGIN@2DateTime::Format::Builder::Parser::Dispatch::BEGIN@2
1 | 1 | 1 | 9µs | 9µs | DateTime::Format::Builder::Parser::Dispatch::::BEGIN@5DateTime::Format::Builder::Parser::Dispatch::BEGIN@5
1 | 1 | 1 | 9µs | 41µs | DateTime::Format::Builder::Parser::Dispatch::::BEGIN@4DateTime::Format::Builder::Parser::Dispatch::BEGIN@4
1 | 1 | 1 | 8µs | 39µs | DateTime::Format::Builder::Parser::Dispatch::::BEGIN@3DateTime::Format::Builder::Parser::Dispatch::BEGIN@3
1 | 1 | 1 | 7µs | 16µs | DateTime::Format::Builder::Parser::Dispatch::::BEGIN@78DateTime::Format::Builder::Parser::Dispatch::BEGIN@78
0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Dispatch::::__ANON__[:111]DateTime::Format::Builder::Parser::Dispatch::__ANON__[:111]
0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Dispatch::::create_parserDateTime::Format::Builder::Parser::Dispatch::create_parser

Call graph for these subroutines as a Graphviz dot language file.

Line | State ments | Time on line | Calls | Time in subs | Code
--- | --- | --- | --- | --- | ---
1 |  |  |  |  | package DateTime::Format::Builder::Parser::Dispatch;
2 | 3 | 23µs | 2 | 20µs | # spent 17µs (14+3) within DateTime::Format::Builder::Parser::Dispatch::BEGIN@2 which was called: # once (14µs+3µs) by DateTime::Format::Builder::Parser::BEGIN@1 at line 2 use strict; # spent 17µs making 1 call to DateTime::Format::Builder::Parser::Dispatch::BEGIN@2 # spent 3µs making 1 call to strict::import
3 | 3 | 25µs | 2 | 70µs | # spent 39µs (8+31) within DateTime::Format::Builder::Parser::Dispatch::BEGIN@3 which was called: # once (8µs+31µs) by DateTime::Format::Builder::Parser::BEGIN@1 at line 3 use vars qw( $VERSION %dispatch_data ); # spent 39µs making 1 call to DateTime::Format::Builder::Parser::Dispatch::BEGIN@3 # spent 31µs making 1 call to vars::import
4 | 3 | 21µs | 2 | 73µs | # spent 41µs (9+32) within DateTime::Format::Builder::Parser::Dispatch::BEGIN@4 which was called: # once (9µs+32µs) by DateTime::Format::Builder::Parser::BEGIN@1 at line 4 use Params::Validate qw( CODEREF validate ); # spent 41µs making 1 call to DateTime::Format::Builder::Parser::Dispatch::BEGIN@4 # spent 32µs making 1 call to Exporter::import
5 | 3 | 54µs | 1 | 9µs | # spent 9µs within DateTime::Format::Builder::Parser::Dispatch::BEGIN@5 which was called: # once (9µs+0s) by DateTime::Format::Builder::Parser::BEGIN@1 at line 5 use DateTime::Format::Builder::Parser; # spent 9µs making 1 call to DateTime::Format::Builder::Parser::Dispatch::BEGIN@5
6 |  |  |  |  |
7 |  |  |  |  | =head1 NAME
8 |  |  |  |  |
9 |  |  |  |  | DateTime::Format::Builder::Parser::Dispatch - Dispatch parsers by group
10 |  |  |  |  |
11 |  |  |  |  | =head1 SYNOPSIS
12 |  |  |  |  |
13 |  |  |  |  | package SampleDispatch;
14 |  |  |  |  | use DateTime::Format::Builder
15 |  |  |  |  | (
16 |  |  |  |  | parsers => {
17 |  |  |  |  | parse_datetime => [
18 |  |  |  |  | {
19 |  |  |  |  | Dispatch => sub {
20 |  |  |  |  | return 'fnerk';
21 |  |  |  |  | }
22 |  |  |  |  | }
23 |  |  |  |  | ]
24 |  |  |  |  | },
25 |  |  |  |  | groups => {
26 |  |  |  |  | fnerk => [
27 |  |  |  |  | {
28 |  |  |  |  | regex => qr/^(\d{4})(\d\d)(\d\d)$/,
29 |  |  |  |  | params => [qw( year month day )],
30 |  |  |  |  | },
31 |  |  |  |  | ]
32 |  |  |  |  | }
33 |  |  |  |  | );
34 |  |  |  |  |
35 |  |  |  |  | =head1 DESCRIPTION
36 |  |  |  |  |
37 |  |  |  |  | C<Dispatch> adds another parser type to C<Builder> permitting
38 |  |  |  |  | dispatch of parsing according to group names.
39 |  |  |  |  |
40 |  |  |  |  | =head1 SPECIFICATION
41 |  |  |  |  |
42 |  |  |  |  | C<Dispatch> has just one key: C<Dispatch>. The value should be a
43 |  |  |  |  | reference to a subroutine that returns one of:
44 |  |  |  |  |
45 |  |  |  |  | =over 4
46 |  |  |  |  |
47 |  |  |  |  | =item *
48 |  |  |  |  |
49 |  |  |  |  | C<undef>, meaning no groups could be found.
50 |  |  |  |  |
51 |  |  |  |  | =item *
52 |  |  |  |  |
53 |  |  |  |  | An empty list, meaning no groups could be found.
54 |  |  |  |  |
55 |  |  |  |  | =item *
56 |  |  |  |  |
57 |  |  |  |  | A single string, meaning: use this group
58 |  |  |  |  |
59 |  |  |  |  | =item *
60 |  |  |  |  |
61 |  |  |  |  | A list of strings, meaning: use these groups in this order.
62 |  |  |  |  |
63 |  |  |  |  | =back
64 |  |  |  |  |
65 |  |  |  |  | Groups are specified much like the example in the L<SYNOPSIS>.
66 |  |  |  |  | They follow the same format as when you specify them for methods.
67 |  |  |  |  |
68 |  |  |  |  | =head1 SIDEEFFECTS
69 |  |  |  |  |
70 |  |  |  |  | Your group parser can also be a Dispatch parser. Thus you could
71 |  |  |  |  | potentially end up with an infinitely recursive parser.
72 |  |  |  |  |
73 |  |  |  |  | =cut
74 |  |  |  |  |
75 | 1 | 600ns |  |  | $VERSION = '0.78';
76 |  |  |  |  |
77 |  |  |  |  | {
78 | 4 | 169µs | 2 | 26µs | # spent 16µs (7+9) within DateTime::Format::Builder::Parser::Dispatch::BEGIN@78 which was called: # once (7µs+9µs) by DateTime::Format::Builder::Parser::BEGIN@1 at line 78 no strict 'refs'; # spent 16µs making 1 call to DateTime::Format::Builder::Parser::Dispatch::BEGIN@78 # spent 9µs making 1 call to strict::unimport
79 | 2 | 2µs |  |  | *dispatch_data = *DateTime::Format::Builder::dispatch_data;
80 |  |  |  |  | *params = *DateTime::Format::Builder::Parser::params;
81 |  |  |  |  | }
82 |  |  |  |  |
83 |  |  |  |  | DateTime::Format::Builder::Parser->valid_params(
84 | 1 | 3µs | 1 | 10µs | Dispatch => { # spent 10µs making 1 call to DateTime::Format::Builder::Parser::valid_params
85 |  |  |  |  | type => CODEREF,
86 |  |  |  |  | }
87 |  |  |  |  | );
88 |  |  |  |  |
89 |  |  |  |  | sub create_parser
90 |  |  |  |  | {
91 |  |  |  |  | my ($self, %args) = @_;
92 |  |  |  |  | my $coderef = $args{Dispatch};
93 |  |  |  |  |
94 |  |  |  |  | return sub {
95 |  |  |  |  | my ($self, $date, $p, @args) = @_;
96 |  |  |  |  | return unless defined $date;
97 |  |  |  |  | my $class = ref($self)||$self;
98 |  |  |  |  |
99 |  |  |  |  | my @results = $coderef->( $date );
100 |  |  |  |  | return unless @results;
101 |  |  |  |  | return unless defined $results[0];
102 |  |  |  |  |
103 |  |  |  |  | for my $group (@results)
104 |  |  |  |  | {
105 |  |  |  |  | my $parser = $dispatch_data{$class}{$group};
106 |  |  |  |  | die "Unknown parsing group: $class\n" unless defined $parser;
107 |  |  |  |  | my $rv = eval { $parser->parse( $self, $date, $p, @args ) };
108 |  |  |  |  | return $rv unless $@ or not defined $rv;
109 |  |  |  |  | }
110 |  |  |  |  | return;
111 |  |  |  |  | };
112 |  |  |  |  | }
113 |  |  |  |  |
114 | 1 | 4µs |  |  | 1;
115 |  |  |  |  |
116 |  |  |  |  | __END__