| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DateTime/Format/Builder/Parser/generic.pm |
| Statements | Executed 70 statements in 781µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 7 | 1 | 1 | 110µs | 299µs | DateTime::Format::Builder::Parser::generic::generic_parser |
| 7 | 1 | 1 | 27µs | 27µs | DateTime::Format::Builder::Parser::generic::new |
| 1 | 1 | 1 | 15µs | 17µs | DateTime::Format::Builder::Parser::generic::BEGIN@2 |
| 1 | 1 | 1 | 8µs | 46µs | DateTime::Format::Builder::Parser::generic::BEGIN@4 |
| 1 | 1 | 1 | 7µs | 19µs | DateTime::Format::Builder::Parser::generic::BEGIN@171 |
| 1 | 1 | 1 | 7µs | 43µs | DateTime::Format::Builder::Parser::generic::BEGIN@5 |
| 1 | 1 | 1 | 6µs | 22µs | DateTime::Format::Builder::Parser::generic::BEGIN@3 |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::generic::__ANON__[:125] |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::Format::Builder::Parser::generic; | ||||
| 2 | 3 | 20µs | 2 | 19µ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 # spent 17µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@2
# spent 2µs making 1 call to strict::import |
| 3 | 3 | 18µs | 2 | 38µ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 # spent 22µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@3
# spent 16µs making 1 call to vars::import |
| 4 | 3 | 23µs | 2 | 83µ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 # spent 46µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@4
# spent 37µs making 1 call to Exporter::import |
| 5 | 1 | 36µ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 # spent 36µs making 1 call to Exporter::import | ||
| 6 | validate SCALAR CODEREF UNDEF | ||||
| 7 | 3 | 338µs | 1 | 43µs | ); # spent 43µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@5 |
| 8 | |||||
| 9 | 1 | 600ns | $VERSION = '0.77'; | ||
| 10 | |||||
| 11 | =head1 NAME | ||||
| 12 | |||||
| 13 | DateTime::Format::Builder::Parser::generic - Useful routines | ||||
| 14 | |||||
| 15 | =head1 METHODS | ||||
| 16 | |||||
| 17 | =head2 Useful | ||||
| 18 | |||||
| 19 | =head3 new | ||||
| 20 | |||||
| 21 | Standard constructor. Returns a blessed hash; any arguments are placed | ||||
| 22 | in the hash. This is useful for storing information between methods. | ||||
| 23 | |||||
| 24 | =cut | ||||
| 25 | |||||
| 26 | sub 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 | ||||
| 28 | 14 | 35µs | my $class = shift; | ||
| 29 | bless { @_ }, $class; | ||||
| 30 | } | ||||
| 31 | |||||
| 32 | =head3 generic_parser | ||||
| 33 | |||||
| 34 | This is a method provided solely for the benefit of | ||||
| 35 | C<Parser> implementations. It semi-neatly abstracts | ||||
| 36 | a lot of the work involved. | ||||
| 37 | |||||
| 38 | Basically, it takes parameters matching the assorted | ||||
| 39 | callbacks from the parser declarations and makes a coderef | ||||
| 40 | out of it all. | ||||
| 41 | |||||
| 42 | Currently recognized callbacks are: | ||||
| 43 | |||||
| 44 | =over 4 | ||||
| 45 | |||||
| 46 | =item * | ||||
| 47 | |||||
| 48 | on_match | ||||
| 49 | |||||
| 50 | =item * | ||||
| 51 | |||||
| 52 | on_fail | ||||
| 53 | |||||
| 54 | =item * | ||||
| 55 | |||||
| 56 | preprocess | ||||
| 57 | |||||
| 58 | =item * | ||||
| 59 | |||||
| 60 | postprocess | ||||
| 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 | ||||
| 67 | 35 | 191µs | my $class = shift; | ||
| 68 | my %args = validate( @_, { | ||||
| 69 | 1 | 104µs | 7 | 188µ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 | |||||
| 130 | These are methods you should define when writing your own subclass. | ||||
| 131 | |||||
| 132 | B<Note>: these methods do not exist in this class. There is no point | ||||
| 133 | trying to call C<< $self->SUPER::do_match( ... ) >>. | ||||
| 134 | |||||
| 135 | =head3 do_match | ||||
| 136 | |||||
| 137 | C<do_match> is the first phase. Arguments are the date and @args. | ||||
| 138 | C<self>, C<label>, C<args>. Return value must be defined if you match | ||||
| 139 | successfully. | ||||
| 140 | |||||
| 141 | =head3 post_match | ||||
| 142 | |||||
| 143 | C<post_match> is called after the appropriate callback out of | ||||
| 144 | C<on_match>/C<on_fail> is done. It's passed the date, the return | ||||
| 145 | value from C<do_match> and the parsing hash. | ||||
| 146 | |||||
| 147 | Its return value is used as the C<post> argument to the C<postprocess> | ||||
| 148 | callback, and as the second argument to C<make>. | ||||
| 149 | |||||
| 150 | =head3 make | ||||
| 151 | |||||
| 152 | C<make> takes the original input, the return value from C<post_match> | ||||
| 153 | and the parsing hash and should return a C<DateTime> object or | ||||
| 154 | undefined. | ||||
| 155 | |||||
| 156 | =head2 Delegations | ||||
| 157 | |||||
| 158 | For use of C<Parser>, this module also delegates C<valid_params> and | ||||
| 159 | C<params>. This is just convenience to save typing the following: | ||||
| 160 | |||||
| 161 | DateTime::Format::Builder::Parser->valid_params( blah ) | ||||
| 162 | |||||
| 163 | Instead we get to type: | ||||
| 164 | |||||
| 165 | $self->valid_params( blah ); | ||||
| 166 | __PACKAGE__->valid_params( blah ); | ||||
| 167 | |||||
| 168 | =cut | ||||
| 169 | |||||
| 170 | { | ||||
| 171 | 4 | 40µs | 2 | 31µ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 # spent 19µs making 1 call to DateTime::Format::Builder::Parser::generic::BEGIN@171
# spent 12µs making 1 call to strict::unimport |
| 172 | 1 | 600ns | for (qw( valid_params params )) | ||
| 173 | { | ||||
| 174 | 2 | 7µs | *$_ = *{"DateTime::Format::Builder::Parser::$_"}; | ||
| 175 | } | ||||
| 176 | } | ||||
| 177 | |||||
| 178 | 1 | 4µs | 1; | ||
| 179 | |||||
| 180 | __END__ |