| Filename | /2home/ss5/perl5/perlbrew/perls/perl-5.12.3/lib/site_perl/5.12.3/DateTime/Format/Builder/Parser/Quick.pm |
| Statements | Executed 15 statements in 262µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 13µs | 91µs | DateTime::Format::Builder::Parser::Quick::BEGIN@5 |
| 1 | 1 | 1 | 13µs | 15µs | DateTime::Format::Builder::Parser::Quick::BEGIN@2 |
| 1 | 1 | 1 | 7µs | 44µs | DateTime::Format::Builder::Parser::Quick::BEGIN@4 |
| 1 | 1 | 1 | 6µs | 33µs | DateTime::Format::Builder::Parser::Quick::BEGIN@3 |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Quick::__ANON__[:68] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Quick::__ANON__[:92] |
| 0 | 0 | 0 | 0s | 0s | DateTime::Format::Builder::Parser::Quick::create_parser |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package DateTime::Format::Builder::Parser::Quick; | ||||
| 2 | 3 | 20µs | 2 | 17µs | # spent 15µs (13+2) within DateTime::Format::Builder::Parser::Quick::BEGIN@2 which was called:
# once (13µs+2µs) by DateTime::Format::Builder::Parser::BEGIN@1.39 at line 2 # spent 15µs making 1 call to DateTime::Format::Builder::Parser::Quick::BEGIN@2
# spent 2µs making 1 call to strict::import |
| 3 | 3 | 21µs | 2 | 60µs | # spent 33µs (6+27) within DateTime::Format::Builder::Parser::Quick::BEGIN@3 which was called:
# once (6µs+27µs) by DateTime::Format::Builder::Parser::BEGIN@1.39 at line 3 # spent 33µs making 1 call to DateTime::Format::Builder::Parser::Quick::BEGIN@3
# spent 27µs making 1 call to vars::import |
| 4 | 3 | 19µs | 2 | 80µs | # spent 44µs (7+36) within DateTime::Format::Builder::Parser::Quick::BEGIN@4 which was called:
# once (7µs+36µs) by DateTime::Format::Builder::Parser::BEGIN@1.39 at line 4 # spent 44µs making 1 call to DateTime::Format::Builder::Parser::Quick::BEGIN@4
# spent 36µs making 1 call to Exporter::import |
| 5 | 3 | 189µs | 2 | 169µs | # spent 91µs (13+78) within DateTime::Format::Builder::Parser::Quick::BEGIN@5 which was called:
# once (13µs+78µs) by DateTime::Format::Builder::Parser::BEGIN@1.39 at line 5 # spent 91µs making 1 call to DateTime::Format::Builder::Parser::Quick::BEGIN@5
# spent 78µs making 1 call to base::import |
| 6 | |||||
| 7 | =head1 NAME | ||||
| 8 | |||||
| 9 | DateTime::Format::Builder::Parser::Quick - Use another formatter, simply | ||||
| 10 | |||||
| 11 | =head1 SYNOPSIS | ||||
| 12 | |||||
| 13 | use DateTime::Format::Builder ( | ||||
| 14 | parsers => { parse_datetime => [ | ||||
| 15 | { Quick => 'DateTime::Format::HTTP' }, | ||||
| 16 | { Quick => 'DateTime::Format::Mail' }, | ||||
| 17 | { Quick => 'DateTime::Format::IBeat' }, | ||||
| 18 | ]}); | ||||
| 19 | |||||
| 20 | is the same as: | ||||
| 21 | |||||
| 22 | use DateTime::Format::HTTP; | ||||
| 23 | use DateTime::Format::Mail; | ||||
| 24 | use DateTime::Format::IBeat; | ||||
| 25 | |||||
| 26 | use DateTime::Format::Builder ( | ||||
| 27 | parsers => { parse_datetime => [ | ||||
| 28 | sub { eval { DateTime::Format::HTTP->parse_datetime( $_[1] ) } }, | ||||
| 29 | sub { eval { DateTime::Format::Mail->parse_datetime( $_[1] ) } }, | ||||
| 30 | sub { eval { DateTime::Format::IBeat->parse_datetime( $_[1] ) } }, | ||||
| 31 | ]}); | ||||
| 32 | |||||
| 33 | (These two pieces of code can both be found in the test | ||||
| 34 | suite; one as F<quick.t>, the other as F<fall.t>.) | ||||
| 35 | |||||
| 36 | =head1 DESCRIPTION | ||||
| 37 | |||||
| 38 | C<Quick> adds a parser that allows some shortcuts when | ||||
| 39 | writing fairly standard and mundane calls to other | ||||
| 40 | formatting modules. | ||||
| 41 | |||||
| 42 | =head1 SPECIFICATION | ||||
| 43 | |||||
| 44 | C<Quick> has two keys, one optional. | ||||
| 45 | |||||
| 46 | The C<Quick> keyword should have an argument of either an | ||||
| 47 | object or a class name. If it's a class name then the class | ||||
| 48 | is C<use>d. | ||||
| 49 | |||||
| 50 | The C<method> keyword is optional with a default of | ||||
| 51 | C<parse_datetime>. It's either name of the method to invoke | ||||
| 52 | on the object, or a reference to a piece of code. | ||||
| 53 | |||||
| 54 | In any case, the resultant code ends up looking like: | ||||
| 55 | |||||
| 56 | my $rv = $Quick->$method( $date ); | ||||
| 57 | |||||
| 58 | =cut | ||||
| 59 | |||||
| 60 | 1 | 600ns | $VERSION = '0.77'; | ||
| 61 | |||||
| 62 | __PACKAGE__->valid_params( | ||||
| 63 | Quick => { | ||||
| 64 | type => SCALAR|OBJECT, | ||||
| 65 | callbacks => { | ||||
| 66 | good_classname => sub { | ||||
| 67 | (ref $_[0]) or ( $_[0] =~ /^\w+[:'\w+]*\w+/ ) | ||||
| 68 | }, | ||||
| 69 | } | ||||
| 70 | }, | ||||
| 71 | 1 | 8µs | 1 | 13µs | method => { # spent 13µs making 1 call to DateTime::Format::Builder::Parser::valid_params |
| 72 | optional => 1, | ||||
| 73 | type => SCALAR|CODEREF, | ||||
| 74 | }, | ||||
| 75 | ); | ||||
| 76 | |||||
| 77 | sub create_parser | ||||
| 78 | { | ||||
| 79 | my ($self, %args) = @_; | ||||
| 80 | my $class = $args{Quick}; | ||||
| 81 | my $method = $args{method}; | ||||
| 82 | $method = 'parse_datetime' unless defined $method; | ||||
| 83 | eval "use $class"; | ||||
| 84 | die $@ if $@; | ||||
| 85 | |||||
| 86 | return sub { | ||||
| 87 | my ($self, $date) = @_; | ||||
| 88 | return unless defined $date; | ||||
| 89 | my $rv = eval { $class->$method( $date ) }; | ||||
| 90 | return $rv if defined $rv; | ||||
| 91 | return; | ||||
| 92 | }; | ||||
| 93 | } | ||||
| 94 | |||||
| 95 | 1 | 4µs | 1; | ||
| 96 | |||||
| 97 | __END__ |